Skip to content

Incorrect pthread_t definition on Darwin (should be a raw pointer, not an uintptr_t) #4336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ fn test_apple(target: &str) {
// OSX calls this something else
"sighandler_t" => "sig_t".to_string(),

"_opaque_pthread_t" => format!("struct {}", ty),
t if is_union => format!("union {}", t),
t if t.ends_with("_t") => t.to_string(),
t if is_struct => format!("struct {}", t),
Expand Down Expand Up @@ -4064,8 +4065,7 @@ fn test_linux(target: &str) {
"epoll_params" => true,

// FIXME(linux): Requires >= 6.12 kernel headers.
"dmabuf_cmsg" |
"dmabuf_token" => true,
"dmabuf_cmsg" | "dmabuf_token" => true,

_ => false,
}
Expand Down
4 changes: 4 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1779,8 +1779,12 @@ __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
acct
aio_cancel
Expand Down
1 change: 1 addition & 0 deletions src/unix/bsd/apple/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ cfg_if! {
#[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;
Expand Down
1 change: 1 addition & 0 deletions src/unix/bsd/apple/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ cfg_if! {
#[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;
Expand Down
29 changes: 28 additions & 1 deletion src/unix/bsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,34 @@ 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(
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<unsafe extern "C" fn(*mut c_void)>,
__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__],
}
}
} else {
pub type pthread_t = crate::uintptr_t;
}
}

pub type nfds_t = c_uint;
pub type regoff_t = off_t;

Expand Down
Loading