Skip to content

Commit

Permalink
Specialize CMSG_NXTHDR for Android and Emscripten
Browse files Browse the repository at this point in the history
  • Loading branch information
asomers committed Feb 5, 2019
1 parent 4300666 commit eddc8d3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
14 changes: 14 additions & 0 deletions src/unix/notbsd/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,20 @@ pub const MODULE_INIT_IGNORE_VERMAGIC: ::c_uint = 0x0002;
pub const ENOATTR: ::c_int = ::ENODATA;

f! {
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
cmsg: *const cmsghdr) -> *mut cmsghdr {
let next = (cmsg as usize
+ super::CMSG_ALIGN((*cmsg).cmsg_len as usize))
as *mut cmsghdr;
let max = (*mhdr).msg_control as usize
+ (*mhdr).msg_controllen as usize;
if (next.offset(1)) as usize > max {
0 as *mut cmsghdr
} else {
next as *mut cmsghdr
}
}

pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
for slot in cpuset.__bits.iter_mut() {
*slot = 0;
Expand Down
17 changes: 17 additions & 0 deletions src/unix/notbsd/emscripten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,23 @@ pub const ARPD_FLUSH: ::c_ushort = 0x03;
pub const ATF_MAGIC: ::c_int = 0x80;

f! {
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
cmsg: *const cmsghdr) -> *mut cmsghdr {
if ((*cmsg).cmsg_len as usize) < mem::size_of::<cmsghdr>() {
return 0 as *mut cmsghdr;
};
let next = (cmsg as usize +
super::CMSG_ALIGN((*cmsg).cmsg_len as usize))
as *mut cmsghdr;
let max = (*mhdr).msg_control as usize
+ (*mhdr).msg_controllen as usize;
if (next.offset(1)) as usize > max {
0 as *mut cmsghdr
} else {
next as *mut cmsghdr
}
}

pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
for slot in cpuset.bits.iter_mut() {
*slot = 0;
Expand Down
19 changes: 19 additions & 0 deletions src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,25 @@ pub const SOF_TIMESTAMPING_SYS_HARDWARE: ::c_uint = 1 << 5;
pub const SOF_TIMESTAMPING_RAW_HARDWARE: ::c_uint = 1 << 6;

f! {
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
cmsg: *const cmsghdr) -> *mut cmsghdr {
if ((*cmsg).cmsg_len as usize) < mem::size_of::<cmsghdr>() {
return 0 as *mut cmsghdr;
};
let next = (cmsg as usize +
super::CMSG_ALIGN((*cmsg).cmsg_len as usize))
as *mut cmsghdr;
let max = (*mhdr).msg_control as usize
+ (*mhdr).msg_controllen as usize;
if (next.offset(1)) as usize > max ||
next as usize + super::CMSG_ALIGN((*next).cmsg_len as usize) > max
{
0 as *mut cmsghdr
} else {
next as *mut cmsghdr
}
}

pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
for slot in cpuset.bits.iter_mut() {
*slot = 0;
Expand Down
18 changes: 0 additions & 18 deletions src/unix/notbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,24 +1127,6 @@ f! {
}
}

pub fn CMSG_NXTHDR(mhdr: *const msghdr,
cmsg: *const cmsghdr) -> *mut cmsghdr {
if ((*cmsg).cmsg_len as usize) < mem::size_of::<cmsghdr>() {
return 0 as *mut cmsghdr;
};
let next = (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize))
as *mut cmsghdr;
let max = (*mhdr).msg_control as usize
+ (*mhdr).msg_controllen as usize;
if (next.offset(1)) as usize > max
|| next as usize + CMSG_ALIGN((*next).cmsg_len as usize) > max
{
0 as *mut cmsghdr
} else {
next as *mut cmsghdr
}
}

pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut ::c_uchar {
cmsg.offset(1) as *mut ::c_uchar
}
Expand Down

0 comments on commit eddc8d3

Please sign in to comment.