Skip to content

libc: wrap padding fields with Padding newtype. #4609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
16 changes: 8 additions & 8 deletions src/fuchsia/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ s! {
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
pub st_rdev: crate::dev_t,
__pad0: c_ulong,
__pad0: Padding<c_ulong>,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
__pad1: c_int,
__pad1: Padding<c_int>,
pub st_blocks: crate::blkcnt_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: [c_uint; 2],
__unused: Padding<[c_uint; 2]>,
}

pub struct stat64 {
Expand All @@ -37,18 +37,18 @@ s! {
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
pub st_rdev: crate::dev_t,
__pad0: c_ulong,
__pad0: Padding<c_ulong>,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
__pad1: c_int,
__pad1: Padding<c_int>,
pub st_blocks: crate::blkcnt_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: [c_uint; 2],
__unused: Padding<[c_uint; 2]>,
}

pub struct ipc_perm {
Expand All @@ -59,8 +59,8 @@ s! {
pub cgid: crate::gid_t,
pub mode: crate::mode_t,
pub __seq: c_ushort,
__unused1: c_ulong,
__unused2: c_ulong,
__unused1: Padding<c_ulong>,
__unused2: Padding<c_ulong>,
}
}

Expand Down
56 changes: 28 additions & 28 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,46 +143,46 @@ s! {
pub ru_stime: timeval,
pub ru_maxrss: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad1: u32,
__pad1: Padding<u32>,
pub ru_ixrss: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad2: u32,
__pad2: Padding<u32>,
pub ru_idrss: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad3: u32,
__pad3: Padding<u32>,
pub ru_isrss: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad4: u32,
__pad4: Padding<u32>,
pub ru_minflt: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad5: u32,
__pad5: Padding<u32>,
pub ru_majflt: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad6: u32,
__pad6: Padding<u32>,
pub ru_nswap: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad7: u32,
__pad7: Padding<u32>,
pub ru_inblock: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad8: u32,
__pad8: Padding<u32>,
pub ru_oublock: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad9: u32,
__pad9: Padding<u32>,
pub ru_msgsnd: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad10: u32,
__pad10: Padding<u32>,
pub ru_msgrcv: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad11: u32,
__pad11: Padding<u32>,
pub ru_nsignals: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad12: u32,
__pad12: Padding<u32>,
pub ru_nvcsw: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad13: u32,
__pad13: Padding<u32>,
pub ru_nivcsw: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
__pad14: u32,
__pad14: Padding<u32>,
}

pub struct in_addr {
Expand Down Expand Up @@ -449,11 +449,11 @@ s! {
pub gl_offs: size_t,
pub gl_flags: c_int,

__unused1: *mut c_void,
__unused2: *mut c_void,
__unused3: *mut c_void,
__unused4: *mut c_void,
__unused5: *mut c_void,
__unused1: Padding<*mut c_void>,
__unused2: Padding<*mut c_void>,
__unused3: Padding<*mut c_void>,
__unused4: Padding<*mut c_void>,
__unused5: Padding<*mut c_void>,
}

pub struct ifaddrs {
Expand Down Expand Up @@ -538,7 +538,7 @@ s! {
pub ssi_stime: u64,
pub ssi_addr: u64,
pub ssi_addr_lsb: u16,
_pad2: u16,
_pad2: Padding<u16>,
pub ssi_syscall: i32,
pub ssi_call_addr: u64,
pub ssi_arch: u32,
Expand Down Expand Up @@ -795,8 +795,8 @@ s! {
pub shm_cpid: crate::pid_t,
pub shm_lpid: crate::pid_t,
pub shm_nattch: c_ulong,
__pad1: c_ulong,
__pad2: c_ulong,
__pad1: Padding<c_ulong>,
__pad2: Padding<c_ulong>,
}

pub struct msqid_ds {
Expand All @@ -809,8 +809,8 @@ s! {
pub msg_qbytes: crate::msglen_t,
pub msg_lspid: crate::pid_t,
pub msg_lrpid: crate::pid_t,
__pad1: c_ulong,
__pad2: c_ulong,
__pad1: Padding<c_ulong>,
__pad2: Padding<c_ulong>,
}

pub struct statfs {
Expand All @@ -833,10 +833,10 @@ s! {
pub msg_namelen: crate::socklen_t,
pub msg_iov: *mut crate::iovec,
pub msg_iovlen: c_int,
__pad1: c_int,
__pad1: Padding<c_int>,
pub msg_control: *mut c_void,
pub msg_controllen: crate::socklen_t,
__pad2: crate::socklen_t,
__pad2: Padding<crate::socklen_t>,
pub msg_flags: c_int,
}

Expand Down Expand Up @@ -924,7 +924,7 @@ s_no_extra_traits! {

pub struct sockaddr_storage {
pub ss_family: sa_family_t,
__ss_pad2: [u8; 128 - 2 - 8],
__ss_pad2: Padding<[u8; 128 - 2 - 8]>,
__ss_align: size_t,
}

Expand Down Expand Up @@ -981,7 +981,7 @@ s_no_extra_traits! {

pub struct sockaddr_nl {
pub nl_family: crate::sa_family_t,
nl_pad: c_ushort,
nl_pad: Padding<c_ushort>,
pub nl_pid: u32,
pub nl_groups: u32,
}
Expand Down
8 changes: 4 additions & 4 deletions src/fuchsia/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ s! {
pub st_mode: crate::mode_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
__pad0: c_int,
__pad0: Padding<c_int>,
pub st_rdev: crate::dev_t,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
Expand All @@ -28,7 +28,7 @@ s! {
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: [c_long; 3],
__unused: Padding<[c_long; 3]>,
}

// Not actually used, IPC calls just return ENOSYS
Expand All @@ -40,7 +40,7 @@ s! {
pub cgid: crate::gid_t,
pub mode: crate::mode_t,
pub __seq: c_ushort,
__unused1: c_ulong,
__unused2: c_ulong,
__unused1: Padding<c_ulong>,
__unused2: Padding<c_ulong>,
}
}
12 changes: 6 additions & 6 deletions src/fuchsia/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ s! {
pub st_mode: crate::mode_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
__pad0: c_int,
__pad0: Padding<c_int>,
pub st_rdev: crate::dev_t,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
Expand All @@ -25,7 +25,7 @@ s! {
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__unused: [c_long; 3],
__unused: Padding<[c_long; 3]>,
}

pub struct stat64 {
Expand All @@ -35,7 +35,7 @@ s! {
pub st_mode: crate::mode_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
__pad0: c_int,
__pad0: Padding<c_int>,
pub st_rdev: crate::dev_t,
pub st_size: off_t,
pub st_blksize: crate::blksize_t,
Expand All @@ -46,7 +46,7 @@ s! {
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,
__reserved: [c_long; 3],
__reserved: Padding<[c_long; 3]>,
}

pub struct mcontext_t {
Expand All @@ -61,8 +61,8 @@ s! {
pub cgid: crate::gid_t,
pub mode: crate::mode_t,
pub __seq: c_int,
__unused1: c_long,
__unused2: c_long,
__unused1: Padding<c_long>,
__unused2: Padding<c_long>,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ s! {
pub struct sockaddr_storage {
pub ss_len: u8,
pub ss_family: sa_family_t,
__ss_pad1: [u8; 6],
__ss_pad1: Padding<[u8; 6]>,
__ss_align: i64,
__ss_pad2: [u8; 112],
__ss_pad2: Padding<[u8; 112]>,
}

pub struct stat {
Expand Down
2 changes: 1 addition & 1 deletion src/new/linux_uapi/linux/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ s! {
pub can_id: canid_t,
// FIXME(1.0): this field was renamed to `len` in Linux 5.11
pub can_dlc: u8,
__pad: u8,
__pad: Padding<u8>,
__res0: u8,
pub len8_dlc: u8,
pub data: [u8; CAN_MAX_DLEN],
Expand Down
4 changes: 2 additions & 2 deletions src/unix/aix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ s! {
pub struct sockaddr_storage {
pub __ss_len: c_uchar,
pub ss_family: sa_family_t,
__ss_pad1: [c_char; 6],
__ss_pad1: Padding<[c_char; 6]>,
__ss_align: crate::int64_t,
__ss_pad2: [c_char; 1265],
__ss_pad2: Padding<[c_char; 1265]>,
}

pub struct sockaddr_un {
Expand Down
28 changes: 14 additions & 14 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,18 @@ s! {

pub struct glob_t {
pub gl_pathc: size_t,
__unused1: c_int,
__unused1: Padding<c_int>,
pub gl_offs: size_t,
__unused2: c_int,
__unused2: Padding<c_int>,
pub gl_pathv: *mut *mut c_char,

__unused3: *mut c_void,
__unused3: Padding<*mut c_void>,

__unused4: *mut c_void,
__unused5: *mut c_void,
__unused6: *mut c_void,
__unused7: *mut c_void,
__unused8: *mut c_void,
__unused4: Padding<*mut c_void>,
__unused5: Padding<*mut c_void>,
__unused6: Padding<*mut c_void>,
__unused7: Padding<*mut c_void>,
__unused8: Padding<*mut c_void>,
}

pub struct addrinfo {
Expand Down Expand Up @@ -338,7 +338,7 @@ s! {
pub si_addr: *mut c_void,
//Requires it to be union for tests
//pub si_value: crate::sigval,
_pad: [usize; 9],
_pad: Padding<[usize; 9]>,
}

pub struct sigaction {
Expand Down Expand Up @@ -1087,7 +1087,7 @@ s! {
pub tcpi_state: u8,
pub tcpi_snd_wscale: u8,
pub tcpi_rcv_wscale: u8,
__pad1: u8,
__pad1: Padding<u8>,
pub tcpi_options: u32,
pub tcpi_flags: u32,
pub tcpi_rto: u32,
Expand Down Expand Up @@ -1115,7 +1115,7 @@ s! {
pub tcpi_tfo_send_blackhole: u32,
pub tcpi_tfo_recv_blackhole: u32,
pub tcpi_tfo_onebyte_proxy: u32,
__pad2: u32,
__pad2: Padding<u32>,
pub tcpi_txpackets: u64,
pub tcpi_txbytes: u64,
pub tcpi_txretransmitbytes: u64,
Expand Down Expand Up @@ -1359,9 +1359,9 @@ s_no_extra_traits! {
pub struct sockaddr_storage {
pub ss_len: u8,
pub ss_family: crate::sa_family_t,
__ss_pad1: [u8; 6],
__ss_pad1: Padding<[u8; 6]>,
__ss_align: i64,
__ss_pad2: [u8; 112],
__ss_pad2: Padding<[u8; 112]>,
}

pub struct utmpx {
Expand All @@ -1379,7 +1379,7 @@ s_no_extra_traits! {
pub sigev_notify: c_int,
pub sigev_signo: c_int,
pub sigev_value: crate::sigval,
__unused1: *mut c_void, //actually a function pointer
__unused1: Padding<*mut c_void>, //actually a function pointer
pub sigev_notify_attributes: *mut crate::pthread_attr_t,
}

Expand Down
Loading
Loading