Skip to content
Merged
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
28 changes: 14 additions & 14 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3250,20 +3250,20 @@ cfg_if! {
f! {
pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
let size = mem::size_of_val(&(*set).fds_bits[0]) * 8;
let size = size_of_val(&(*set).fds_bits[0]) * 8;
(*set).fds_bits[fd / size] &= !(1 << (fd % size));
return;
}

pub fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
let fd = fd as usize;
let size = mem::size_of_val(&(*set).fds_bits[0]) * 8;
let size = size_of_val(&(*set).fds_bits[0]) * 8;
return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0;
}

pub fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
let size = mem::size_of_val(&(*set).fds_bits[0]) * 8;
let size = size_of_val(&(*set).fds_bits[0]) * 8;
(*set).fds_bits[fd / size] |= 1 << (fd % size);
return;
}
Expand All @@ -3281,21 +3281,21 @@ f! {
}

pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.bits[idx] |= 1 << offset;
()
}

pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]); // 32, 64 etc
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.bits[idx] &= !(1 << offset);
()
}

pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool {
let size_in_bits = 8 * mem::size_of_val(&cpuset.bits[0]);
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]);
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
0 != (cpuset.bits[idx] & (1 << offset))
}
Expand All @@ -3309,33 +3309,33 @@ f! {
}

pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
if ((*cmsg).cmsg_len as size_t) < mem::size_of::<cmsghdr>() {
if ((*cmsg).cmsg_len as size_t) < size_of::<cmsghdr>() {
core::ptr::null_mut::<cmsghdr>()
} else if __CMSG_NEXT(cmsg).add(mem::size_of::<cmsghdr>()) >= __MHDR_END(mhdr) {
} else if __CMSG_NEXT(cmsg).add(size_of::<cmsghdr>()) >= __MHDR_END(mhdr) {
core::ptr::null_mut::<cmsghdr>()
} else {
__CMSG_NEXT(cmsg).cast()
}
}

pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
if (*mhdr).msg_controllen as size_t >= mem::size_of::<cmsghdr>() {
if (*mhdr).msg_controllen as size_t >= size_of::<cmsghdr>() {
(*mhdr).msg_control.cast()
} else {
core::ptr::null_mut::<cmsghdr>()
}
}

pub {const} fn CMSG_ALIGN(len: size_t) -> size_t {
(len + mem::size_of::<size_t>() - 1) & !(mem::size_of::<size_t>() - 1)
(len + size_of::<size_t>() - 1) & !(size_of::<size_t>() - 1)
}

pub {const} fn CMSG_SPACE(len: c_uint) -> c_uint {
(CMSG_ALIGN(len as size_t) + CMSG_ALIGN(mem::size_of::<cmsghdr>())) as c_uint
(CMSG_ALIGN(len as size_t) + CMSG_ALIGN(size_of::<cmsghdr>())) as c_uint
}

pub {const} fn CMSG_LEN(len: c_uint) -> c_uint {
(CMSG_ALIGN(mem::size_of::<cmsghdr>()) + len as size_t) as c_uint
(CMSG_ALIGN(size_of::<cmsghdr>()) + len as size_t) as c_uint
}
}

Expand Down Expand Up @@ -3403,8 +3403,8 @@ safe_f! {
}

fn __CMSG_LEN(cmsg: *const cmsghdr) -> ssize_t {
((unsafe { (*cmsg).cmsg_len as size_t } + mem::size_of::<c_long>() - 1)
& !(mem::size_of::<c_long>() - 1)) as ssize_t
((unsafe { (*cmsg).cmsg_len as size_t } + size_of::<c_long>() - 1) & !(size_of::<c_long>() - 1))
as ssize_t
}

