From f5c0c1a9c91c5f2fed56724681273a922236e2b5 Mon Sep 17 00:00:00 2001 From: auronandace Date: Tue, 16 Jun 2026 08:04:26 +0100 Subject: [PATCH] split out ucred to a bits header --- src/header/bits_ucred/cbindgen.toml | 17 +++++++++++++++++ src/header/bits_ucred/mod.rs | 16 ++++++++++++++++ src/header/mod.rs | 1 + src/header/sys_socket/cbindgen.toml | 8 +++----- src/header/sys_socket/mod.rs | 20 +------------------- src/platform/redox/socket.rs | 3 ++- 6 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 src/header/bits_ucred/cbindgen.toml create mode 100644 src/header/bits_ucred/mod.rs diff --git a/src/header/bits_ucred/cbindgen.toml b/src/header/bits_ucred/cbindgen.toml new file mode 100644 index 0000000000..0a3788acdc --- /dev/null +++ b/src/header/bits_ucred/cbindgen.toml @@ -0,0 +1,17 @@ +# Non-POSIX spec: https://www.man7.org/linux/man-pages/man7/unix.7.html +# +# This type is split out to avoid namespace pollution in sys/socket.h. +after_includes = """ +#include // for gid_t from sys/types.h +#include // for pid_t from sys/types.h +#include // for uid_t from sys/types.h +""" +include_guard = "_RELIBC_BITS_UCRED_H" +language = "C" +style = "Tag" +no_includes = true +cpp_compat = true +[export] +include = ["ucred"] +[enum] +prefix_with_name = true diff --git a/src/header/bits_ucred/mod.rs b/src/header/bits_ucred/mod.rs new file mode 100644 index 0000000000..1bc1968355 --- /dev/null +++ b/src/header/bits_ucred/mod.rs @@ -0,0 +1,16 @@ +use crate::platform::types::{gid_t, pid_t, uid_t}; + +/// Non-POSIX, see . +/// +/// Represents UNIX credentials. +#[repr(C)] +#[derive(Clone, Debug)] +// FIXME: CheckVsLibcCrate +pub struct ucred { + /// Process ID of the sending process. + pub pid: pid_t, + /// User ID of the sending process. + pub uid: uid_t, + /// Group ID of the sending process. + pub gid: gid_t, +} diff --git a/src/header/mod.rs b/src/header/mod.rs index 006f5a6a87..f21412269e 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -57,6 +57,7 @@ pub mod bits_time_t; pub mod bits_timer_t; pub mod bits_timespec; pub mod bits_timeval; +pub mod bits_ucred; #[path = "bits_uid-t/mod.rs"] pub mod bits_uid_t; #[path = "bits_useconds-t/mod.rs"] diff --git a/src/header/sys_socket/cbindgen.toml b/src/header/sys_socket/cbindgen.toml index e37f7b7d62..f941d31068 100644 --- a/src/header/sys_socket/cbindgen.toml +++ b/src/header/sys_socket/cbindgen.toml @@ -16,10 +16,9 @@ after_includes = """ #include // for socklen_t #include // for ssize_t from sys/types.h -// Below required for Non-POSIX ucred struct -#include // for gid_t from sys/types.h -#include // for pid_t from sys/types.h -#include // for uid_t from sys/types.h +#if defined(_GNU_SOURCE) +#include // for Non-POSIX ucred struct +#endif """ trailer = """ #ifndef _RELIBC_BITS_SYS_SOCKET_H @@ -61,7 +60,6 @@ prefix_with_name = true include = [ "linger", "cmsghdr", - "ucred" ] [export.rename] diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index 49f25ff3fb..8d1e2557c1 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -9,9 +9,7 @@ use crate::{ header::{bits_safamily_t::sa_family_t, sys_uio::iovec}, 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, - }, + types::{c_char, c_int, c_long, c_uchar, c_uint, c_void, size_t, ssize_t}, }, }; @@ -61,22 +59,6 @@ pub struct cmsghdr { pub cmsg_type: c_int, } -// TODO: `ucred` should be behind _GNU_SOURCE include guard -/// Non-POSIX, see . -/// -/// Represents UNIX credentials. -#[repr(C)] -#[derive(Clone, Debug)] -// FIXME: CheckVsLibcCrate -pub struct ucred { - /// Process ID of the sending process. - pub pid: pid_t, - /// User ID of the sending process. - pub uid: uid_t, - /// Group ID of the sending process. - pub gid: gid_t, -} - /// See . #[repr(C)] #[derive(Default, CheckVsLibcCrate)] diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs index 296263169d..199434df55 100644 --- a/src/platform/redox/socket.rs +++ b/src/platform/redox/socket.rs @@ -14,6 +14,7 @@ use crate::{ header::{ arpa_inet::inet_aton, bits_safamily_t::sa_family_t, + bits_ucred::ucred, errno::{ EAFNOSUPPORT, EDOM, EFAULT, EINVAL, EMSGSIZE, ENOMEM, ENOSYS, ENOTSOCK, EOPNOTSUPP, EPROTONOSUPPORT, @@ -23,7 +24,7 @@ use crate::{ sys_select::timeval, sys_socket::{ CMSG_ALIGN, CMSG_DATA, CMSG_FIRSTHDR, CMSG_LEN, CMSG_NXTHDR, CMSG_SPACE, cmsghdr, - constants::*, msghdr, sockaddr, socklen_t, ucred, + constants::*, msghdr, sockaddr, socklen_t, }, sys_uio::iovec, sys_un::sockaddr_un,