Skip to content

Commit f7e75a4

Browse files
committed
libc: wrap padding fields with Padding newtype.
1 parent 83bd32f commit f7e75a4

File tree

81 files changed

+732
-715
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+732
-715
lines changed

src/fuchsia/aarch64.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ s! {
1515
pub st_uid: crate::uid_t,
1616
pub st_gid: crate::gid_t,
1717
pub st_rdev: crate::dev_t,
18-
__pad0: c_ulong,
18+
__pad0: Padding<c_ulong>,
1919
pub st_size: off_t,
2020
pub st_blksize: crate::blksize_t,
21-
__pad1: c_int,
21+
__pad1: Padding<c_int>,
2222
pub st_blocks: crate::blkcnt_t,
2323
pub st_atime: crate::time_t,
2424
pub st_atime_nsec: c_long,
2525
pub st_mtime: crate::time_t,
2626
pub st_mtime_nsec: c_long,
2727
pub st_ctime: crate::time_t,
2828
pub st_ctime_nsec: c_long,
29-
__unused: [c_uint; 2],
29+
__unused: Padding<[c_uint; 2]>,
3030
}
3131

3232
pub struct stat64 {
@@ -37,18 +37,18 @@ s! {
3737
pub st_uid: crate::uid_t,
3838
pub st_gid: crate::gid_t,
3939
pub st_rdev: crate::dev_t,
40-
__pad0: c_ulong,
40+
__pad0: Padding<c_ulong>,
4141
pub st_size: off_t,
4242
pub st_blksize: crate::blksize_t,
43-
__pad1: c_int,
43+
__pad1: Padding<c_int>,
4444
pub st_blocks: crate::blkcnt_t,
4545
pub st_atime: crate::time_t,
4646
pub st_atime_nsec: c_long,
4747
pub st_mtime: crate::time_t,
4848
pub st_mtime_nsec: c_long,
4949
pub st_ctime: crate::time_t,
5050
pub st_ctime_nsec: c_long,
51-
__unused: [c_uint; 2],
51+
__unused: Padding<[c_uint; 2]>,
5252
}
5353

5454
pub struct ipc_perm {
@@ -59,8 +59,8 @@ s! {
5959
pub cgid: crate::gid_t,
6060
pub mode: crate::mode_t,
6161
pub __seq: c_ushort,
62-
__unused1: c_ulong,
63-
__unused2: c_ulong,
62+
__unused1: Padding<c_ulong>,
63+
__unused2: Padding<c_ulong>,
6464
}
6565
}
6666

src/fuchsia/mod.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,46 +121,46 @@ s! {
121121
pub ru_stime: timeval,
122122
pub ru_maxrss: c_long,
123123
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
124-
__pad1: u32,
124+
__pad1: Padding<u32>,
125125
pub ru_ixrss: c_long,
126126
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
127-
__pad2: u32,
127+
__pad2: Padding<u32>,
128128
pub ru_idrss: c_long,
129129
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
130-
__pad3: u32,
130+
__pad3: Padding<u32>,
131131
pub ru_isrss: c_long,
132132
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
133-
__pad4: u32,
133+
__pad4: Padding<u32>,
134134
pub ru_minflt: c_long,
135135
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
136-
__pad5: u32,
136+
__pad5: Padding<u32>,
137137
pub ru_majflt: c_long,
138138
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
139-
__pad6: u32,
139+
__pad6: Padding<u32>,
140140
pub ru_nswap: c_long,
141141
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
142-
__pad7: u32,
142+
__pad7: Padding<u32>,
143143
pub ru_inblock: c_long,
144144
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
145-
__pad8: u32,
145+
__pad8: Padding<u32>,
146146
pub ru_oublock: c_long,
147147
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
148-
__pad9: u32,
148+
__pad9: Padding<u32>,
149149
pub ru_msgsnd: c_long,
150150
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
151-
__pad10: u32,
151+
__pad10: Padding<u32>,
152152
pub ru_msgrcv: c_long,
153153
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
154-
__pad11: u32,
154+
__pad11: Padding<u32>,
155155
pub ru_nsignals: c_long,
156156
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
157-
__pad12: u32,
157+
__pad12: Padding<u32>,
158158
pub ru_nvcsw: c_long,
159159
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
160-
__pad13: u32,
160+
__pad13: Padding<u32>,
161161
pub ru_nivcsw: c_long,
162162
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
163-
__pad14: u32,
163+
__pad14: Padding<u32>,
164164
}
165165

166166
pub struct in_addr {
@@ -427,11 +427,11 @@ s! {
427427
pub gl_offs: size_t,
428428
pub gl_flags: c_int,
429429

430-
__unused1: *mut c_void,
431-
__unused2: *mut c_void,
432-
__unused3: *mut c_void,
433-
__unused4: *mut c_void,
434-
__unused5: *mut c_void,
430+
__unused1: Padding<*mut c_void>,
431+
__unused2: Padding<*mut c_void>,
432+
__unused3: Padding<*mut c_void>,
433+
__unused4: Padding<*mut c_void>,
434+
__unused5: Padding<*mut c_void>,
435435
}
436436

437437
pub struct ifaddrs {
@@ -516,7 +516,7 @@ s! {
516516
pub ssi_stime: u64,
517517
pub ssi_addr: u64,
518518
pub ssi_addr_lsb: u16,
519-
_pad2: u16,
519+
_pad2: Padding<u16>,
520520
pub ssi_syscall: i32,
521521
pub ssi_call_addr: u64,
522522
pub ssi_arch: u32,
@@ -773,8 +773,8 @@ s! {
773773
pub shm_cpid: crate::pid_t,
774774
pub shm_lpid: crate::pid_t,
775775
pub shm_nattch: c_ulong,
776-
__pad1: c_ulong,
777-
__pad2: c_ulong,
776+
__pad1: Padding<c_ulong>,
777+
__pad2: Padding<c_ulong>,
778778
}
779779

780780
pub struct msqid_ds {
@@ -787,8 +787,8 @@ s! {
787787
pub msg_qbytes: crate::msglen_t,
788788
pub msg_lspid: crate::pid_t,
789789
pub msg_lrpid: crate::pid_t,
790-
__pad1: c_ulong,
791-
__pad2: c_ulong,
790+
__pad1: Padding<c_ulong>,
791+
__pad2: Padding<c_ulong>,
792792
}
793793

794794
pub struct statfs {
@@ -811,10 +811,10 @@ s! {
811811
pub msg_namelen: crate::socklen_t,
812812
pub msg_iov: *mut crate::iovec,
813813
pub msg_iovlen: c_int,
814-
__pad1: c_int,
814+
__pad1: Padding<c_int>,
815815
pub msg_control: *mut c_void,
816816
pub msg_controllen: crate::socklen_t,
817-
__pad2: crate::socklen_t,
817+
__pad2: Padding<crate::socklen_t>,
818818
pub msg_flags: c_int,
819819
}
820820

@@ -900,7 +900,7 @@ s! {
900900

901901
pub struct sockaddr_storage {
902902
pub ss_family: sa_family_t,
903-
__ss_pad2: [u8; 128 - 2 - 8],
903+
__ss_pad2: Padding<[u8; 128 - 2 - 8]>,
904904
__ss_align: size_t,
905905
}
906906

@@ -957,7 +957,7 @@ s! {
957957

958958
pub struct sockaddr_nl {
959959
pub nl_family: crate::sa_family_t,
960-
nl_pad: c_ushort,
960+
nl_pad: Padding<c_ushort>,
961961
pub nl_pid: u32,
962962
pub nl_groups: u32,
963963
}

src/fuchsia/riscv64.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ s! {
1717
pub st_mode: crate::mode_t,
1818
pub st_uid: crate::uid_t,
1919
pub st_gid: crate::gid_t,
20-
__pad0: c_int,
20+
__pad0: Padding<c_int>,
2121
pub st_rdev: crate::dev_t,
2222
pub st_size: off_t,
2323
pub st_blksize: crate::blksize_t,
@@ -28,7 +28,7 @@ s! {
2828
pub st_mtime_nsec: c_long,
2929
pub st_ctime: crate::time_t,
3030
pub st_ctime_nsec: c_long,
31-
__unused: [c_long; 3],
31+
__unused: Padding<[c_long; 3]>,
3232
}
3333

3434
// Not actually used, IPC calls just return ENOSYS
@@ -40,7 +40,7 @@ s! {
4040
pub cgid: crate::gid_t,
4141
pub mode: crate::mode_t,
4242
pub __seq: c_ushort,
43-
__unused1: c_ulong,
44-
__unused2: c_ulong,
43+
__unused1: Padding<c_ulong>,
44+
__unused2: Padding<c_ulong>,
4545
}
4646
}

src/fuchsia/x86_64.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ s! {
1414
pub st_mode: crate::mode_t,
1515
pub st_uid: crate::uid_t,
1616
pub st_gid: crate::gid_t,
17-
__pad0: c_int,
17+
__pad0: Padding<c_int>,
1818
pub st_rdev: crate::dev_t,
1919
pub st_size: off_t,
2020
pub st_blksize: crate::blksize_t,
@@ -25,7 +25,7 @@ s! {
2525
pub st_mtime_nsec: c_long,
2626
pub st_ctime: crate::time_t,
2727
pub st_ctime_nsec: c_long,
28-
__unused: [c_long; 3],
28+
__unused: Padding<[c_long; 3]>,
2929
}
3030

3131
pub struct stat64 {
@@ -35,7 +35,7 @@ s! {
3535
pub st_mode: crate::mode_t,
3636
pub st_uid: crate::uid_t,
3737
pub st_gid: crate::gid_t,
38-
__pad0: c_int,
38+
__pad0: Padding<c_int>,
3939
pub st_rdev: crate::dev_t,
4040
pub st_size: off_t,
4141
pub st_blksize: crate::blksize_t,
@@ -46,7 +46,7 @@ s! {
4646
pub st_mtime_nsec: c_long,
4747
pub st_ctime: crate::time_t,
4848
pub st_ctime_nsec: c_long,
49-
__reserved: [c_long; 3],
49+
__reserved: Padding<[c_long; 3]>,
5050
}
5151

5252
pub struct mcontext_t {
@@ -61,8 +61,8 @@ s! {
6161
pub cgid: crate::gid_t,
6262
pub mode: crate::mode_t,
6363
pub __seq: c_int,
64-
__unused1: c_long,
65-
__unused2: c_long,
64+
__unused1: Padding<c_long>,
65+
__unused2: Padding<c_long>,
6666
}
6767

6868
pub struct ucontext_t {

src/hermit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ s! {
8787
pub struct sockaddr_storage {
8888
pub ss_len: u8,
8989
pub ss_family: sa_family_t,
90-
__ss_pad1: [u8; 6],
90+
__ss_pad1: Padding<[u8; 6]>,
9191
__ss_align: i64,
92-
__ss_pad2: [u8; 112],
92+
__ss_pad2: Padding<[u8; 112]>,
9393
}
9494

9595
pub struct stat {

src/new/linux_uapi/linux/can.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ s! {
4141
pub can_id: canid_t,
4242
// FIXME(1.0): this field was renamed to `len` in Linux 5.11
4343
pub can_dlc: u8,
44-
__pad: u8,
44+
__pad: Padding<u8>,
4545
__res0: u8,
4646
pub len8_dlc: u8,
4747
pub data: [u8; CAN_MAX_DLEN],

src/types.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Platform-agnostic support types.
22
3+
#[cfg(feature = "extra_traits")]
4+
use core::hash::Hash;
35
use core::mem::MaybeUninit;
46

57
use crate::prelude::*;
@@ -30,6 +32,21 @@ impl<T: Copy> fmt::Debug for Padding<T> {
3032
}
3133
}
3234

35+
#[cfg(feature = "extra_traits")]
36+
impl<T: Copy> Hash for Padding<T> {
37+
fn hash<H: hash::Hasher>(&self, _state: &mut H) {}
38+
}
39+
40+
#[cfg(feature = "extra_traits")]
41+
impl<T: Copy> PartialEq for Padding<T> {
42+
fn eq(&self, _other: &Self) -> bool {
43+
true
44+
}
45+
}
46+
47+
#[cfg(feature = "extra_traits")]
48+
impl<T: Copy> Eq for Padding<T> {}
49+
3350
/// The default repr type used for C style enums in Rust.
3451
#[cfg(target_env = "msvc")]
3552
#[allow(unused)]

src/unix/aix/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ s! {
251251
pub struct sockaddr_storage {
252252
pub __ss_len: c_uchar,
253253
pub ss_family: sa_family_t,
254-
__ss_pad1: [c_char; 6],
254+
__ss_pad1: Padding<[c_char; 6]>,
255255
__ss_align: crate::int64_t,
256-
__ss_pad2: [c_char; 1265],
256+
__ss_pad2: Padding<[c_char; 1265]>,
257257
}
258258

259259
pub struct sockaddr_un {

0 commit comments

Comments
 (0)