From cae30932b3a26f61a2e4034cc1a7613f542ec128 Mon Sep 17 00:00:00 2001 From: auronandace Date: Wed, 3 Dec 2025 14:06:55 +0000 Subject: [PATCH 1/2] update and add spec links in sys_socket and sys_stat --- src/header/sys_socket/mod.rs | 31 ++++++++++++++++++++++++++++++- src/header/sys_stat/mod.rs | 18 +++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index 24578482d9..ad04a1c847 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -1,4 +1,6 @@ -//! socket implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xns/syssocket.h.html +//! `sys/socket.h` implementation. +//! +//! See . use core::{mem, ptr}; @@ -13,6 +15,7 @@ pub mod constants; pub type sa_family_t = u16; pub type socklen_t = u32; +/// See . #[repr(C)] #[derive(Default, CheckVsLibcCrate)] pub struct linger { @@ -23,6 +26,7 @@ pub struct linger { #[unsafe(no_mangle)] pub extern "C" fn _cbindgen_export_linger(linger: linger) {} +/// See . #[repr(C)] #[derive(Debug, CheckVsLibcCrate)] pub struct msghdr { @@ -35,6 +39,7 @@ pub struct msghdr { pub msg_flags: c_int, } +/// See . #[repr(C)] #[derive(Debug, CheckVsLibcCrate)] pub struct cmsghdr { @@ -55,6 +60,7 @@ pub struct ucred { #[unsafe(no_mangle)] pub extern "C" fn _cbindgen_export_cmsghdr(cmsghdr: cmsghdr) {} +/// See . #[repr(C)] #[derive(Default, CheckVsLibcCrate)] pub struct sockaddr { @@ -67,6 +73,7 @@ const _SS_MAXSIZE: usize = 128; // Align to pointer width const _SS_PADDING: usize = _SS_MAXSIZE - mem::size_of::() - mem::size_of::(); +/// See . /// Opaque storage large enough to hold any protocol specific address structure. /// /// ## Implementation notes @@ -97,11 +104,13 @@ 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) } } +/// See . #[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::()) as isize) } } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { if cmsg.is_null() { @@ -121,6 +130,7 @@ pub unsafe extern "C" fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) } } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr { unsafe { @@ -137,17 +147,20 @@ pub unsafe extern "C" fn CMSG_ALIGN(len: size_t) -> size_t { (len + mem::size_of::() - 1) & !(mem::size_of::() - 1) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn CMSG_SPACE(len: c_uint) -> c_uint { (CMSG_ALIGN(len as size_t) + CMSG_ALIGN(mem::size_of::())) as c_uint } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn CMSG_LEN(length: c_uint) -> c_uint { (CMSG_ALIGN(mem::size_of::()) + length as usize) as c_uint } // } These must match C macros in include/bits/sys/socket.h +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn accept( socket: c_int, @@ -163,6 +176,7 @@ pub unsafe extern "C" fn accept( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn bind( socket: c_int, @@ -180,6 +194,7 @@ pub unsafe extern "C" fn bind( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn connect( socket: c_int, @@ -195,6 +210,7 @@ pub unsafe extern "C" fn connect( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn getpeername( socket: c_int, @@ -212,6 +228,7 @@ pub unsafe extern "C" fn getpeername( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn getsockname( socket: c_int, @@ -229,6 +246,7 @@ pub unsafe extern "C" fn getsockname( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn getsockopt( socket: c_int, @@ -250,6 +268,7 @@ pub unsafe extern "C" fn getsockopt( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn listen(socket: c_int, backlog: c_int) -> c_int { Sys::listen(socket, backlog) @@ -257,6 +276,7 @@ pub unsafe extern "C" fn listen(socket: c_int, backlog: c_int) -> c_int { .or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn recv( socket: c_int, @@ -274,6 +294,7 @@ pub unsafe extern "C" fn recv( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn recvfrom( socket: c_int, @@ -297,6 +318,7 @@ pub unsafe extern "C" fn recvfrom( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn recvmsg(socket: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t { Sys::recvmsg(socket, msg, flags) @@ -304,6 +326,7 @@ pub unsafe extern "C" fn recvmsg(socket: c_int, msg: *mut msghdr, flags: c_int) .or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn send( socket: c_int, @@ -314,6 +337,7 @@ pub unsafe extern "C" fn send( sendto(socket, message, length, flags, ptr::null(), 0) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn sendmsg(socket: c_int, msg: *const msghdr, flags: c_int) -> ssize_t { Sys::sendmsg(socket, msg, flags) @@ -321,6 +345,7 @@ pub unsafe extern "C" fn sendmsg(socket: c_int, msg: *const msghdr, flags: c_int .or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn sendto( socket: c_int, @@ -344,6 +369,7 @@ pub unsafe extern "C" fn sendto( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn setsockopt( socket: c_int, @@ -365,11 +391,13 @@ pub unsafe extern "C" fn setsockopt( ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn shutdown(socket: c_int, how: c_int) -> c_int { Sys::shutdown(socket, how).map(|()| 0).or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int { trace_expr!( @@ -381,6 +409,7 @@ pub unsafe extern "C" fn socket(domain: c_int, kind: c_int, protocol: c_int) -> ) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn socketpair( domain: c_int, diff --git a/src/header/sys_stat/mod.rs b/src/header/sys_stat/mod.rs index 01fa741e77..a3f6249353 100644 --- a/src/header/sys_stat/mod.rs +++ b/src/header/sys_stat/mod.rs @@ -1,4 +1,6 @@ -//! stat implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html +//! `sys/stat.h` implementation. +//! +//! See . use crate::{ c_str::CStr, @@ -47,6 +49,7 @@ pub const S_ISVTX: c_int = 0o1_000; pub const UTIME_NOW: useconds_t = (1 << 30) - 1; pub const UTIME_OMIT: useconds_t = (1 << 30) - 2; +/// See . #[repr(C)] #[derive(Default)] pub struct stat { @@ -71,17 +74,20 @@ pub struct stat { pub _pad: [c_char; 24], } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn chmod(path: *const c_char, mode: mode_t) -> c_int { let path = CStr::from_ptr(path); Sys::chmod(path, mode).map(|()| 0).or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub extern "C" fn fchmod(fildes: c_int, mode: mode_t) -> c_int { Sys::fchmod(fildes, mode).map(|()| 0).or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn fchmodat( dirfd: c_int, @@ -95,12 +101,14 @@ pub unsafe extern "C" fn fchmodat( .or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn fstat(fildes: c_int, buf: *mut stat) -> c_int { let buf = Out::nonnull(buf); Sys::fstat(fildes, buf).map(|()| 0).or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn fstatat( fildes: c_int, @@ -120,11 +128,13 @@ pub unsafe extern "C" fn __fxstat(_ver: c_int, fildes: c_int, buf: *mut stat) -> fstat(fildes, buf) } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn futimens(fd: c_int, times: *const timespec) -> c_int { Sys::futimens(fd, times).map(|()| 0).or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn lstat(path: *const c_char, buf: *mut stat) -> c_int { let path = CStr::from_ptr(path); @@ -144,24 +154,28 @@ pub unsafe extern "C" fn lstat(path: *const c_char, buf: *mut stat) -> c_int { res } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn mkdir(path: *const c_char, mode: mode_t) -> c_int { let path = CStr::from_ptr(path); Sys::mkdir(path, mode).map(|()| 0).or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn mkfifo(path: *const c_char, mode: mode_t) -> c_int { let path = CStr::from_ptr(path); Sys::mkfifo(path, mode).map(|()| 0).or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn mknod(path: *const c_char, mode: mode_t, dev: dev_t) -> c_int { let path = CStr::from_ptr(path); Sys::mknod(path, mode, dev).map(|()| 0).or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn mknodat( dirfd: c_int, @@ -175,6 +189,7 @@ pub unsafe extern "C" fn mknodat( .or_minus_one_errno() } +/// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn stat(file: *const c_char, buf: *mut stat) -> c_int { let file = CStr::from_ptr(file); @@ -194,6 +209,7 @@ pub unsafe extern "C" fn stat(file: *const c_char, buf: *mut stat) -> c_int { res } +/// See . #[unsafe(no_mangle)] pub extern "C" fn umask(mask: mode_t) -> mode_t { Sys::umask(mask) From 1e27ad561fad4602c737a7c06c7f914e3808667b Mon Sep 17 00:00:00 2001 From: auronandace Date: Wed, 3 Dec 2025 14:16:19 +0000 Subject: [PATCH 2/2] only import needed types in sys_socket and sys_stat --- src/header/sys_socket/mod.rs | 7 ++++++- src/header/sys_stat/mod.rs | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index ad04a1c847..e555d23e3f 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -7,7 +7,12 @@ use core::{mem, ptr}; use crate::{ error::ResultExt, header::sys_uio::iovec, - platform::{PalSocket, Sys, types::*}, + platform::{ + PalSocket, Sys, + types::{ + c_char, c_int, c_long, c_uchar, c_uint, c_void, gid_t, pid_t, size_t, ssize_t, uid_t, + }, + }, }; pub mod constants; diff --git a/src/header/sys_stat/mod.rs b/src/header/sys_stat/mod.rs index a3f6249353..aa09ef21c0 100644 --- a/src/header/sys_stat/mod.rs +++ b/src/header/sys_stat/mod.rs @@ -10,7 +10,13 @@ use crate::{ time::timespec, }, out::Out, - platform::{Pal, Sys, types::*}, + platform::{ + Pal, Sys, + types::{ + blkcnt_t, blksize_t, c_char, c_int, dev_t, gid_t, ino_t, mode_t, nlink_t, off_t, uid_t, + useconds_t, + }, + }, }; pub const S_IFMT: c_int = 0o0_170_000;