Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions library/std/src/sys/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use crate::sys_common::AsInner;
use libc::{c_int, c_void};

#[derive(Debug)]
#[rustc_layout_scalar_valid_range_start(0)]
#[cfg_attr(not(target_os = "fuchsia"), rustc_layout_scalar_valid_range_start(0))]
// libstd/os/raw/mod.rs assures me that every libstd-supported platform has a
// 32-bit c_int. Below is -2, in two's complement, but that only works out
// because c_int is 32 bits.
#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)]
#[cfg_attr(not(target_os = "fuchsia"), rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE))]
pub struct FileDesc {
fd: c_int,
}
Expand Down Expand Up @@ -68,7 +68,10 @@ const fn max_iov() -> usize {

impl FileDesc {
pub fn new(fd: c_int) -> FileDesc {
assert_ne!(fd, -1i32);
if cfg!(not(target_os = "fuchsia")) {
assert_ne!(fd, -1i32);
}

// SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
unsafe { FileDesc { fd } }
}
Expand Down
11 changes: 10 additions & 1 deletion library/std/src/sys/unix/fd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ use core::mem::ManuallyDrop;

#[test]
fn limit_vector_count() {
let stdout = ManuallyDrop::new(unsafe { FileDesc { fd: 1 } });
let stdout = ManuallyDrop::new(
#[cfg(not(target_os = "fuchsia"))]
{
unsafe { FileDesc { fd: 1 } }
},
#[cfg(target_os = "fuchsia")]
{
FileDesc { fd: 1 }
},
);
let bufs = (0..1500).map(|_| IoSlice::new(&[])).collect::<Vec<_>>();
assert!(stdout.write_vectored(&bufs).is_ok());
}