Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
cargo update --package=half --precise=2.2.1
cargo update --package=flate2 --precise=1.0.35
cargo update --package=serde --precise=1.0.228
cargo update --package=web-sys --precise=0.3.104
cargo update --package=syn --precise=2.0.106
cargo update --package=textwrap --precise=0.16.1
cargo update --package=parking_lot --precise=0.12.4
Expand Down Expand Up @@ -596,6 +597,7 @@ jobs:
cargo update --package=half --precise=2.2.1
cargo update --package=flate2 --precise=1.0.35
cargo update --package=serde --precise=1.0.228
cargo update --package=web-sys --precise=0.3.104
cargo update --package=syn --precise=2.0.106
cargo update --package=textwrap --precise=0.16.1
cargo update --package=parking_lot --precise=0.12.4
Expand Down
6 changes: 4 additions & 2 deletions src/backend/libc/fs/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use crate::io;
#[cfg(not(any(target_os = "fuchsia", target_os = "vita", target_os = "wasi")))]
#[cfg(feature = "process")]
use crate::process::fchdir;
#[cfg(target_os = "openbsd")]
use crate::types::Padding;
use alloc::borrow::ToOwned as _;
#[cfg(not(any(linux_like, target_os = "hurd")))]
use c::readdir as libc_readdir;
Expand Down Expand Up @@ -408,7 +410,7 @@ struct libc_dirent {
d_reclen: u16,
d_type: u8,
d_namlen: u8,
__d_padding: [u8; 4],
__d_padding: Padding<[u8; 4]>,
d_name: [c::c_char; 256],
}

Expand All @@ -434,7 +436,7 @@ fn check_dirent_layout(dirent: &c::dirent) {
d_reclen: 0_u16,
d_type: 0_u8,
d_namlen: 0_u8,
__d_padding: [0_u8; 4],
__d_padding: Default::default(),
d_name: [0 as c::c_char; 256],
};
let base = as_ptr(&z) as usize;
Expand Down
4 changes: 3 additions & 1 deletion src/backend/libc/fs/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::backend::c;
use crate::ffi;
#[cfg(target_os = "netbsd")]
use crate::types::Padding;
use bitflags::bitflags;

#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))]
Expand Down Expand Up @@ -1054,7 +1056,7 @@ pub struct Stat {
pub st_blksize: c::blksize_t,
pub st_flags: u32,
pub st_gen: u32,
pub st_spare: [u32; 2],
pub(crate) st_spare: Padding<[u32; 2]>,
}

/// `struct statfs` for use with [`statfs`] and [`fstatfs`].
Expand Down
36 changes: 19 additions & 17 deletions src/backend/linux_raw/fs/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::ffi;
#[allow(unused_imports)]
use crate::types::Padding;
use bitflags::bitflags;

