From 9b2e0a984e317a2f5049c326fbc7e26019758a89 Mon Sep 17 00:00:00 2001 From: highjeans Date: Sun, 16 Mar 2025 16:36:57 +0000 Subject: [PATCH 1/8] Add correct darwin definition of pthread_t --- src/unix/bsd/apple/b32/mod.rs | 8 ++++++++ src/unix/bsd/apple/b64/mod.rs | 8 ++++++++ src/unix/bsd/mod.rs | 31 ++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/unix/bsd/apple/b32/mod.rs b/src/unix/bsd/apple/b32/mod.rs index ab0c94ef4c2c2..1e0be2ca97131 100644 --- a/src/unix/bsd/apple/b32/mod.rs +++ b/src/unix/bsd/apple/b32/mod.rs @@ -60,6 +60,14 @@ s_no_extra_traits! { #[deprecated(since = "0.2.55")] pub const NET_RT_MAXID: c_int = 10; +pub const __PTHREAD_SIZE__: usize = 4088; +pub const __PTHREAD_MUTEX_SIZE__: usize = 40; +pub const __PTHREAD_COND_SIZE__: usize = 24; +pub const __PTHREAD_CONDATTR_SIZE__: usize = 4; +pub const __PTHREAD_ONCE_SIZE__: usize = 4; +pub const __PTHREAD_RWLOCK_SIZE__: usize = 124; +pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 12; + pub const TIOCTIMESTAMP: c_ulong = 0x40087459; pub const TIOCDCDTIMESTAMP: c_ulong = 0x40087458; diff --git a/src/unix/bsd/apple/b64/mod.rs b/src/unix/bsd/apple/b64/mod.rs index 5ccf65abb840e..ee31487d05a41 100644 --- a/src/unix/bsd/apple/b64/mod.rs +++ b/src/unix/bsd/apple/b64/mod.rs @@ -53,6 +53,14 @@ s! { #[deprecated(since = "0.2.55")] pub const NET_RT_MAXID: c_int = 11; +pub const __PTHREAD_SIZE__: usize = 8176; +pub const __PTHREAD_MUTEX_SIZE__: usize = 56; +pub const __PTHREAD_COND_SIZE__: usize = 40; +pub const __PTHREAD_CONDATTR_SIZE__: usize = 8; +pub const __PTHREAD_ONCE_SIZE__: usize = 8; +pub const __PTHREAD_RWLOCK_SIZE__: usize = 192; +pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 16; + pub const TIOCTIMESTAMP: c_ulong = 0x40107459; pub const TIOCDCDTIMESTAMP: c_ulong = 0x40107458; diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 37ef0f0d81ed1..4b23e5717fd33 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -5,7 +5,36 @@ pub type useconds_t = u32; pub type blkcnt_t = i64; pub type socklen_t = u32; pub type sa_family_t = u8; -pub type pthread_t = crate::uintptr_t; +// pub type pthread_t = crate::uintptr_t; + +cfg_if! { + if #[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + ))] { + s! { + pub struct __darwin_pthread_handler_rec { + __routine: Option, + __arg: *mut c_void, + __next: *mut __darwin_pthread_handler_rec, + } + pub struct _opaque_pthread_t { + __sig: c_long, + __cleanup_stack: *mut __darwin_pthread_handler_rec, + __opaque: [c_char; __PTHREAD_SIZE__], + } + } + pub type __darwin_pthread_t = *mut _opaque_pthread_t; + pub type pthread_t = __darwin_pthread_t; + } + else { + pub type pthread_t = crate::uintptr_t; + } +} + pub type nfds_t = c_uint; pub type regoff_t = off_t; From d9e026300c21b76e222b4d579c6815fd528ea631 Mon Sep 17 00:00:00 2001 From: highjeans Date: Mon, 17 Mar 2025 15:19:37 +0000 Subject: [PATCH 2/8] Explicitly set "opaque_pthread_t" to be a struct rather than a type --- libc-test/build.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 1cbacfde9d979..558671fe63e71 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2,20 +2,9 @@ #![allow(clippy::match_like_matches_macro)] use std::fs::File; -use std::io::{ - BufRead, - BufReader, - BufWriter, - Write, -}; -use std::path::{ - Path, - PathBuf, -}; -use std::{ - env, - io, -}; +use std::io::{BufRead, BufReader, BufWriter, Write}; +use std::path::{Path, PathBuf}; +use std::{env, io}; fn do_cc() { let target = env::var("TARGET").unwrap(); From 2f307d90077a4e072b8604fc510cfa21bb725e81 Mon Sep 17 00:00:00 2001 From: highjeans Date: Mon, 17 Mar 2025 15:19:52 +0000 Subject: [PATCH 3/8] Update symbols list --- libc-test/semver/apple.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 7b11ad7c66ebd..39362179c453a 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -1778,13 +1778,17 @@ _UTX_LINESIZE _UTX_USERSIZE _WSTATUS _WSTOPPED +_opaque_pthread_t __PTHREAD_CONDATTR_SIZE__ __PTHREAD_COND_SIZE__ __PTHREAD_MUTEX_SIZE__ __PTHREAD_ONCE_SIZE__ __PTHREAD_RWLOCKATTR_SIZE__ __PTHREAD_RWLOCK_SIZE__ +__PTHREAD_SIZE__ __darwin_mcontext64 +__darwin_pthread_handler_rec +__darwin_pthread_t __error abs acct From f65234cdf3d775121153e115759706bee099f321 Mon Sep 17 00:00:00 2001 From: highjeans Date: Mon, 17 Mar 2025 15:30:00 +0000 Subject: [PATCH 4/8] Fix stylings --- libc-test/build.rs | 1 - libc-test/semver/apple.txt | 2 +- src/unix/bsd/mod.rs | 19 +++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 558671fe63e71..df15e35e00e04 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -4118,7 +4118,6 @@ fn test_linux(target: &str) { // FIXME(linux): Requires >= 6.12 kernel headers. "dmabuf_cmsg" | "dmabuf_token" => true, - // FIXME(linux): Requires >= 6.12 kernel headers. "mnt_ns_info" => true, diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 39362179c453a..107433fc7fe4b 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -1778,7 +1778,6 @@ _UTX_LINESIZE _UTX_USERSIZE _WSTATUS _WSTOPPED -_opaque_pthread_t __PTHREAD_CONDATTR_SIZE__ __PTHREAD_COND_SIZE__ __PTHREAD_MUTEX_SIZE__ @@ -1790,6 +1789,7 @@ __darwin_mcontext64 __darwin_pthread_handler_rec __darwin_pthread_t __error +_opaque_pthread_t abs acct aio_cancel diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 4b23e5717fd33..82c5b3eb9ecae 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -9,12 +9,14 @@ pub type sa_family_t = u8; cfg_if! { if #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos", - ))] { + target_os = "macos", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + ))] { + pub type __darwin_pthread_t = *mut _opaque_pthread_t; + pub type pthread_t = __darwin_pthread_t; s! { pub struct __darwin_pthread_handler_rec { __routine: Option, @@ -27,10 +29,7 @@ cfg_if! { __opaque: [c_char; __PTHREAD_SIZE__], } } - pub type __darwin_pthread_t = *mut _opaque_pthread_t; - pub type pthread_t = __darwin_pthread_t; - } - else { + } else { pub type pthread_t = crate::uintptr_t; } } From 830afaff138586717783a27f8b137b8546ba6fd8 Mon Sep 17 00:00:00 2001 From: highjeans Date: Tue, 18 Mar 2025 07:49:58 +0000 Subject: [PATCH 5/8] Remove commented line --- src/unix/bsd/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 82c5b3eb9ecae..154edb3e38122 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -5,7 +5,6 @@ pub type useconds_t = u32; pub type blkcnt_t = i64; pub type socklen_t = u32; pub type sa_family_t = u8; -// pub type pthread_t = crate::uintptr_t; cfg_if! { if #[cfg(any( From b7a0e6478a7656d724cdb70f602c8bf591af09a2 Mon Sep 17 00:00:00 2001 From: R4 Cheng Date: Fri, 20 Feb 2026 00:34:57 -0800 Subject: [PATCH 6/8] Add #[non_exhaustive] attribute Ps. Doesn't really matter here since they are all private fields, but we are starting to do that for everything new (by tgross35) --- src/unix/bsd/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 154edb3e38122..d63b2388c7511 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -17,11 +17,13 @@ cfg_if! { pub type __darwin_pthread_t = *mut _opaque_pthread_t; pub type pthread_t = __darwin_pthread_t; s! { + #[non_exhaustive] pub struct __darwin_pthread_handler_rec { __routine: Option, __arg: *mut c_void, __next: *mut __darwin_pthread_handler_rec, } + #[non_exhaustive] pub struct _opaque_pthread_t { __sig: c_long, __cleanup_stack: *mut __darwin_pthread_handler_rec, From cef8e1b071834b66ae1e747b3c8a3a39b2266c59 Mon Sep 17 00:00:00 2001 From: R4 Cheng Date: Fri, 20 Feb 2026 00:42:57 -0800 Subject: [PATCH 7/8] Refactor pthread type definitions for better clarity and compatibility ref for verify other BSDs - https://github.com/freebsd/freebsd-src/blob/5bffa1d2069a05c8346eb34e17a39085fe0bf09b/include/signal.h#L68 - https://github.com/openbsd/src/blob/ac71a6695016645a6726c964da2a0f509d63c2c8/include/pthread.h#L112 --- src/unix/bsd/apple/b32/mod.rs | 1 - src/unix/bsd/apple/b64/mod.rs | 1 - src/unix/bsd/mod.rs | 29 +++++++---------------------- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/unix/bsd/apple/b32/mod.rs b/src/unix/bsd/apple/b32/mod.rs index 1e0be2ca97131..a89edb65008e8 100644 --- a/src/unix/bsd/apple/b32/mod.rs +++ b/src/unix/bsd/apple/b32/mod.rs @@ -60,7 +60,6 @@ s_no_extra_traits! { #[deprecated(since = "0.2.55")] pub const NET_RT_MAXID: c_int = 10; -pub const __PTHREAD_SIZE__: usize = 4088; pub const __PTHREAD_MUTEX_SIZE__: usize = 40; pub const __PTHREAD_COND_SIZE__: usize = 24; pub const __PTHREAD_CONDATTR_SIZE__: usize = 4; diff --git a/src/unix/bsd/apple/b64/mod.rs b/src/unix/bsd/apple/b64/mod.rs index ee31487d05a41..89da33a0981e9 100644 --- a/src/unix/bsd/apple/b64/mod.rs +++ b/src/unix/bsd/apple/b64/mod.rs @@ -53,7 +53,6 @@ s! { #[deprecated(since = "0.2.55")] pub const NET_RT_MAXID: c_int = 11; -pub const __PTHREAD_SIZE__: usize = 8176; pub const __PTHREAD_MUTEX_SIZE__: usize = 56; pub const __PTHREAD_COND_SIZE__: usize = 40; pub const __PTHREAD_CONDATTR_SIZE__: usize = 8; diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index d63b2388c7511..80da4896f3c13 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -7,30 +7,15 @@ pub type socklen_t = u32; pub type sa_family_t = u8; cfg_if! { - if #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos", - ))] { - pub type __darwin_pthread_t = *mut _opaque_pthread_t; - pub type pthread_t = __darwin_pthread_t; - s! { - #[non_exhaustive] - pub struct __darwin_pthread_handler_rec { - __routine: Option, - __arg: *mut c_void, - __next: *mut __darwin_pthread_handler_rec, - } - #[non_exhaustive] - pub struct _opaque_pthread_t { - __sig: c_long, - __cleanup_stack: *mut __darwin_pthread_handler_rec, - __opaque: [c_char; __PTHREAD_SIZE__], - } + if #[cfg(target_vendor = "apple")] { + extern_ty! { + pub enum _opaque_pthread_t {} } + + type __darwin_pthread_t = *mut _opaque_pthread_t; + pub type pthread_t = __darwin_pthread_t; } else { + // FIXME(1.0): verify other BSDs? Glancing around, other BSDs also look like a pointer pub type pthread_t = crate::uintptr_t; } } From 37afe498454c7e029777ee7cfa5867f67fbce13a Mon Sep 17 00:00:00 2001 From: R4 Cheng Date: Sat, 21 Feb 2026 15:17:58 -0800 Subject: [PATCH 8/8] styling --- libc-test/build.rs | 18 +++++++++++++++--- libc-test/semver/apple.txt | 3 --- src/unix/bsd/apple/b32/mod.rs | 7 ------- src/unix/bsd/apple/b64/mod.rs | 7 ------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index df15e35e00e04..1cbacfde9d979 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2,9 +2,20 @@ #![allow(clippy::match_like_matches_macro)] use std::fs::File; -use std::io::{BufRead, BufReader, BufWriter, Write}; -use std::path::{Path, PathBuf}; -use std::{env, io}; +use std::io::{ + BufRead, + BufReader, + BufWriter, + Write, +}; +use std::path::{ + Path, + PathBuf, +}; +use std::{ + env, + io, +}; fn do_cc() { let target = env::var("TARGET").unwrap(); @@ -4118,6 +4129,7 @@ fn test_linux(target: &str) { // FIXME(linux): Requires >= 6.12 kernel headers. "dmabuf_cmsg" | "dmabuf_token" => true, + // FIXME(linux): Requires >= 6.12 kernel headers. "mnt_ns_info" => true, diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 107433fc7fe4b..07ac437f6d10b 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -1784,10 +1784,7 @@ __PTHREAD_MUTEX_SIZE__ __PTHREAD_ONCE_SIZE__ __PTHREAD_RWLOCKATTR_SIZE__ __PTHREAD_RWLOCK_SIZE__ -__PTHREAD_SIZE__ __darwin_mcontext64 -__darwin_pthread_handler_rec -__darwin_pthread_t __error _opaque_pthread_t abs diff --git a/src/unix/bsd/apple/b32/mod.rs b/src/unix/bsd/apple/b32/mod.rs index a89edb65008e8..ab0c94ef4c2c2 100644 --- a/src/unix/bsd/apple/b32/mod.rs +++ b/src/unix/bsd/apple/b32/mod.rs @@ -60,13 +60,6 @@ s_no_extra_traits! { #[deprecated(since = "0.2.55")] pub const NET_RT_MAXID: c_int = 10; -pub const __PTHREAD_MUTEX_SIZE__: usize = 40; -pub const __PTHREAD_COND_SIZE__: usize = 24; -pub const __PTHREAD_CONDATTR_SIZE__: usize = 4; -pub const __PTHREAD_ONCE_SIZE__: usize = 4; -pub const __PTHREAD_RWLOCK_SIZE__: usize = 124; -pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 12; - pub const TIOCTIMESTAMP: c_ulong = 0x40087459; pub const TIOCDCDTIMESTAMP: c_ulong = 0x40087458; diff --git a/src/unix/bsd/apple/b64/mod.rs b/src/unix/bsd/apple/b64/mod.rs index 89da33a0981e9..5ccf65abb840e 100644 --- a/src/unix/bsd/apple/b64/mod.rs +++ b/src/unix/bsd/apple/b64/mod.rs @@ -53,13 +53,6 @@ s! { #[deprecated(since = "0.2.55")] pub const NET_RT_MAXID: c_int = 11; -pub const __PTHREAD_MUTEX_SIZE__: usize = 56; -pub const __PTHREAD_COND_SIZE__: usize = 40; -pub const __PTHREAD_CONDATTR_SIZE__: usize = 8; -pub const __PTHREAD_ONCE_SIZE__: usize = 8; -pub const __PTHREAD_RWLOCK_SIZE__: usize = 192; -pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 16; - pub const TIOCTIMESTAMP: c_ulong = 0x40107459; pub const TIOCDCDTIMESTAMP: c_ulong = 0x40107458;