Skip to content

Commit

Permalink
Apple: Add additional pthread APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-bennett committed Oct 1, 2024
1 parent d8ff07b commit 7b0b1a8
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 0 deletions.
26 changes: 26 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1117,16 +1117,29 @@ PROC_CSM_TECS
PROC_PIDTASKALLINFO
PROC_PIDTASKINFO
PROC_PIDTHREADINFO
PTHREAD_CANCEL_ASYNCHRONOUS
PTHREAD_CANCEL_DEFERRED
PTHREAD_CANCEL_DISABLE
PTHREAD_CANCEL_ENABLE
PTHREAD_CANCELED
PTHREAD_CREATE_DETACHED
PTHREAD_CREATE_JOINABLE
PTHREAD_EXPLICIT_SCHED
PTHREAD_INHERIT_SCHED
PTHREAD_INTROSPECTION_THREAD_CREATE
PTHREAD_INTROSPECTION_THREAD_DESTROY
PTHREAD_INTROSPECTION_THREAD_START
PTHREAD_INTROSPECTION_THREAD_TERMINATE
PTHREAD_MUTEX_DEFAULT
PTHREAD_MUTEX_ERRORCHECK
PTHREAD_ONCE_INIT
PTHREAD_PRIO_INHERIT
PTHREAD_PRIO_NONE
PTHREAD_PRIO_PROTECT
PTHREAD_PROCESS_PRIVATE
PTHREAD_PROCESS_SHARED
PTHREAD_SCOPE_PROCESS
PTHREAD_SCOPE_SYSTEM
PTHREAD_STACK_MIN
PT_ATTACH
PT_ATTACHEXC
Expand Down Expand Up @@ -1744,6 +1757,7 @@ _WSTOPPED
__PTHREAD_CONDATTR_SIZE__
__PTHREAD_COND_SIZE__
__PTHREAD_MUTEX_SIZE__
__PTHREAD_ONCE_SIZE__
__PTHREAD_RWLOCKATTR_SIZE__
__PTHREAD_RWLOCK_SIZE__
__darwin_mcontext64
Expand Down Expand Up @@ -2041,8 +2055,18 @@ pseudo_AF_KEY
pseudo_AF_PIP
pseudo_AF_RTIP
pseudo_AF_XTP
pthread_atfork
pthread_attr_getdetachstate
pthread_attr_getinheritsched
pthread_attr_getschedparam
pthread_attr_getschedpolicy
pthread_attr_getscope
pthread_attr_getstackaddr
pthread_attr_setinheritsched
pthread_attr_setschedparam
pthread_attr_setschedpolicy
pthread_attr_setscope
pthread_attr_setstackaddr
pthread_cancel
pthread_condattr_getpshared
pthread_condattr_setpshared
Expand All @@ -2064,6 +2088,8 @@ pthread_kill
pthread_main_np
pthread_mutexattr_getpshared
pthread_mutexattr_setpshared
pthread_once
pthread_once_t
pthread_rwlockattr_getpshared
pthread_rwlockattr_setpshared
pthread_setname_np
Expand Down
35 changes: 35 additions & 0 deletions src/unix/bsd/apple/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ s_no_extra_traits! {
__sig: c_long,
__opaque: [::c_char; 36]
}

pub struct pthread_once_t {
__sig: c_long,
__opaque: [::c_char; ::__PTHREAD_ONCE_SIZE__],
}
}

cfg_if! {
Expand Down Expand Up @@ -82,6 +87,29 @@ cfg_if! {
self.__opaque.hash(state);
}
}
impl PartialEq for pthread_once_t {
fn eq(&self, other: &pthread_once_t) -> bool {
self.__sig == other.__sig
&& self.__opaque
.iter()
.zip(other.__opaque.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_once_t {}
impl ::fmt::Debug for pthread_once_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_once_t")
.field("__sig", &self.__sig)
.finish()
}
}
impl ::hash::Hash for pthread_once_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.__sig.hash(state);
self.__opaque.hash(state);
}
}
}
}

Expand All @@ -92,6 +120,7 @@ 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;

Expand All @@ -103,6 +132,12 @@ pub const BIOCSRTIMEOUT: ::c_ulong = 0x8008426d;
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4008426e;
pub const BIOCSETFNR: ::c_ulong = 0x8008427e;

const _PTHREAD_ONCE_SIG_INIT: c_long = 0x30B1BCBA;
pub const PTHREAD_ONCE_INIT: ::pthread_once_t = ::pthread_once_t {
__sig: _PTHREAD_ONCE_SIG_INIT,
__opaque: [0; 4],
};

