Merge branch 'termios-syssocket-cleanup' into 'master'

sys_socket and termios header cleanup

See merge request redox-os/relibc!1054
This commit is contained in:
Jeremy Soller
2026-02-28 10:31:05 -07:00
3 changed files with 19 additions and 20 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ pub const GRND_RANDOM: c_uint = 2;
#[unsafe(no_mangle)]
pub unsafe extern "C" fn getrandom(buf: *mut c_void, buflen: size_t, flags: c_uint) -> ssize_t {
Sys::getrandom(
unsafe { slice::from_raw_parts_mut(buf as *mut u8, buflen as usize) },
unsafe { slice::from_raw_parts_mut(buf.cast::<u8>(), buflen) },
flags,
)
.map(|read| read as ssize_t)
+12 -13
View File
@@ -86,7 +86,7 @@ const _SS_PADDING: usize = _SS_MAXSIZE - mem::size_of::<sa_family_t>() - mem::si
/// * The underscore fields are implementation specific details for padding that may change
/// * [`usize`] is used because it's the width of a pointer for a given platform
/// * The order of the fields is important because the bytes in the padding will be cast to and
/// from protocol structs in C
/// from protocol structs in C
#[repr(C)]
//#[derive(CheckVsLibcCrate)] FIXME: can't ignore private fields yet
pub struct sockaddr_storage {
@@ -106,13 +106,13 @@ pub unsafe extern "C" fn __CMSG_NEXT(cmsg: *const cmsghdr) -> *mut c_uchar {
}
pub unsafe extern "C" fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar {
unsafe { ((*mhdr).msg_control as *mut c_uchar).offset((*mhdr).msg_controllen as isize) }
unsafe { ((*mhdr).msg_control.cast::<c_uchar>()).add((*mhdr).msg_controllen) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_socket.h.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
unsafe { (cmsg as *mut c_uchar).offset(CMSG_ALIGN(mem::size_of::<cmsghdr>()) as isize) }
unsafe { (cmsg as *mut c_uchar).add(CMSG_ALIGN(mem::size_of::<cmsghdr>())) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_socket.h.html>.
@@ -123,14 +123,13 @@ pub unsafe extern "C" fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr)
};
unsafe {
let next = cmsg as usize
+ CMSG_ALIGN((*cmsg).cmsg_len as usize)
+ CMSG_ALIGN(mem::size_of::<cmsghdr>());
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize;
let next =
cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len) + CMSG_ALIGN(mem::size_of::<cmsghdr>());
let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen;
if next > max {
0 as *mut cmsghdr
ptr::null_mut::<cmsghdr>()
} else {
(cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize)) as *mut cmsghdr
(cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len)) as *mut cmsghdr
}
}
}
@@ -139,10 +138,10 @@ pub unsafe extern "C" fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr)
#[unsafe(no_mangle)]
pub unsafe extern "C" fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
unsafe {
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
(*mhdr).msg_control as *mut cmsghdr
if (*mhdr).msg_controllen >= mem::size_of::<cmsghdr>() {
(*mhdr).msg_control.cast::<cmsghdr>()
} else {
0 as *mut cmsghdr
ptr::null_mut::<cmsghdr>()
}
}
}
@@ -427,7 +426,7 @@ pub unsafe extern "C" fn socketpair(
) -> c_int {
trace_expr!(
Sys::socketpair(domain, kind, protocol, unsafe {
&mut *(sv as *mut [c_int; 2])
&mut *sv.cast::<[c_int; 2]>()
})
.map(|()| 0)
.or_minus_one_errno(),
+6 -6
View File
@@ -71,13 +71,13 @@ pub struct termios {
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcgetattr.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TCGETS, out as *mut c_void) }
unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TCGETS, out.cast::<c_void>()) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcsetattr.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *const termios) -> c_int {
if act < 0 || act > 2 {
if !(0..=2).contains(&act) {
platform::ERRNO.set(errno::EINVAL);
return -1;
}
@@ -89,7 +89,7 @@ pub unsafe extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *const termios)
#[unsafe(no_mangle)]
pub unsafe extern "C" fn tcgetsid(fd: c_int) -> pid_t {
let mut sid = 0;
if unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TIOCGSID, (&raw mut sid) as *mut c_void) } < 0 {
if unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TIOCGSID, (&raw mut sid).cast::<c_void>()) } < 0 {
return -1;
}
sid
@@ -196,7 +196,7 @@ pub unsafe extern "C" fn tcflush(fd: c_int, queue: c_int) -> c_int {
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcdrain.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn tcdrain(fd: c_int) -> c_int {
unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, 1 as *mut _) }
unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, core::ptr::dangling_mut()) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcsendbreak.html>.
@@ -204,7 +204,7 @@ pub unsafe extern "C" fn tcdrain(fd: c_int) -> c_int {
pub unsafe extern "C" fn tcsendbreak(fd: c_int, _dur: c_int) -> c_int {
// non-zero duration is ignored by musl due to it being
// implementation-defined. we do the same.
unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, 0 as *mut _) }
unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, core::ptr::null_mut()) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcgetwinsize.html>.
@@ -216,7 +216,7 @@ pub unsafe extern "C" fn tcgetwinsize(fd: c_int, sws: *mut winsize) -> c_int {
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcsetwinsize.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn tcsetwinsize(fd: c_int, sws: *const winsize) -> c_int {
unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TIOCSWINSZ, (sws as *mut winsize).cast()) }
unsafe { sys_ioctl::ioctl(fd, sys_ioctl::TIOCSWINSZ, sws.cast_mut().cast()) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcflow.html>.