Skip to content

Commit eddc8d3

Browse files
committed
Specialize CMSG_NXTHDR for Android and Emscripten
1 parent 4300666 commit eddc8d3

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
lines changed

src/unix/notbsd/android/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,20 @@ pub const MODULE_INIT_IGNORE_VERMAGIC: ::c_uint = 0x0002;
16881688
pub const ENOATTR: ::c_int = ::ENODATA;
16891689

16901690
f! {
1691+
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
1692+
cmsg: *const cmsghdr) -> *mut cmsghdr {
1693+
let next = (cmsg as usize
1694+
+ super::CMSG_ALIGN((*cmsg).cmsg_len as usize))
1695+
as *mut cmsghdr;
1696+
let max = (*mhdr).msg_control as usize
1697+
+ (*mhdr).msg_controllen as usize;
1698+
if (next.offset(1)) as usize > max {
1699+
0 as *mut cmsghdr
1700+
} else {
1701+
next as *mut cmsghdr
1702+
}
1703+
}
1704+
16911705
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
16921706
for slot in cpuset.__bits.iter_mut() {
16931707
*slot = 0;

src/unix/notbsd/emscripten.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,23 @@ pub const ARPD_FLUSH: ::c_ushort = 0x03;
15151515
pub const ATF_MAGIC: ::c_int = 0x80;
15161516

15171517
f! {
1518+
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
1519+
cmsg: *const cmsghdr) -> *mut cmsghdr {
1520+
if ((*cmsg).cmsg_len as usize) < mem::size_of::<cmsghdr>() {
1521+
return 0 as *mut cmsghdr;
1522+
};
1523+
let next = (cmsg as usize +
1524+
super::CMSG_ALIGN((*cmsg).cmsg_len as usize))
1525+
as *mut cmsghdr;
1526+
let max = (*mhdr).msg_control as usize
1527+
+ (*mhdr).msg_controllen as usize;
1528+
if (next.offset(1)) as usize > max {
1529+
0 as *mut cmsghdr
1530+
} else {
1531+
next as *mut cmsghdr
1532+
}
1533+
}
1534+
15181535
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
15191536
for slot in cpuset.bits.iter_mut() {
15201537
*slot = 0;

src/unix/notbsd/linux/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,25 @@ pub const SOF_TIMESTAMPING_SYS_HARDWARE: ::c_uint = 1 << 5;
18971897
pub const SOF_TIMESTAMPING_RAW_HARDWARE: ::c_uint = 1 << 6;
18981898

18991899
f! {
1900+
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
1901+
cmsg: *const cmsghdr) -> *mut cmsghdr {
1902+
if ((*cmsg).cmsg_len as usize) < mem::size_of::<cmsghdr>() {
1903+
return 0 as *mut cmsghdr;
1904+
};
1905+
let next = (cmsg as usize +
1906+
super::CMSG_ALIGN((*cmsg).cmsg_len as usize))
1907+
as *mut cmsghdr;
1908+
let max = (*mhdr).msg_control as usize
1909+
+ (*mhdr).msg_controllen as usize;
1910+
if (next.offset(1)) as usize > max ||
1911+
next as usize + super::CMSG_ALIGN((*next).cmsg_len as usize) > max
1912+
{
1913+
0 as *mut cmsghdr
1914+
} else {
1915+
next as *mut cmsghdr
1916+
}
1917+
}
1918+
19001919
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
19011920
for slot in cpuset.bits.iter_mut() {
19021921
*slot = 0;

src/unix/notbsd/mod.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,24 +1127,6 @@ f! {
11271127
}
11281128
}
11291129

1130-
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
1131-
cmsg: *const cmsghdr) -> *mut cmsghdr {
1132-
if ((*cmsg).cmsg_len as usize) < mem::size_of::<cmsghdr>() {
1133-
return 0 as *mut cmsghdr;
1134-
};
1135-
let next = (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize))
1136-
as *mut cmsghdr;
1137-
let max = (*mhdr).msg_control as usize
1138-
+ (*mhdr).msg_controllen as usize;
1139-
if (next.offset(1)) as usize > max
1140-
|| next as usize + CMSG_ALIGN((*next).cmsg_len as usize) > max
1141-
{
1142-
0 as *mut cmsghdr
1143-
} else {
1144-
next as *mut cmsghdr
1145-
}
1146-
}
1147-
11481130
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut ::c_uchar {
11491131
cmsg.offset(1) as *mut ::c_uchar
11501132
}

0 commit comments

Comments
 (0)