extern "C" {
pub fn exchangedata(
path1: *const ::c_char,
Expand Down
35 changes: 35 additions & 0 deletions src/unix/bsd/apple/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ s_no_extra_traits! {
__sig: c_long,
__opaque: [::c_char; 56]
}

pub struct pthread_once_t {
__sig: c_long,
__opaque: [::c_char; __PTHREAD_ONCE_SIZE__],
}
}

cfg_if! {
Expand Down Expand Up @@ -82,6 +87,29 @@ cfg_if! {
self.__opaque.hash(state);
}
}
impl PartialEq for pthread_once_t {
fn eq(&self, other: &pthread_once_t) -> bool {
self.__sig == other.__sig
&& self.__opaque
.iter()
.zip(other.__opaque.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for pthread_once_t {}
impl ::fmt::Debug for pthread_once_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("pthread_once_t")
.field("__sig", &self.__sig)
.finish()
}
}
impl ::hash::Hash for pthread_once_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.__sig.hash(state);
self.__opaque.hash(state);
}
}
}
}

Expand All @@ -92,6 +120,7 @@ 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;

Expand All @@ -103,6 +132,12 @@ pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;
pub const BIOCSETFNR: ::c_ulong = 0x8010427e;

const _PTHREAD_ONCE_SIG_INIT: c_long = 0x30B1BCBA;
pub const PTHREAD_ONCE_INIT: ::pthread_once_t = ::pthread_once_t {
__sig: _PTHREAD_ONCE_SIG_INIT,
__opaque: [0; 8],
};

extern "C" {
pub fn exchangedata(
path1: *const ::c_char,
Expand Down
47 changes: 47 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3761,6 +3761,19 @@ pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 2;
pub const PTHREAD_PROCESS_SHARED: ::c_int = 1;
pub const PTHREAD_CREATE_JOINABLE: ::c_int = 1;
pub const PTHREAD_CREATE_DETACHED: ::c_int = 2;
pub const PTHREAD_INHERIT_SCHED: ::c_int = 1;
pub const PTHREAD_EXPLICIT_SCHED: ::c_int = 2;
pub const PTHREAD_CANCEL_ENABLE: ::c_int = 0x01;
pub const PTHREAD_CANCEL_DISABLE: ::c_int = 0x00;
pub const PTHREAD_CANCEL_DEFERRED: ::c_int = 0x02;
pub const PTHREAD_CANCEL_ASYNCHRONOUS: ::c_int = 0x00;
pub const PTHREAD_CANCELED: *mut ::c_void = 1 as *mut ::c_void;
pub const PTHREAD_SCOPE_SYSTEM: ::c_int = 1;
pub const PTHREAD_SCOPE_PROCESS: ::c_int = 2;
pub const PTHREAD_PRIO_NONE: ::c_int = 0;
pub const PTHREAD_PRIO_INHERIT: ::c_int = 1;
pub const PTHREAD_PRIO_PROTECT: ::c_int = 2;

#[cfg(target_arch = "aarch64")]
pub const PTHREAD_STACK_MIN: ::size_t = 16384;
#[cfg(not(target_arch = "aarch64"))]
Expand Down Expand Up @@ -5700,6 +5713,40 @@ extern "C" {
newp: *mut ::c_void,
newlen: ::size_t,
) -> ::c_int;
pub fn pthread_once(
once_control: *mut ::pthread_once_t,
init_routine: ::Option<unsafe extern "C" fn()>,
) -> ::c_int;
pub fn pthread_attr_getinheritsched(
attr: *const ::pthread_attr_t,
inheritsched: *mut ::c_int,
) -> ::c_int;
pub fn pthread_attr_getschedpolicy(
attr: *const ::pthread_attr_t,
policy: *mut ::c_int,
) -> ::c_int;
pub fn pthread_attr_getscope(
attr: *const ::pthread_attr_t,
contentionscope: *mut ::c_int,
) -> ::c_int;
pub fn pthread_attr_getstackaddr(
attr: *const ::pthread_attr_t,
stackaddr: *mut *mut ::c_void,
) -> ::c_int;
pub fn pthread_attr_getdetachstate(
attr: *const ::pthread_attr_t,
detachstate: *mut ::c_int,
) -> ::c_int;
pub fn pthread_attr_setinheritsched(
attr: *mut ::pthread_attr_t,
inheritsched: ::c_int,
) -> ::c_int;
pub fn pthread_attr_setschedpolicy(attr: *mut ::pthread_attr_t, policy: ::c_int) -> ::c_int;
pub fn pthread_attr_setscope(attr: *mut ::pthread_attr_t, contentionscope: ::c_int) -> ::c_int;
pub fn pthread_attr_setstackaddr(
attr: *mut ::pthread_attr_t,
stackaddr: *mut ::c_void,
) -> ::c_int;
pub fn pthread_setname_np(name: *const ::c_char) -> ::c_int;
pub fn pthread_getname_np(thread: ::pthread_t, name: *mut ::c_char, len: ::size_t) -> ::c_int;
pub fn pthread_mach_thread_np(thread: ::pthread_t) -> ::mach_port_t;
Expand Down

0 comments on commit 7b0b1a8

Please sign in to comment.