fn __CMSG_NEXT(cmsg: *const cmsghdr) -> *mut c_uchar {
Expand Down
2 changes: 2 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ macro_rules! prelude {
pub(crate) use ::core::option::Option;
#[allow(unused_imports)]
pub(crate) use ::core::{fmt, hash, iter, mem};
#[allow(unused_imports)]
pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};

// Commonly used types defined in this crate
#[allow(unused_imports)]
Expand Down
16 changes: 8 additions & 8 deletions src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ cfg_if! {
// // catch the fact that llvm and gcc disagree on how x64 __int128
// // is actually *passed* on the stack (clang underaligns it for
// // the same reason that rustc *never* properly aligns it).
// static_assert_eq!(core::mem::size_of::<__int128>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__int128>(), _ALIGN_128);
// static_assert_eq!(size_of::<__int128>(), _SIZE_128);
// static_assert_eq!(align_of::<__int128>(), _ALIGN_128);

// static_assert_eq!(core::mem::size_of::<__uint128>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__uint128>(), _ALIGN_128);
// static_assert_eq!(size_of::<__uint128>(), _SIZE_128);
// static_assert_eq!(align_of::<__uint128>(), _ALIGN_128);

// static_assert_eq!(core::mem::size_of::<__int128_t>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__int128_t>(), _ALIGN_128);
// static_assert_eq!(size_of::<__int128_t>(), _SIZE_128);
// static_assert_eq!(align_of::<__int128_t>(), _ALIGN_128);

// static_assert_eq!(core::mem::size_of::<__uint128_t>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__uint128_t>(), _ALIGN_128);
// static_assert_eq!(size_of::<__uint128_t>(), _SIZE_128);
// static_assert_eq!(align_of::<__uint128_t>(), _ALIGN_128);
} else if #[cfg(all(
target_arch = "aarch64",
any(
Expand Down
8 changes: 4 additions & 4 deletions src/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct pthread_attr_t {

#[repr(C)]
pub struct cpu_set_t {
bits: [c_ulong; 128 / core::mem::size_of::<c_ulong>()],
bits: [c_ulong; 128 / size_of::<c_ulong>()],
}

#[repr(C)]
Expand Down Expand Up @@ -137,7 +137,7 @@ pub struct mbstate_t {

#[repr(C)]
pub struct sem_t {
pub __val: [c_int; 4 * core::mem::size_of::<c_long>() / core::mem::size_of::<c_int>()],
pub __val: [c_int; 4 * size_of::<c_long>() / size_of::<c_int>()],
}

#[repr(C)]
Expand Down Expand Up @@ -1342,7 +1342,7 @@ pub fn errno() -> c_int {

pub fn CPU_COUNT_S(size: usize, cpuset: &cpu_set_t) -> c_int {
let mut s: u32 = 0;
let size_of_mask = core::mem::size_of_val(&cpuset.bits[0]);
let size_of_mask = size_of_val(&cpuset.bits[0]);

for i in cpuset.bits[..(size / size_of_mask)].iter() {
s += i.count_ones();
Expand All @@ -1351,5 +1351,5 @@ pub fn CPU_COUNT_S(size: usize, cpuset: &cpu_set_t) -> c_int {
}

pub fn CPU_COUNT(cpuset: &cpu_set_t) -> c_int {
CPU_COUNT_S(core::mem::size_of::<cpu_set_t>(), cpuset)
CPU_COUNT_S(size_of::<cpu_set_t>(), cpuset)
}
16 changes: 8 additions & 8 deletions src/unix/aix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2433,7 +2433,7 @@ pub const ACCOUNTING: c_short = 9;

f! {
pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
if (*mhdr).msg_controllen as usize >= size_of::<cmsghdr>() {
(*mhdr).msg_control as *mut cmsghdr
} else {
core::ptr::null_mut::<cmsghdr>()
Expand All @@ -2444,7 +2444,7 @@ f! {
if cmsg.is_null() {
CMSG_FIRSTHDR(mhdr)
} else {
if (cmsg as usize + (*cmsg).cmsg_len as usize + mem::size_of::<cmsghdr>())
if (cmsg as usize + (*cmsg).cmsg_len as usize + size_of::<cmsghdr>())
> ((*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize)
{
core::ptr::null_mut::<cmsghdr>()
Expand All @@ -2456,15 +2456,15 @@ f! {
}

pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(mem::size_of::<cmsghdr>() as isize)
(cmsg as *mut c_uchar).offset(size_of::<cmsghdr>() as isize)
}

pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
mem::size_of::<cmsghdr>() as c_uint + length
size_of::<cmsghdr>() as c_uint + length
}

pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
mem::size_of::<cmsghdr>() as c_uint + length
size_of::<cmsghdr>() as c_uint + length
}

pub fn FD_ZERO(set: *mut fd_set) -> () {
Expand All @@ -2474,21 +2474,21 @@ f! {
}

pub fn FD_SET(fd: c_int, set: *mut fd_set) -> () {
let bits = mem::size_of::<c_long>() * 8;
let bits = size_of::<c_long>() * 8;
let fd = fd as usize;
(*set).fds_bits[fd / bits] |= 1 << (fd % bits);
return;
}

pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
let bits = mem::size_of::<c_long>() * 8;
let bits = size_of::<c_long>() * 8;
let fd = fd as usize;
(*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
return;
}

pub fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool {
let bits = mem::size_of::<c_long>() * 8;
let bits = size_of::<c_long>() * 8;
let fd = fd as usize;
return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0;
}
Expand Down
46 changes: 20 additions & 26 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4470,7 +4470,7 @@ pub const PROC_PIDVNODEPATHINFO: c_int = 9;
pub const PROC_PIDPATHINFO_MAXSIZE: c_int = 4096;

pub const PROC_PIDLISTFDS: c_int = 1;
pub const PROC_PIDLISTFD_SIZE: c_int = mem::size_of::<proc_fdinfo>() as c_int;
pub const PROC_PIDLISTFD_SIZE: c_int = size_of::<proc_fdinfo>() as c_int;
pub const PROX_FDTYPE_ATALK: c_int = 0;
pub const PROX_FDTYPE_VNODE: c_int = 1;
pub const PROX_FDTYPE_SOCKET: c_int = 2;
Expand Down Expand Up @@ -4956,48 +4956,42 @@ pub const VMADDR_CID_HOST: c_uint = 2;
pub const VMADDR_PORT_ANY: c_uint = 0xFFFFFFFF;

const fn __DARWIN_ALIGN32(p: usize) -> usize {
const __DARWIN_ALIGNBYTES32: usize = mem::size_of::<u32>() - 1;
const __DARWIN_ALIGNBYTES32: usize = size_of::<u32>() - 1;
(p + __DARWIN_ALIGNBYTES32) & !__DARWIN_ALIGNBYTES32
}

pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_extended_policy_data_t>() / mem::size_of::<integer_t>())
as mach_msg_type_number_t;
(size_of::<thread_extended_policy_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_time_constraint_policy_data_t>() / mem::size_of::<integer_t>())
(size_of::<thread_time_constraint_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_precedence_policy_data_t>() / mem::size_of::<integer_t>())
(size_of::<thread_precedence_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_AFFINITY_POLICY_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_affinity_policy_data_t>() / mem::size_of::<integer_t>())
as mach_msg_type_number_t;
(size_of::<thread_affinity_policy_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_BACKGROUND_POLICY_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_background_policy_data_t>() / mem::size_of::<integer_t>())
(size_of::<thread_background_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_LATENCY_QOS_POLICY_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_latency_qos_policy_data_t>() / mem::size_of::<integer_t>())
(size_of::<thread_latency_qos_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_THROUGHPUT_QOS_POLICY_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_throughput_qos_policy_data_t>() / mem::size_of::<integer_t>())
(size_of::<thread_throughput_qos_policy_data_t>() / size_of::<integer_t>())
as mach_msg_type_number_t;
pub const THREAD_BASIC_INFO_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_basic_info_data_t>() / mem::size_of::<integer_t>())
as mach_msg_type_number_t;
(size_of::<thread_basic_info_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_IDENTIFIER_INFO_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_identifier_info_data_t>() / mem::size_of::<integer_t>())
as mach_msg_type_number_t;
(size_of::<thread_identifier_info_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;
pub const THREAD_EXTENDED_INFO_COUNT: mach_msg_type_number_t =
(mem::size_of::<thread_extended_info_data_t>() / mem::size_of::<integer_t>())
as mach_msg_type_number_t;
(size_of::<thread_extended_info_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;

pub const TASK_THREAD_TIMES_INFO_COUNT: u32 =
(mem::size_of::<task_thread_times_info_data_t>() / mem::size_of::<natural_t>()) as u32;
(size_of::<task_thread_times_info_data_t>() / size_of::<natural_t>()) as u32;
pub const MACH_TASK_BASIC_INFO_COUNT: u32 =
(mem::size_of::<mach_task_basic_info_data_t>() / mem::size_of::<natural_t>()) as u32;
pub const HOST_VM_INFO64_COUNT: mach_msg_type_number_t = (mem::size_of::<vm_statistics64_data_t>()
/ mem::size_of::<integer_t>())
as mach_msg_type_number_t;
(size_of::<mach_task_basic_info_data_t>() / size_of::<natural_t>()) as u32;
pub const HOST_VM_INFO64_COUNT: mach_msg_type_number_t =
(size_of::<vm_statistics64_data_t>() / size_of::<integer_t>()) as mach_msg_type_number_t;

// bsd/net/if_mib.h
/// Non-interface-specific
Expand Down Expand Up @@ -5036,23 +5030,23 @@ f! {
let cmsg_len = (*cmsg).cmsg_len as usize;
let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len);
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
if next + __DARWIN_ALIGN32(mem::size_of::<cmsghdr>()) > max {
if next + __DARWIN_ALIGN32(size_of::<cmsghdr>()) > max {
core::ptr::null_mut()
} else {
next as *mut cmsghdr
}
}

pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).add(__DARWIN_ALIGN32(mem::size_of::<cmsghdr>()))
(cmsg as *mut c_uchar).add(__DARWIN_ALIGN32(size_of::<cmsghdr>()))
}

pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
(__DARWIN_ALIGN32(mem::size_of::<cmsghdr>()) + __DARWIN_ALIGN32(length as usize)) as c_uint
(__DARWIN_ALIGN32(size_of::<cmsghdr>()) + __DARWIN_ALIGN32(length as usize)) as c_uint
}

pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
(__DARWIN_ALIGN32(mem::size_of::<cmsghdr>()) + length as usize) as c_uint
(__DARWIN_ALIGN32(size_of::<cmsghdr>()) + length as usize) as c_uint
}

pub {const} fn VM_MAKE_TAG(id: u8) -> u32 {
Expand Down
12 changes: 6 additions & 6 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ pub const CPUCTL_MSRSBIT: c_int = 0xc0106305;
pub const CPUCTL_MSRCBIT: c_int = 0xc0106306;
pub const CPUCTL_CPUID_COUNT: c_int = 0xc0106307;

pub const CPU_SETSIZE: size_t = mem::size_of::<crate::cpumask_t>() * 8;
pub const CPU_SETSIZE: size_t = size_of::<crate::cpumask_t>() * 8;

pub const EVFILT_READ: i16 = -1;
pub const EVFILT_WRITE: i16 = -2;
Expand Down Expand Up @@ -1421,23 +1421,23 @@ pub const RTAX_MAX: c_int = 11;

const_fn! {
{const} fn _CMSG_ALIGN(n: usize) -> usize {
(n + (mem::size_of::<c_long>() - 1)) & !(mem::size_of::<c_long>() - 1)
(n + (size_of::<c_long>() - 1)) & !(size_of::<c_long>() - 1)
}
}

f! {
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(_CMSG_ALIGN(mem::size_of::<cmsghdr>()) as isize)
(cmsg as *mut c_uchar).offset(_CMSG_ALIGN(size_of::<cmsghdr>()) as isize)
}

pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
(_CMSG_ALIGN(mem::size_of::<cmsghdr>()) + length as usize) as c_uint
(_CMSG_ALIGN(size_of::<cmsghdr>()) + length as usize) as c_uint
}

pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
let next = cmsg as usize
+ _CMSG_ALIGN((*cmsg).cmsg_len as usize)
+ _CMSG_ALIGN(mem::size_of::<cmsghdr>());
+ _CMSG_ALIGN(size_of::<cmsghdr>());
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
if next <= max {
(cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr
Expand All @@ -1447,7 +1447,7 @@ f! {
}

pub {const} fn CMSG_SPACE(length: c_uint) -> c_uint {
(_CMSG_ALIGN(mem::size_of::<cmsghdr>()) + _CMSG_ALIGN(length as usize)) as c_uint
(_CMSG_ALIGN(size_of::<cmsghdr>()) + _CMSG_ALIGN(length as usize)) as c_uint
}

pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/freebsdlike/freebsd/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ s_no_extra_traits! {
}
}

pub(crate) const _ALIGNBYTES: usize = mem::size_of::<c_longlong>() - 1;
pub(crate) const _ALIGNBYTES: usize = size_of::<c_longlong>() - 1;

cfg_if! {
if #[cfg(feature = "extra_traits")] {
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/freebsdlike/freebsd/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ cfg_if! {
}
}

pub(crate) const _ALIGNBYTES: usize = mem::size_of::<c_int>() - 1;
pub(crate) const _ALIGNBYTES: usize = size_of::<c_int>() - 1;

pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d;
pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e;
Expand Down
Loading
Loading