From aebae6194c9464448059b2341e1337fb5d1065e0 Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Tue, 23 Jun 2026 18:09:30 +0200 Subject: [PATCH 1/8] fuchsia: mirror `fd_set` definition Fixes `fd_set`'s array field. The size was wrong [1]. Now unused constants have been removed. The PR has been separated from the commit fixing miscellaneous records. [1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/sys/select.h;l=23-25 --- src/fuchsia/mod.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 1c671f415b4c..0d2747019a69 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -354,7 +354,7 @@ s! { } pub struct fd_set { - fds_bits: [c_ulong; FD_SETSIZE as usize / ULONG_SIZE], + fds_bits: [c_ulong; FD_SETSIZE as usize / 8 / size_of::()], } pub struct tm { @@ -3006,17 +3006,6 @@ pub const O_NOFOLLOW: c_int = 0x00000080; pub const HUGETLB_FLAG_ENCODE_SHIFT: u32 = 26; pub const MAP_HUGE_SHIFT: u32 = 26; -// intentionally not public, only used for fd_set -cfg_if! { - if #[cfg(target_pointer_width = "32")] { - const ULONG_SIZE: usize = 32; - } else if #[cfg(target_pointer_width = "64")] { - const ULONG_SIZE: usize = 64; - } else { - // Unknown target_pointer_width - } -} - // END_PUB_CONST f! { From f234b95459d70eb874651a970776c2e0a56f53d1 Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Tue, 23 Jun 2026 18:02:42 +0200 Subject: [PATCH 2/8] fuchsia: mirror type aliases Mirror type aliases. They were previously only equivalent. This changes them to using C types. Remove architecture-specific definitions. They were the same. --- src/fuchsia/aarch64.rs | 2 -- src/fuchsia/mod.rs | 22 ++++++++++++---------- src/fuchsia/riscv64.rs | 3 --- src/fuchsia/x86_64.rs | 2 -- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/fuchsia/aarch64.rs b/src/fuchsia/aarch64.rs index 93090f7238d7..cf91bc4d4504 100644 --- a/src/fuchsia/aarch64.rs +++ b/src/fuchsia/aarch64.rs @@ -3,8 +3,6 @@ use crate::prelude::*; pub type __u64 = c_ulonglong; pub type wchar_t = u32; -pub type nlink_t = c_ulong; -pub type blksize_t = c_long; s! { pub struct stat { diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 0d2747019a69..0a17f48d1280 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -16,36 +16,38 @@ pub type size_t = usize; pub type ptrdiff_t = isize; pub type intptr_t = isize; pub type uintptr_t = usize; -pub type ssize_t = isize; +pub type ssize_t = crate::intptr_t; -pub type pid_t = i32; -pub type uid_t = u32; -pub type gid_t = u32; +pub type pid_t = c_int; +pub type uid_t = c_uint; +pub type gid_t = c_uint; pub type in_addr_t = u32; pub type in_port_t = u16; pub type sighandler_t = size_t; pub type cc_t = c_uchar; -pub type sa_family_t = u16; +pub type sa_family_t = c_ushort; pub type pthread_key_t = c_uint; pub type speed_t = c_uint; pub type tcflag_t = c_uint; pub type clockid_t = c_int; pub type key_t = c_int; pub type id_t = c_uint; -pub type useconds_t = u32; -pub type dev_t = u64; -pub type socklen_t = u32; +pub type useconds_t = c_uint; +pub type dev_t = c_ulonglong; +pub type socklen_t = c_uint; pub type pthread_t = c_ulong; -pub type mode_t = u32; pub type ino64_t = u64; pub type off64_t = i64; pub type blkcnt64_t = i64; pub type rlim64_t = u64; pub type mqd_t = c_int; +pub type mode_t = c_uint; pub type nfds_t = c_ulong; pub type nl_item = c_int; pub type idtype_t = c_uint; -pub type loff_t = c_longlong; +pub type loff_t = crate::off_t; +pub type nlink_t = c_ulong; +pub type blksize_t = c_long; pub type __u8 = c_uchar; pub type __u16 = c_ushort; diff --git a/src/fuchsia/riscv64.rs b/src/fuchsia/riscv64.rs index bc93cc3bff0a..6bc038e48652 100644 --- a/src/fuchsia/riscv64.rs +++ b/src/fuchsia/riscv64.rs @@ -5,9 +5,6 @@ use crate::prelude::*; pub type __u64 = c_ulonglong; pub type wchar_t = i32; -pub type nlink_t = c_ulong; -pub type blksize_t = c_long; - pub type stat64 = stat; s! { pub struct stat { diff --git a/src/fuchsia/x86_64.rs b/src/fuchsia/x86_64.rs index fc42cd981098..26343235398e 100644 --- a/src/fuchsia/x86_64.rs +++ b/src/fuchsia/x86_64.rs @@ -2,8 +2,6 @@ use crate::off_t; use crate::prelude::*; pub type wchar_t = i32; -pub type nlink_t = u64; -pub type blksize_t = c_long; pub type __u64 = c_ulonglong; s! { From a72d272cd6d4bf5c8f3d2a96d427355b38d29476 Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Sun, 31 May 2026 12:10:09 +0200 Subject: [PATCH 3/8] fuchsia: fix constant definitions Mirror constants. They were previously equivalent. --- src/fuchsia/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 0a17f48d1280..e8db52af66d2 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -1104,7 +1104,7 @@ pub const FD_CLOEXEC: c_int = 0x1; pub const USRQUOTA: c_int = 0; pub const GRPQUOTA: c_int = 1; -pub const SIGIOT: c_int = 6; +pub const SIGIOT: c_int = SIGABRT; pub const S_ISUID: mode_t = 0o4000; pub const S_ISGID: mode_t = 0o2000; From 644b0a8988082462a981e051b6aba07462874502 Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Tue, 23 Jun 2026 19:29:26 +0200 Subject: [PATCH 4/8] fuchsia: fill in definition of `fpos_t` Fills in the pending definition. It's opaque in other platforms. It's public in the Fuchsia headers [1]. Solves a `FIXME`. [1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/stdio.h;l=47-50 --- src/fuchsia/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index e8db52af66d2..05fcdac5b83b 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -1028,6 +1028,11 @@ s_no_extra_traits! { pub sival_ptr: *mut c_void, } + pub union fpos_t { + __opaque: [c_char; 16], + __align: c_double, + } + pub union epoll_data { pub ptr: *mut c_void, pub fd: c_int, @@ -3182,7 +3187,6 @@ extern "C" {} extern_ty! { pub type FILE; - pub type fpos_t; // FIXME(fuchsia): fill this out with a struct } extern "C" { From 9c0eb2b9ff2edc9d0d98dc80a1bce27ba6ef80b0 Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Tue, 23 Jun 2026 18:10:09 +0200 Subject: [PATCH 5/8] fuchsia: deprecate nonexistent types Remove nonexistent types. They are not part of the Fuchsia SDK. Replace `off64_t` in two routines. It's now `off_t`. `off64_t` has never existed in Fuchsia. --- src/fuchsia/aarch64.rs | 12 ++++ src/fuchsia/mod.rs | 158 +++++++++++++++++++++++++++++++++-------- src/fuchsia/riscv64.rs | 13 ++++ src/fuchsia/x86_64.rs | 13 ++++ 4 files changed, 167 insertions(+), 29 deletions(-) diff --git a/src/fuchsia/aarch64.rs b/src/fuchsia/aarch64.rs index cf91bc4d4504..30651047a512 100644 --- a/src/fuchsia/aarch64.rs +++ b/src/fuchsia/aarch64.rs @@ -1,6 +1,10 @@ use crate::off_t; use crate::prelude::*; +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist. The Fuchsia SDK doesn't ship it." +)] pub type __u64 = c_ulonglong; pub type wchar_t = u32; @@ -27,6 +31,10 @@ s! { __unused: Padding<[c_uint; 2]>, } + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." + )] pub struct stat64 { pub st_dev: crate::dev_t, pub st_ino: crate::ino_t, @@ -49,6 +57,10 @@ s! { __unused: Padding<[c_uint; 2]>, } + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." + )] pub struct ipc_perm { pub __ipc_perm_key: crate::key_t, pub uid: crate::uid_t, diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 05fcdac5b83b..d3c8fc268b12 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -36,11 +36,6 @@ pub type useconds_t = c_uint; pub type dev_t = c_ulonglong; pub type socklen_t = c_uint; pub type pthread_t = c_ulong; -pub type ino64_t = u64; -pub type off64_t = i64; -pub type blkcnt64_t = i64; -pub type rlim64_t = u64; -pub type mqd_t = c_int; pub type mode_t = c_uint; pub type nfds_t = c_ulong; pub type nl_item = c_int; @@ -49,6 +44,36 @@ pub type loff_t = crate::off_t; pub type nlink_t = c_ulong; pub type blksize_t = c_long; +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist usptream. It's not part of the Fuchsia SDK." +)] +pub type mqd_t = c_int; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist usptream. It's not part of the Fuchsia SDK." +)] +pub type off64_t = i64; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist usptream. It's not part of the Fuchsia SDK." +)] +pub type ino64_t = u64; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist usptream. It's not part of the Fuchsia SDK." +)] +pub type blkcnt64_t = i64; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist upstream. It's not part of the Fuchsia SDK." +)] +pub type rlim64_t = u64; + pub type __u8 = c_uchar; pub type __u16 = c_ushort; pub type __s16 = c_short; @@ -78,12 +103,28 @@ pub type msgqnum_t = c_ulong; pub type msglen_t = c_ulong; pub type fsblkcnt_t = c_ulonglong; pub type fsfilcnt_t = c_ulonglong; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist upstream. It's not part of the Fuchsia SDK." +)] pub type rlim_t = c_ulonglong; +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist upstream. It's not part of the Fuchsia SDK." +)] +pub type statfs64 = statfs; + extern_ty! { pub type timezone; pub type DIR; - pub type fpos64_t; // FIXME(fuchsia): fill this out with a struct + + #[deprecated( + since = "0.2.187", + note = "Use `fpos_t` instead. This type does not exist upstream." + )] + pub type fpos64_t; } // PUB_STRUCT @@ -113,8 +154,7 @@ s! { pub tv_nsec: c_long, } - // FIXME(fuchsia): the rlimit and rusage related functions and types don't exist - // within zircon. Are there reasons for keeping them around? + #[deprecated(since = "0.2.187", note = "This type does not exist upstream.")] pub struct rlimit { pub rlim_cur: rlim_t, pub rlim_max: rlim_t, @@ -388,6 +428,11 @@ s! { pub dli_saddr: *mut c_void, } + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist. The Fuchsia SDK doesn't ship it." + )] + #[allow(deprecated)] pub struct epoll_event { pub events: u32, pub data: epoll_data, @@ -420,6 +465,10 @@ s! { pub int_n_sign_posn: c_char, } + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist upstream. It is not part of the Fuchsia SDK." + )] pub struct rlimit64 { pub rlim_cur: rlim64_t, pub rlim_max: rlim64_t, @@ -665,6 +714,10 @@ s! { pub weak_magnitude: crate::__u16, } + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist usptream. It's not included in the Fuchsia SDK." + )] pub struct ff_effect { pub type_: crate::__u16, pub id: crate::__s16, @@ -724,21 +777,10 @@ s! { pub p_align: Elf64_Xword, } - pub struct statfs64 { - pub f_type: c_ulong, - pub f_bsize: c_ulong, - pub f_blocks: crate::fsblkcnt_t, - pub f_bfree: crate::fsblkcnt_t, - pub f_bavail: crate::fsblkcnt_t, - pub f_files: crate::fsfilcnt_t, - pub f_ffree: crate::fsfilcnt_t, - pub f_fsid: crate::fsid_t, - pub f_namelen: c_ulong, - pub f_frsize: c_ulong, - pub f_flags: c_ulong, - pub f_spare: [c_ulong; 4], - } - + #[deprecated( + since = "0.2.187", + note = "Use `statvfs` instead. This type doesn't exist upstream." + )] pub struct statvfs64 { pub f_bsize: c_ulong, pub f_frsize: c_ulong, @@ -841,6 +883,10 @@ s! { _align: [usize; 0], } + #[deprecated( + since = "0.2.187", + note = "Use `termios`. This type doesn't exist. The Fuchsia SDK doesn't include it." + )] pub struct termios2 { pub c_iflag: crate::tcflag_t, pub c_oflag: crate::tcflag_t, @@ -880,6 +926,7 @@ s! { size: [u8; crate::__SIZEOF_PTHREAD_CONDATTR_T], } + #[deprecated(since = "0.2.187", note = "This type doesn't exist upstream.")] pub struct sysinfo { pub uptime: c_ulong, pub loads: [c_ulong; 3], @@ -925,6 +972,11 @@ s! { pub d_name: [c_char; 256], } + #[deprecated( + since = "0.2.187", + note = "Use `dirent` instead. This type doesn't exist. It's not part of the Fuchsia SDK." + )] + #[allow(deprecated)] pub struct dirent64 { pub d_ino: crate::ino64_t, pub d_off: off64_t, @@ -933,8 +985,10 @@ s! { pub d_name: [c_char; 256], } - // x32 compatibility - // See https://sourceware.org/bugzilla/show_bug.cgi?id=21279 + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist upstream. It's not part of the Fuchsia SDK." + )] pub struct mq_attr { #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] pub mq_flags: i64, @@ -959,6 +1013,10 @@ s! { pad: Padding<[c_long; 4]>, } + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist upstream. It's not part of the Fuchsia SDK." + )] pub struct sockaddr_nl { pub nl_family: crate::sa_family_t, nl_pad: Padding, @@ -1033,6 +1091,10 @@ s_no_extra_traits! { __align: c_double, } + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." + )] pub union epoll_data { pub ptr: *mut c_void, pub fd: c_int, @@ -1048,36 +1110,45 @@ s_no_extra_traits! { cfg_if! { if #[cfg(feature = "extra_traits")] { + #[allow(deprecated)] impl PartialEq for sigval { fn eq(&self, _other: &sigval) -> bool { unimplemented!("traits") } } + #[allow(deprecated)] impl Eq for sigval {} + #[allow(deprecated)] impl hash::Hash for sigval { fn hash(&self, _state: &mut H) { unimplemented!("traits") } } + #[allow(deprecated)] impl PartialEq for epoll_data { fn eq(&self, _other: &epoll_data) -> bool { unimplemented!("traits") } } + #[allow(deprecated)] impl Eq for epoll_data {} + #[allow(deprecated)] impl hash::Hash for epoll_data { fn hash(&self, _state: &mut H) { unimplemented!("traits") } } + #[allow(deprecated)] impl PartialEq for __c_anonymous_ifaddrs_ifa_ifu { fn eq(&self, _other: &__c_anonymous_ifaddrs_ifa_ifu) -> bool { unimplemented!("traits") } } + #[allow(deprecated)] impl Eq for __c_anonymous_ifaddrs_ifa_ifu {} + #[allow(deprecated)] impl hash::Hash for __c_anonymous_ifaddrs_ifa_ifu { fn hash(&self, _state: &mut H) { unimplemented!("traits") @@ -2039,7 +2110,18 @@ pub const _SC_XOPEN_STREAMS: c_int = 246; pub const _SC_THREAD_ROBUST_PRIO_INHERIT: c_int = 247; pub const _SC_THREAD_ROBUST_PRIO_PROTECT: c_int = 248; +#[deprecated( + since = "0.2.187", + note = "This doesn't exist upstream. It's not part of the Fuchsia SDK." +)] +#[allow(deprecated)] pub const RLIM_SAVED_MAX: crate::rlim_t = RLIM_INFINITY; + +#[deprecated( + since = "0.2.187", + note = "This doesn't exist upstream. It's not part of the Fuchsia SDK." +)] +#[allow(deprecated)] pub const RLIM_SAVED_CUR: crate::rlim_t = RLIM_INFINITY; pub const GLOB_ERR: c_int = 1 << 0; @@ -2583,12 +2665,30 @@ pub const POSIX_FADV_NOREUSE: c_int = 5; pub const POSIX_MADV_DONTNEED: c_int = 4; +#[deprecated( + since = "0.2.187", + note = "This doesn't exist upstream. It's not part of the Fuchsia SDK." +)] +#[allow(deprecated)] pub const RLIM_INFINITY: crate::rlim_t = !0; + +#[deprecated( + since = "0.2.187", + note = "This doesn't exist upstream. It's not part of the Fuchsia SDK." +)] +#[allow(deprecated)] pub const RLIMIT_RTTIME: c_int = 15; -#[deprecated(since = "0.2.64", note = "Not stable across OS versions")] + +#[deprecated( + since = "0.2.64", + note = "This doesn't exist upstream. It's not part of the Fuchsia SDK." +)] pub const RLIMIT_NLIMITS: c_int = 16; +#[deprecated( + since = "0.2.64", + note = "This doesn't exist upstream. It's not part of the Fuchsia SDK." +)] #[allow(deprecated)] -#[deprecated(since = "0.2.64", note = "Not stable across OS versions")] pub const RLIM_NLIMITS: c_int = RLIMIT_NLIMITS; pub const MAP_ANONYMOUS: c_int = MAP_ANON; @@ -3794,7 +3894,7 @@ extern "C" { pub fn fallocate(fd: c_int, mode: c_int, offset: off_t, len: off_t) -> c_int; pub fn posix_fallocate(fd: c_int, offset: off_t, len: off_t) -> c_int; - pub fn readahead(fd: c_int, offset: off64_t, count: size_t) -> ssize_t; + pub fn readahead(fd: c_int, offset: off_t, count: size_t) -> ssize_t; pub fn signalfd(fd: c_int, mask: *const crate::sigset_t, flags: c_int) -> c_int; pub fn timerfd_create(clockid: c_int, flags: c_int) -> c_int; pub fn timerfd_gettime(fd: c_int, curr_value: *mut itimerspec) -> c_int; @@ -3834,7 +3934,7 @@ extern "C" { pub fn mkfifoat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int; pub fn if_nameindex() -> *mut if_nameindex; pub fn if_freenameindex(ptr: *mut if_nameindex); - pub fn sync_file_range(fd: c_int, offset: off64_t, nbytes: off64_t, flags: c_uint) -> c_int; + pub fn sync_file_range(fd: c_int, offset: off_t, nbytes: off_t, flags: c_uint) -> c_int; pub fn getifaddrs(ifap: *mut *mut crate::ifaddrs) -> c_int; pub fn freeifaddrs(ifa: *mut crate::ifaddrs); diff --git a/src/fuchsia/riscv64.rs b/src/fuchsia/riscv64.rs index 6bc038e48652..f4eed3a7ceb0 100644 --- a/src/fuchsia/riscv64.rs +++ b/src/fuchsia/riscv64.rs @@ -2,10 +2,19 @@ use crate::off_t; use crate::prelude::*; // From psABI Calling Convention for RV64 +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist. The Fuchsia SDK doesn't ship it." +)] pub type __u64 = c_ulonglong; pub type wchar_t = i32; +#[deprecated( + since = "0.2.187", + note = "Thist type doesn't exist. It's not part of the Fuchsia SDK." +)] pub type stat64 = stat; + s! { pub struct stat { pub st_dev: crate::dev_t, @@ -29,6 +38,10 @@ s! { } // Not actually used, IPC calls just return ENOSYS + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist. The Fuchsia SDK does not ship it." + )] pub struct ipc_perm { pub __ipc_perm_key: crate::key_t, pub uid: crate::uid_t, diff --git a/src/fuchsia/x86_64.rs b/src/fuchsia/x86_64.rs index 26343235398e..8181ca7c4b0a 100644 --- a/src/fuchsia/x86_64.rs +++ b/src/fuchsia/x86_64.rs @@ -2,6 +2,11 @@ use crate::off_t; use crate::prelude::*; pub type wchar_t = i32; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist. The Fuchsia SDK doesn't ship it." +)] pub type __u64 = c_ulonglong; s! { @@ -26,6 +31,10 @@ s! { __unused: Padding<[c_long; 3]>, } + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." + )] pub struct stat64 { pub st_dev: crate::dev_t, pub st_ino: crate::ino64_t, @@ -51,6 +60,10 @@ s! { __private: [u64; 32], } + #[deprecated( + since = "0.2.187", + note = "This type doesn't exist. The Fuchsia SDK doesn't ship with it." + )] pub struct ipc_perm { pub __ipc_perm_key: crate::key_t, pub uid: crate::uid_t, From c432b94be00bb38eea2e56c33ae6943c1ee1f7ab Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Wed, 24 Jun 2026 08:05:59 +0200 Subject: [PATCH 6/8] fuchsia: fix record definitions Remove uses of 32-bit target conditional compilation. Fuchsia does not support 32-bit targets [1]. This is unnecessary. Fix missing fields in records. No particular header file is targetted. All wrong records have been fixed. c.f. all headers under `sysroot/include` in the SDK. Fix `cpu_set_t` macros [2]. They were wrongly defined. They neither returned the right values. [1]: https://fuchsia.dev/fuchsia-src/contribute/governance/rfcs/0111_fuchsia_hardware_specifications#required_64-bit_cpu_and_platform [2]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/sched.h --- src/fuchsia/aarch64.rs | 4 +- src/fuchsia/mod.rs | 100 +++++++++++++++++++---------------------- src/fuchsia/riscv64.rs | 5 +-- src/fuchsia/x86_64.rs | 2 +- 4 files changed, 50 insertions(+), 61 deletions(-) diff --git a/src/fuchsia/aarch64.rs b/src/fuchsia/aarch64.rs index 30651047a512..f7eb7eef98b0 100644 --- a/src/fuchsia/aarch64.rs +++ b/src/fuchsia/aarch64.rs @@ -17,10 +17,10 @@ s! { pub st_uid: crate::uid_t, pub st_gid: crate::gid_t, pub st_rdev: crate::dev_t, - __pad0: Padding, + __pad: Padding, pub st_size: off_t, pub st_blksize: crate::blksize_t, - __pad1: Padding, + __pad2: Padding, pub st_blocks: crate::blkcnt_t, pub st_atime: crate::time_t, pub st_atime_nsec: c_long, diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index d3c8fc268b12..d71266d9d031 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -478,13 +478,8 @@ s! { pub gl_pathc: size_t, pub gl_pathv: *mut *mut c_char, pub gl_offs: size_t, - pub gl_flags: c_int, - - __unused1: Padding<*mut c_void>, - __unused2: Padding<*mut c_void>, - __unused3: Padding<*mut c_void>, - __unused4: Padding<*mut c_void>, - __unused5: Padding<*mut c_void>, + __dummy1: Padding, + __dummy2: Padding<[*mut c_void; 5]>, } pub struct ifaddrs { @@ -528,15 +523,10 @@ s! { pub f_files: crate::fsfilcnt_t, pub f_ffree: crate::fsfilcnt_t, pub f_favail: crate::fsfilcnt_t, - #[cfg(target_endian = "little")] - pub f_fsid: c_ulong, - #[cfg(all(target_pointer_width = "32", not(target_arch = "x86_64")))] - __f_unused: Padding, - #[cfg(target_endian = "big")] pub f_fsid: c_ulong, pub f_flag: c_ulong, pub f_namemax: c_ulong, - __f_spare: [c_int; 6], + __f_spare: Padding<[c_int; 6]>, } pub struct dqblk { @@ -586,10 +576,7 @@ s! { } pub struct cpu_set_t { - #[cfg(all(target_pointer_width = "32", not(target_arch = "x86_64")))] - bits: [u32; 32], - #[cfg(not(all(target_pointer_width = "32", not(target_arch = "x86_64"))))] - bits: [u64; 16], + pub __bits: [c_ulonglong; 128 / size_of::()], } pub struct if_nameindex { @@ -732,23 +719,10 @@ s! { } pub struct dl_phdr_info { - #[cfg(target_pointer_width = "64")] pub dlpi_addr: Elf64_Addr, - #[cfg(target_pointer_width = "32")] - pub dlpi_addr: Elf32_Addr, - pub dlpi_name: *const c_char, - - #[cfg(target_pointer_width = "64")] pub dlpi_phdr: *const Elf64_Phdr, - #[cfg(target_pointer_width = "32")] - pub dlpi_phdr: *const Elf32_Phdr, - - #[cfg(target_pointer_width = "64")] pub dlpi_phnum: Elf64_Half, - #[cfg(target_pointer_width = "32")] - pub dlpi_phnum: Elf32_Half, - pub dlpi_adds: c_ulonglong, pub dlpi_subs: c_ulonglong, pub dlpi_tls_modid: size_t, @@ -807,7 +781,7 @@ s! { } pub struct sigset_t { - __val: [c_ulong; 16], + __bits: [c_ulong; 128 / size_of::()], } pub struct shmid_ds { @@ -872,15 +846,16 @@ s! { } pub struct sem_t { - __val: [c_int; 8], + pub _s_value: c_int, + pub _s_waiters: c_int, } + #[repr(align(8))] pub struct siginfo_t { pub si_signo: c_int, pub si_errno: c_int, pub si_code: c_int, - pub _pad: [c_int; 29], - _align: [usize; 0], + pub __si_fields: [c_int; 28], } #[deprecated( @@ -951,13 +926,14 @@ s! { pub struct sockaddr_storage { pub ss_family: sa_family_t, - __ss_pad2: Padding<[u8; 128 - 2 - 8]>, - __ss_align: size_t, + __ss_padding: + Padding<[c_char; 128 - size_of::() - size_of::()]>, + __ss_align: c_ulong, } pub struct utsname { pub sysname: [c_char; 65], - pub nodename: [c_char; 65], + pub nodename: [c_char; crate::HOST_NAME_MAX.cast_unsigned() as usize + 1], pub release: [c_char; 65], pub version: [c_char; 65], pub machine: [c_char; 65], @@ -965,7 +941,7 @@ s! { } pub struct dirent { - pub d_ino: crate::ino_t, + pub d_ino: ino_t, pub d_off: off_t, pub d_reclen: c_ushort, pub d_type: c_uchar, @@ -1159,8 +1135,10 @@ cfg_if! { // PUB_CONST -pub const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; +pub const HOST_NAME_MAX: c_int = 255; + +pub const INT_MIN: c_int = -1 - 0x7fffffff; +pub const INT_MAX: c_int = 0x7fffffff; pub const SIG_DFL: sighandler_t = 0 as sighandler_t; pub const SIG_IGN: sighandler_t = 1 as sighandler_t; @@ -3141,31 +3119,43 @@ f! { } pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () { - cpuset.bits.fill(0); + cpuset.__bits.fill(0); } - pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] |= 1 << offset; - () + pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> c_ulonglong { + (cpu / 8 >= size_of::()) + .then_some(0) + .unwrap_or_else(|| { + let c = &mut cpuset.__bits[cpu / 8 / size_of::()]; + *c |= 1 << (cpu % (8 * size_of::())); + + *c + }) } - pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () { - let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - cpuset.bits[idx] &= !(1 << offset); - () + pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> c_ulonglong { + (cpu / 8 >= size_of::()) + .then_some(0) + .unwrap_or_else(|| { + let c = &mut cpuset.__bits[cpu / 8 / size_of::()]; + *c &= !(1 << (cpu % (8 * size_of::()))); + + *c + }) } pub fn CPU_ISSET(cpu: usize, cpuset: &cpu_set_t) -> bool { - let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); - let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits); - 0 != (cpuset.bits[idx] & (1 << offset)) + (cpu / 8 >= size_of::()) + .then_some(false) + .unwrap_or_else(|| { + (cpuset.__bits[cpu / 8 / size_of::()] + & (1 << (cpu % (8 * size_of::())))) + != 0 + }) } pub fn CPU_EQUAL(set1: &cpu_set_t, set2: &cpu_set_t) -> bool { - set1.bits == set2.bits + set1.__bits == set2.__bits } pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar { diff --git a/src/fuchsia/riscv64.rs b/src/fuchsia/riscv64.rs index f4eed3a7ceb0..a5d8860e8cc4 100644 --- a/src/fuchsia/riscv64.rs +++ b/src/fuchsia/riscv64.rs @@ -1,4 +1,3 @@ -use crate::off_t; use crate::prelude::*; // From psABI Calling Convention for RV64 @@ -23,9 +22,9 @@ s! { pub st_mode: crate::mode_t, pub st_uid: crate::uid_t, pub st_gid: crate::gid_t, - __pad0: Padding, + __pad0: Padding, pub st_rdev: crate::dev_t, - pub st_size: off_t, + pub st_size: crate::off_t, pub st_blksize: crate::blksize_t, pub st_blocks: crate::blkcnt_t, pub st_atime: crate::time_t, diff --git a/src/fuchsia/x86_64.rs b/src/fuchsia/x86_64.rs index 8181ca7c4b0a..c08f1289d08c 100644 --- a/src/fuchsia/x86_64.rs +++ b/src/fuchsia/x86_64.rs @@ -17,7 +17,7 @@ s! { pub st_mode: crate::mode_t, pub st_uid: crate::uid_t, pub st_gid: crate::gid_t, - __pad0: Padding, + __pad0: Padding, pub st_rdev: crate::dev_t, pub st_size: off_t, pub st_blksize: crate::blksize_t, From ca045966e4a3fb2222ff3a212601f333f7fab475 Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Tue, 23 Jun 2026 19:27:52 +0200 Subject: [PATCH 7/8] fuchsia: fix `bits/signal.h` types Fix definition of types in x86_64. `mcontext_t` provided opaque field. `ucontext_t` had a slightly wrong definition. New records have been introduced. They are particular to `mcontext_t`. Add definitions in AArch64 and RISC-V64. They were missing. They are different for all three target architectures. These are declared in [1]. [1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/bits/signal.h --- src/fuchsia/aarch64.rs | 19 ++++++++++++++++ src/fuchsia/riscv64.rs | 12 +++++++++++ src/fuchsia/x86_64.rs | 49 +++++++++++++++++++++++++++++++++--------- 3 files changed, 70 insertions(+), 10 deletions(-) diff --git a/src/fuchsia/aarch64.rs b/src/fuchsia/aarch64.rs index f7eb7eef98b0..a9bdc834b271 100644 --- a/src/fuchsia/aarch64.rs +++ b/src/fuchsia/aarch64.rs @@ -72,6 +72,25 @@ s! { __unused1: Padding, __unused2: Padding, } + + // FIXME(f128): __reserved is meant to be an array of `long double`s. That + // requires native support for `f128`. This is currently missing. + pub struct mcontext_t { + pub fault_address: c_ulong, + pub regs: [c_ulong; 31], + pub sp: c_ulong, + pub pc: c_ulong, + pub pstate: c_ulong, + __reserved: Padding<[i128; 256]>, + } + + pub struct ucontext_t { + pub uc_flags: c_ulong, + pub uc_link: *mut crate::ucontext_t, + pub uc_stack: crate::stack_t, + pub uc_sigmask: crate::sigset_t, + pub uc_mcontext: crate::mcontext_t, + } } // From https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/bits/signal.h;l=20-21;drc=0827b18ab9540c46f8037f407d17ea15a79e9ba7 diff --git a/src/fuchsia/riscv64.rs b/src/fuchsia/riscv64.rs index a5d8860e8cc4..e62685ad7352 100644 --- a/src/fuchsia/riscv64.rs +++ b/src/fuchsia/riscv64.rs @@ -52,4 +52,16 @@ s! { __unused1: Padding, __unused2: Padding, } + + pub struct mcontext_t { + pub regs: [c_ulong; 32], + } + + pub struct ucontext_t { + pub uc_flags: c_ulong, + pub uc_link: *mut crate::ucontext_t, + pub uc_stack: crate::stack_t, + pub uc_sigmask: crate::sigset_t, + pub uc_mcontext: crate::mcontext_t, + } } diff --git a/src/fuchsia/x86_64.rs b/src/fuchsia/x86_64.rs index c08f1289d08c..60e6e88c1b13 100644 --- a/src/fuchsia/x86_64.rs +++ b/src/fuchsia/x86_64.rs @@ -9,7 +9,34 @@ pub type wchar_t = i32; )] pub type __u64 = c_ulonglong; +pub type gregset_t = [c_ulonglong; 23]; +pub type fpregset_t = *mut _fpstate; + s! { + pub struct _fpstate { + pub cwd: c_ushort, + pub swd: c_ushort, + pub ftw: c_ushort, + pub fop: c_ushort, + pub rip: c_ulonglong, + pub rdp: c_ulonglong, + pub mxcsr: c_uint, + pub mxcr_mask: c_uint, + pub _st: [__c_anonymous__fpstate__st; 8], + pub _xmm: [__c_anonymous__fpstate__xmm; 16], + padding: Padding<[c_uint; 24]>, + } + + pub struct __c_anonymous__fpstate__st { + pub significand: [c_ushort; 4], + pub exponent: c_ushort, + padding: Padding<[c_ushort; 3]>, + } + + pub struct __c_anonymous__fpstate__xmm { + pub element: [c_uint; 4], + } + pub struct stat { pub st_dev: crate::dev_t, pub st_ino: crate::ino_t, @@ -57,7 +84,18 @@ s! { } pub struct mcontext_t { - __private: [u64; 32], + pub gregs: crate::gregset_t, + pub fpregs: crate::fpregset_t, + __reserved1: Padding<[c_ulonglong; 8]>, + } + + pub struct ucontext_t { + pub uc_flags: c_ulong, + pub uc_link: *mut ucontext_t, + pub uc_stack: crate::stack_t, + pub uc_mcontext: crate::mcontext_t, + pub uc_sigmask: crate::sigset_t, + __fpregs_mem: [c_ulong; 64], } #[deprecated( @@ -75,15 +113,6 @@ s! { __unused1: Padding, __unused2: Padding, } - - pub struct ucontext_t { - pub uc_flags: c_ulong, - pub uc_link: *mut ucontext_t, - pub uc_stack: crate::stack_t, - pub uc_mcontext: mcontext_t, - pub uc_sigmask: crate::sigset_t, - __private: [u8; 512], - } } // offsets in user_regs_structs, from sys/reg.h From 12715e99de4e6cf0941c0a7b02535d7d7c6fc33f Mon Sep 17 00:00:00 2001 From: dybucc <149513579+dybucc@users.noreply.github.com> Date: Wed, 24 Jun 2026 07:58:44 +0200 Subject: [PATCH 8/8] fuchsia: fix `pthread.h` definitions Remove opaque types. Replace with proper fields. Remove conditional defintion for 32-bit targets. Fuchsia has no 32-bit targets. Static initializers needed modification. They are specified as `{ 0 }` in POSIX for C. The new definition replicates that. It zeroes/nullifies the new fields. Constants were used to initialize the previous opaque array. These have been deprecated. These are declared in [1]. [1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/pthread.h --- src/fuchsia/mod.rs | 117 ++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 55 deletions(-) diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index d71266d9d031..a8856e414d4d 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -777,7 +777,15 @@ s! { } pub struct pthread_attr_t { - __size: [u64; 7], + __name: *const c_char, + __c11: c_int, + _a_stacksize: crate::size_t, + _a_guardsize: crate::size_t, + _a_stackaddr: *mut c_void, + _a_detach: c_int, + _a_sched: c_int, + _a_policy: c_int, + _a_prio: c_int, } pub struct sigset_t { @@ -878,27 +886,16 @@ s! { pub ipi6_ifindex: c_uint, } - #[cfg_attr( - any(target_pointer_width = "32", target_arch = "x86_64"), - repr(align(4)) - )] - #[cfg_attr( - not(any(target_pointer_width = "32", target_arch = "x86_64")), - repr(align(8)) - )] pub struct pthread_mutexattr_t { - size: [u8; crate::__SIZEOF_PTHREAD_MUTEXATTR_T], + pub __attr: c_uint, } - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] pub struct pthread_rwlockattr_t { - size: [u8; crate::__SIZEOF_PTHREAD_RWLOCKATTR_T], + pub __attr: [c_uint; 2], } - #[repr(align(4))] pub struct pthread_condattr_t { - size: [u8; crate::__SIZEOF_PTHREAD_CONDATTR_T], + pub __attr: c_uint, } #[deprecated(since = "0.2.187", note = "This type doesn't exist upstream.")] @@ -1006,53 +1003,28 @@ s! { pub sigev_value: crate::sigval, pub sigev_signo: c_int, pub sigev_notify: c_int, - pub sigev_notify_function: fn(crate::sigval), + pub sigev_notify_function: Option, pub sigev_notify_attributes: *mut pthread_attr_t, - pub __pad: [c_char; 56 - 3 * 8], + __pad: Padding<[c_char; 56 - 3 * size_of::()]>, } - #[cfg_attr( - all( - target_pointer_width = "32", - any(target_arch = "arm", target_arch = "x86_64") - ), - repr(align(4)) - )] - #[cfg_attr( - any( - target_pointer_width = "64", - not(any(target_arch = "arm", target_arch = "x86_64")) - ), - repr(align(8)) - )] pub struct pthread_mutex_t { - size: [u8; crate::__SIZEOF_PTHREAD_MUTEX_T], + pub _m_attr: c_uint, + pub _m_lock: c_int, + pub _m_waiters: c_int, + pub _m_count: c_int, } - #[cfg_attr( - all( - target_pointer_width = "32", - any(target_arch = "arm", target_arch = "x86_64") - ), - repr(align(4)) - )] - #[cfg_attr( - any( - target_pointer_width = "64", - not(any(target_arch = "arm", target_arch = "x86_64")) - ), - repr(align(8)) - )] pub struct pthread_rwlock_t { - size: [u8; crate::__SIZEOF_PTHREAD_RWLOCK_T], + pub _rw_lock: c_int, + pub _rw_waiters: c_int, } - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_arch = "x86", repr(align(4)))] - #[cfg_attr(not(target_arch = "x86"), repr(align(8)))] pub struct pthread_cond_t { - size: [u8; crate::__SIZEOF_PTHREAD_COND_T], + pub _c_head: *mut c_void, + pub _c_clock: c_int, + pub _c_tail: *mut c_void, + pub _c_lock: c_int, } } @@ -2152,13 +2124,20 @@ pub const RTLD_NOW: c_int = 0x2; pub const TCP_MD5SIG: c_int = 14; pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { - size: [0; __SIZEOF_PTHREAD_MUTEX_T], + _m_attr: 0, + _m_lock: 0, + _m_waiters: 0, + _m_count: 0, }; pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { - size: [0; __SIZEOF_PTHREAD_COND_T], + _c_head: ptr::null_mut(), + _c_clock: 0, + _c_tail: ptr::null_mut(), + _c_lock: 0, }; pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { - size: [0; __SIZEOF_PTHREAD_RWLOCK_T], + _rw_lock: 0, + _rw_waiters: 0, }; pub const PTHREAD_MUTEX_NORMAL: c_int = 0; pub const PTHREAD_MUTEX_RECURSIVE: c_int = 1; @@ -2166,6 +2145,11 @@ pub const PTHREAD_MUTEX_ERRORCHECK: c_int = 2; pub const PTHREAD_MUTEX_DEFAULT: c_int = PTHREAD_MUTEX_NORMAL; pub const PTHREAD_PROCESS_PRIVATE: c_int = 0; pub const PTHREAD_PROCESS_SHARED: c_int = 1; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." +)] pub const __SIZEOF_PTHREAD_COND_T: usize = 48; pub const RENAME_NOREPLACE: c_int = 1; @@ -2687,8 +2671,22 @@ pub const TCP_TIMESTAMP: c_int = 24; pub const SIGUNUSED: c_int = crate::SIGSYS; +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." +)] pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." +)] pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." +)] pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; pub const CPU_SETSIZE: c_int = 128; @@ -2827,7 +2825,16 @@ pub const B3000000: crate::speed_t = 0o010015; pub const B3500000: crate::speed_t = 0o010016; pub const B4000000: crate::speed_t = 0o010017; +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." +)] pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; + +#[deprecated( + since = "0.2.187", + note = "This type doesn't exist. It's not part of the Fuchsia SDK." +)] pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; pub const O_ASYNC: c_int = 0x00000400;