bitflags! {
Expand Down Expand Up @@ -640,7 +642,7 @@ pub struct Stat {
pub st_mode: ffi::c_uint,
pub st_uid: ffi::c_uint,
pub st_gid: ffi::c_uint,
pub(crate) __pad0: ffi::c_uint,
pub(crate) __pad0: Padding<ffi::c_uint>,
pub st_rdev: ffi::c_ulong,
pub st_size: ffi::c_long,
pub st_blksize: ffi::c_long,
Expand All @@ -651,7 +653,7 @@ pub struct Stat {
pub st_mtime_nsec: ffi::c_ulong,
pub st_ctime: ffi::c_long,
pub st_ctime_nsec: ffi::c_ulong,
pub(crate) __unused: [ffi::c_long; 3],
pub(crate) __unused: Padding<[ffi::c_long; 3]>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand All @@ -666,19 +668,19 @@ pub struct Stat {
pub st_uid: ffi::c_uint,
pub st_gid: ffi::c_uint,
pub st_rdev: ffi::c_ulong,
pub(crate) __pad1: ffi::c_ulong,
pub(crate) __pad1: Padding<ffi::c_ulong>,
pub st_size: ffi::c_long,
pub st_blksize: ffi::c_int,
pub(crate) __pad2: ffi::c_int,
pub(crate) __pad2: Padding<ffi::c_int>,
pub st_blocks: ffi::c_long,
pub st_atime: ffi::c_long,
pub st_atime_nsec: ffi::c_ulong,
pub st_mtime: ffi::c_long,
pub st_mtime_nsec: ffi::c_ulong,
pub st_ctime: ffi::c_long,
pub st_ctime_nsec: ffi::c_ulong,
pub(crate) __unused4: ffi::c_uint,
pub(crate) __unused5: ffi::c_uint,
pub(crate) __unused4: Padding<ffi::c_uint>,
pub(crate) __unused5: Padding<ffi::c_uint>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand All @@ -693,19 +695,19 @@ pub struct Stat {
pub st_uid: ffi::c_uint,
pub st_gid: ffi::c_uint,
pub st_rdev: ffi::c_ulong,
pub(crate) __pad1: ffi::c_ulong,
pub(crate) __pad1: Padding<ffi::c_ulong>,
pub st_size: ffi::c_long,
pub st_blksize: ffi::c_int,
pub(crate) __pad2: ffi::c_int,
pub(crate) __pad2: Padding<ffi::c_int>,
pub st_blocks: ffi::c_long,
pub st_atime: ffi::c_long,
pub st_atime_nsec: ffi::c_ulong,
pub st_mtime: ffi::c_long,
pub st_mtime_nsec: ffi::c_ulong,
pub st_ctime: ffi::c_long,
pub st_ctime_nsec: ffi::c_ulong,
pub(crate) __unused4: ffi::c_uint,
pub(crate) __unused5: ffi::c_uint,
pub(crate) __unused4: Padding<ffi::c_uint>,
pub(crate) __unused5: Padding<ffi::c_uint>,
}
// This follows `stat`. powerpc64 defines a `stat64` but it's not used.
#[repr(C)]
Expand All @@ -730,9 +732,9 @@ pub struct Stat {
pub st_mtime_nsec: ffi::c_ulong,
pub st_ctime: ffi::c_long,
pub st_ctime_nsec: ffi::c_ulong,
pub(crate) __unused4: ffi::c_ulong,
pub(crate) __unused5: ffi::c_ulong,
pub(crate) __unused6: ffi::c_ulong,
pub(crate) __unused4: Padding<ffi::c_ulong>,
pub(crate) __unused5: Padding<ffi::c_ulong>,
pub(crate) __unused6: Padding<ffi::c_ulong>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand All @@ -746,7 +748,7 @@ pub struct Stat {
pub st_mode: ffi::c_uint,
pub st_uid: ffi::c_uint,
pub st_gid: ffi::c_uint,
pub(crate) __pad1: ffi::c_uint,
pub(crate) __pad1: Padding<ffi::c_uint>,
pub st_rdev: ffi::c_ulong,
pub st_size: ffi::c_long, // Linux has `c_ulong` but we make it signed.
pub st_atime: ffi::c_long,
Expand All @@ -757,7 +759,7 @@ pub struct Stat {
pub st_ctime_nsec: ffi::c_ulong,
pub st_blksize: ffi::c_ulong,
pub st_blocks: ffi::c_long,
pub(crate) __unused: [ffi::c_ulong; 3],
pub(crate) __unused: Padding<[ffi::c_ulong; 3]>,
}

/// `struct statfs` for use with [`statfs`] and [`fstatfs`].
Expand Down Expand Up @@ -795,9 +797,9 @@ pub struct StatFs {
#[cfg(any(target_arch = "arm", target_arch = "s390x"))]
pub f_flags: ffi::c_uint,
#[cfg(not(target_arch = "s390x"))]
pub(crate) f_spare: [ffi::c_long; 4],
pub(crate) f_spare: Padding<[ffi::c_long; 4]>,
#[cfg(target_arch = "s390x")]
pub(crate) f_spare: [ffi::c_uint; 5],
pub(crate) f_spare: Padding<[ffi::c_uint; 5]>,
}

/// `fsid_t` for use with [`StatFs`].
Expand Down
8 changes: 5 additions & 3 deletions src/event/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ use crate::buffer::Buffer;
use crate::fd::{AsFd, OwnedFd};
use crate::io;
use crate::timespec::Timespec;
#[cfg(target_pointer_width = "32")]
use crate::types::Padding;
use core::ffi::c_void;
use core::hash::{Hash, Hasher};

Expand Down Expand Up @@ -276,7 +278,7 @@ impl EventData {
sixty_four_bit_pointer: SixtyFourBitPointer {
pointer: value,
#[cfg(target_pointer_width = "32")]
_padding: 0,
_padding: Padding::new(0),
},
}
}
Expand Down Expand Up @@ -321,13 +323,13 @@ impl Hash for EventData {
struct SixtyFourBitPointer {
#[cfg(target_endian = "big")]
#[cfg(target_pointer_width = "32")]
_padding: u32,
_padding: Padding<u32>,

pointer: *mut c_void,

#[cfg(target_endian = "little")]
#[cfg(target_pointer_width = "32")]
_padding: u32,
_padding: Padding<u32>,
}

#[cfg(test)]
Expand Down
9 changes: 5 additions & 4 deletions src/fs/statx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::fd::AsFd;
use crate::fs::AtFlags;
use crate::types::Padding;
use crate::{backend, io, path};
use backend::c;
use bitflags::bitflags;
Expand All @@ -24,7 +25,7 @@ pub struct Statx {
pub stx_uid: u32,
pub stx_gid: u32,
pub stx_mode: u16,
pub(crate) __spare0: [u16; 1],
pub(crate) __spare0: Padding<[u16; 1]>,
pub stx_ino: u64,
pub stx_size: u64,
pub stx_blocks: u64,
Expand All @@ -46,8 +47,8 @@ pub struct Statx {
pub stx_atomic_write_segments_max: u32,
pub stx_dio_read_offset_align: u32,
pub stx_atomic_write_unit_max_opt: u32,
pub __spare2: [u32; 1usize],
pub __spare3: [u64; 8usize],
pub(crate) __spare2: Padding<[u32; 1usize]>,
pub(crate) __spare3: Padding<[u64; 8usize]>,
}

/// `struct statx_timestamp` for use with [`Statx`].
Expand All @@ -61,7 +62,7 @@ pub struct StatxTimestamp {
/// Nanoseconds. Must be less than 1_000_000_000.
pub tv_nsec: u32,

pub(crate) __reserved: i32,
pub(crate) __reserved: Padding<i32>,
}

bitflags! {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ pub(crate) mod bitcast;
#[cfg(sanitize_memory)]
pub(crate) mod msan;

mod types;

// linux_raw: Weak symbols are used by the use-libc-auxv feature for
// glibc 2.15 support.
//
Expand Down
4 changes: 3 additions & 1 deletion src/termios/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::backend::c;
use crate::backend::termios::types;
#[cfg(target_os = "nto")]
use crate::ffi;
#[cfg(target_os = "nto")]
use crate::types::Padding;
use crate::{backend, io};
use bitflags::bitflags;

Expand Down Expand Up @@ -46,7 +48,7 @@ pub struct Termios {
pub special_codes: SpecialCodes,

#[cfg(target_os = "nto")]
pub(crate) __reserved: [ffi::c_uint; 3],
pub(crate) __reserved: Padding<[ffi::c_uint; 3]>,

/// Line discipline.
// On PowerPC, this field comes after `c_cc`.
Expand Down
5 changes: 3 additions & 2 deletions src/thread/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use core::sync::atomic::AtomicU32;
use crate::backend::thread::futex::Operation;
use crate::backend::thread::syscalls::{futex_timeout, futex_val2};
use crate::fd::{FromRawFd as _, OwnedFd, RawFd};
use crate::types::Padding;
use crate::{backend, io};

pub use crate::clockid::ClockId;
Expand Down Expand Up @@ -532,7 +533,7 @@ pub struct Wait {
pub flags: WaitFlags,

/// Reserved for future use.
pub(crate) __reserved: u32,
pub(crate) __reserved: Padding<u32>,
}

impl Wait {
Expand All @@ -543,7 +544,7 @@ impl Wait {
val: 0,
uaddr: WaitPtr::new(ptr::null_mut()),
flags: WaitFlags::empty(),
__reserved: 0,
__reserved: Padding::new(0),
}
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Platform-agnostic support types.
//!
//! Copied from https://github.com/rust-lang/libc/blob/008f905256d27eb5dd416d0976678ee6c2855554/src/types.rs

use core::fmt;
use core::mem::MaybeUninit;

/// A transparent wrapper over `MaybeUninit<T>` to represent uninitialized padding
/// while providing `Default`.
// This is restricted to `Copy` types since that's a loose indicator that zeros is actually
// a valid bitpattern. There is no technical reason this is required, though, so it could be
// lifted in the future if it becomes a problem.
#[allow(dead_code)]
#[repr(transparent)]
#[derive(Clone, Copy)]
pub(crate) struct Padding<T: Copy>(MaybeUninit<T>);

impl<T: Copy> Default for Padding<T> {
fn default() -> Self {
Self(MaybeUninit::zeroed())
}
}

impl<T: Copy> Padding<T> {
/// Create a `Padding` initialized with the given value.
#[allow(dead_code)]
pub(crate) const fn new(val: T) -> Self {
Self(MaybeUninit::new(val))
}
}

impl<T: Copy> fmt::Debug for Padding<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Taken from `MaybeUninit`'s debug implementation
// NB: there is no `.pad_fmt` so we can't use a simpler `format_args!("Padding<{..}>").
let full_name = core::any::type_name::<Self>();
let prefix_len = full_name.find("Padding").unwrap();
f.pad(&full_name[prefix_len..])
}
}
Loading