summaryrefslogtreecommitdiffstats
path: root/vendor/linux-raw-sys/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /vendor/linux-raw-sys/src
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/linux-raw-sys/src')
-rw-r--r--vendor/linux-raw-sys/src/lib.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/linux-raw-sys/src/lib.rs b/vendor/linux-raw-sys/src/lib.rs
index 199cddefa..3204531d0 100644
--- a/vendor/linux-raw-sys/src/lib.rs
+++ b/vendor/linux-raw-sys/src/lib.rs
@@ -78,6 +78,59 @@ impl PartialEq for general::__kernel_timespec {
#[cfg(feature = "general")]
impl Eq for general::__kernel_timespec {}
+#[cfg(feature = "general")]
+pub mod cmsg_macros {
+ use crate::ctypes::{c_long, c_uint, c_uchar};
+ use crate::general::{cmsghdr, msghdr};
+ use core::mem::size_of;
+ use core::ptr;
+
+ pub unsafe fn CMSG_ALIGN(len: c_uint) -> c_uint {
+ let c_long_size = size_of::<c_long>() as c_uint;
+ (len + c_long_size - 1) & !(c_long_size - 1)
+ }
+
+ pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
+ (cmsg as *mut c_uchar).offset(size_of::<cmsghdr>() as isize)
+ }
+
+ pub unsafe fn CMSG_SPACE(len: c_uint) -> c_uint {
+ size_of::<cmsghdr>() as c_uint + CMSG_ALIGN(len)
+ }
+
+ pub unsafe fn CMSG_LEN(len: c_uint) -> c_uint {
+ size_of::<cmsghdr>() as c_uint + len
+ }
+
+ pub unsafe fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
+ if (*mhdr).msg_controllen < size_of::<cmsghdr>() as _ {
+ return ptr::null_mut();
+ }
+
+ (*mhdr).msg_control as *mut cmsghdr
+ }
+
+ pub unsafe fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
+ // We convert from raw pointers to isize here, which may not be sound in a future version of Rust.
+ // Once the provenance rules are set in stone, it will be a good idea to give this function a once-over.
+
+ let cmsg_len = (*cmsg).cmsg_len;
+ let next_cmsg = (cmsg as *mut u8).offset(CMSG_ALIGN(cmsg_len as _) as isize) as *mut cmsghdr;
+ let max = ((*mhdr).msg_control as usize) + ((*mhdr).msg_controllen as usize);
+
+ if cmsg_len < size_of::<cmsghdr>() as _ {
+ return ptr::null_mut();
+ }
+
+ if next_cmsg.offset(1) as usize > max || next_cmsg as usize + CMSG_ALIGN(cmsg_len as _) as usize > max
+ {
+ return ptr::null_mut();
+ }
+
+ next_cmsg
+ }
+}
+
// The rest of this file is auto-generated!
#[cfg(feature = "errno")]
#[cfg(target_arch = "arm")]