Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7b86f6b

Browse files
authored
Unrolled build for rust-lang#139092
Rollup merge of rust-lang#139092 - thaliaarchi:move-fd-pal, r=joboet Move `fd` into `std::sys` Move platform definitions of `fd` into `std::sys`, as part of rust-lang#117276. Unlike other modules directly under `std::sys`, this is only available on some platforms and I have not provided a fallback abstraction for unsupported platforms. That is similar to how `std::os::fd` is gated to only supported platforms. Also, fix the `unsafe_op_in_unsafe_fn` lint, which was allowed for the Unix fd impl. Since macro expansions from `std::sys::pal::unix::weak` trigger this lint, fix it there too. cc `@joboet,` `@ChrisDenton` try-job: x86_64-gnu-aux
2 parents da83217 + 3ab22fa commit 7b86f6b

File tree

17 files changed

+55
-33
lines changed

17 files changed

+55
-33
lines changed

library/std/src/sys/pal/hermit/fd.rs renamed to library/std/src/sys/fd/hermit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![unstable(reason = "not public", issue = "none", feature = "fd")]
22

3-
use super::hermit_abi;
43
use crate::cmp;
54
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, SeekFrom};
5+
use crate::os::hermit::hermit_abi;
66
use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
77
use crate::sys::{cvt, unsupported};
88
use crate::sys_common::{AsInner, FromInner, IntoInner};

library/std/src/sys/fd/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Platform-dependent file descriptor abstraction.
2+
3+
#![forbid(unsafe_op_in_unsafe_fn)]
4+
5+
cfg_if::cfg_if! {
6+
if #[cfg(target_family = "unix")] {
7+
mod unix;
8+
pub use unix::*;
9+
} else if #[cfg(target_os = "hermit")] {
10+
mod hermit;
11+
pub use hermit::*;
12+
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
13+
mod sgx;
14+
pub use sgx::*;
15+
} else if #[cfg(target_os = "wasi")] {
16+
mod wasi;
17+
pub use wasi::*;
18+
}
19+
}

library/std/src/sys/pal/sgx/fd.rs renamed to library/std/src/sys/fd/sgx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use fortanix_sgx_abi::Fd;
22

3-
use super::abi::usercalls;
43
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
54
use crate::mem::ManuallyDrop;
5+
use crate::sys::pal::abi::usercalls;
66
use crate::sys::{AsInner, FromInner, IntoInner};
77

88
#[derive(Debug)]

library/std/src/sys/pal/unix/fd.rs renamed to library/std/src/sys/fd/unix.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ use crate::cmp;
2222
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read};
2323
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
2424
use crate::sys::cvt;
25+
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
26+
use crate::sys::pal::weak::syscall;
27+
#[cfg(any(all(target_os = "android", target_pointer_width = "32"), target_vendor = "apple"))]
28+
use crate::sys::pal::weak::weak;
2529
use crate::sys_common::{AsInner, FromInner, IntoInner};
2630

2731
#[derive(Debug)]
@@ -232,7 +236,7 @@ impl FileDesc {
232236
// implementation if `preadv` is not available.
233237
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
234238
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
235-
super::weak::syscall!(
239+
syscall!(
236240
fn preadv(
237241
fd: libc::c_int,
238242
iovec: *const libc::iovec,
@@ -257,7 +261,7 @@ impl FileDesc {
257261
// and its metadata from LLVM IR.
258262
#[no_sanitize(cfi)]
259263
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
260-
super::weak::weak!(
264+
weak!(
261265
fn preadv64(
262266
fd: libc::c_int,
263267
iovec: *const libc::iovec,
@@ -293,7 +297,7 @@ impl FileDesc {
293297
// use "weak" linking.
294298
#[cfg(target_vendor = "apple")]
295299
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
296-
super::weak::weak!(
300+
weak!(
297301
fn preadv(
298302
fd: libc::c_int,
299303
iovec: *const libc::iovec,
@@ -442,7 +446,7 @@ impl FileDesc {
442446
// implementation if `pwritev` is not available.
443447
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
444448
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
445-
super::weak::syscall!(
449+
syscall!(
446450
fn pwritev(
447451
fd: libc::c_int,
448452
iovec: *const libc::iovec,
@@ -464,7 +468,7 @@ impl FileDesc {
464468

465469
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
466470
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
467-
super::weak::weak!(
471+
weak!(
468472
fn pwritev64(
469473
fd: libc::c_int,
470474
iovec: *const libc::iovec,
@@ -500,7 +504,7 @@ impl FileDesc {
500504
// use "weak" linking.
501505
#[cfg(target_vendor = "apple")]
502506
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
503-
super::weak::weak!(
507+
weak!(
504508
fn pwritev(
505509
fd: libc::c_int,
506510
iovec: *const libc::iovec,
@@ -669,6 +673,6 @@ impl IntoRawFd for FileDesc {
669673

670674
impl FromRawFd for FileDesc {
671675
unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
672-
Self(FromRawFd::from_raw_fd(raw_fd))
676+
Self(unsafe { FromRawFd::from_raw_fd(raw_fd) })
673677
}
674678
}

library/std/src/sys/pal/unix/fd/tests.rs renamed to library/std/src/sys/fd/unix/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use core::mem::ManuallyDrop;
22

3-
use super::{FileDesc, IoSlice};
3+
use super::FileDesc;
4+
use crate::io::IoSlice;
45
use crate::os::unix::io::FromRawFd;
56

67
#[test]

library/std/src/sys/pal/wasi/fd.rs renamed to library/std/src/sys/fd/wasi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
#![forbid(unsafe_op_in_unsafe_fn)]
2-
#![allow(dead_code)]
1+
#![expect(dead_code)]
32

4-
use super::err2io;
53
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
64
use crate::mem;
75
use crate::net::Shutdown;
86
use crate::os::wasi::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
7+
use crate::sys::pal::err2io;
98
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
109

1110
#[derive(Debug)]

library/std/src/sys/fs/hermit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Raw
99
use crate::path::{Path, PathBuf};
1010
use crate::sync::Arc;
1111
use crate::sys::common::small_c_string::run_path_with_cstr;
12+
use crate::sys::fd::FileDesc;
1213
pub use crate::sys::fs::common::{copy, exists};
13-
use crate::sys::pal::fd::FileDesc;
1414
use crate::sys::time::SystemTime;
1515
use crate::sys::{cvt, unsupported};
1616
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};

library/std/src/sys/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod anonymous_pipe;
1212
pub mod backtrace;
1313
pub mod cmath;
1414
pub mod exit_guard;
15+
pub mod fd;
1516
pub mod fs;
1617
pub mod io;
1718
pub mod net;

library/std/src/sys/pal/hermit/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::os::raw::c_char;
2020

2121
pub mod args;
2222
pub mod env;
23-
pub mod fd;
2423
pub mod futex;
2524
pub mod os;
2625
#[path = "../unsupported/pipe.rs"]

library/std/src/sys/pal/sgx/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::sync::atomic::{AtomicBool, Ordering};
1111
pub mod abi;
1212
pub mod args;
1313
pub mod env;
14-
pub mod fd;
1514
mod libunwind_integration;
1615
pub mod os;
1716
#[path = "../unsupported/pipe.rs"]

0 commit comments

Comments
 (0)