diff --git a/src/new/bionic_libc/mod.rs b/src/new/bionic_libc/mod.rs index b608e2f123c96..1dd186e4f940f 100644 --- a/src/new/bionic_libc/mod.rs +++ b/src/new/bionic_libc/mod.rs @@ -2,5 +2,6 @@ //! //! +pub(crate) mod pthread; pub(crate) mod sys; pub(crate) mod unistd; diff --git a/src/new/bionic_libc/pthread.rs b/src/new/bionic_libc/pthread.rs new file mode 100644 index 0000000000000..ab2657c5a3a4c --- /dev/null +++ b/src/new/bionic_libc/pthread.rs @@ -0,0 +1,31 @@ +//! Header: `unistd.h` + +pub use crate::new::common::linux_like::pthread::pthread_setname_np; +pub use crate::new::common::posix::pthread::{ + pthread_atfork, + pthread_attr_getguardsize, + pthread_attr_getinheritsched, + pthread_attr_setguardsize, + pthread_attr_setinheritsched, + pthread_barrier_destroy, + pthread_barrier_init, + pthread_barrier_wait, + pthread_barrierattr_destroy, + pthread_barrierattr_getpshared, + pthread_barrierattr_init, + pthread_barrierattr_setpshared, + pthread_condattr_getpshared, + pthread_create, + pthread_getcpuclockid, + pthread_getschedparam, + pthread_kill, + pthread_mutex_timedlock, + pthread_mutexattr_getpshared, + pthread_setschedparam, + pthread_sigmask, + pthread_spin_destroy, + pthread_spin_init, + pthread_spin_lock, + pthread_spin_trylock, + pthread_spin_unlock, +}; diff --git a/src/new/common/linux_like/mod.rs b/src/new/common/linux_like/mod.rs index 1faf98706392f..b6700d8d0a84e 100644 --- a/src/new/common/linux_like/mod.rs +++ b/src/new/common/linux_like/mod.rs @@ -1,4 +1,4 @@ //! API that primarily comes from Linux but is also used other platforms (e.g. Android). -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "android", target_os = "linux"))] pub(crate) mod pthread; diff --git a/src/new/common/linux_like/pthread.rs b/src/new/common/linux_like/pthread.rs index 19c7cd81ec3b9..1cb042668031f 100644 --- a/src/new/common/linux_like/pthread.rs +++ b/src/new/common/linux_like/pthread.rs @@ -18,6 +18,6 @@ extern "C" { cpuset: *const crate::cpu_set_t, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_setname_np(thread: crate::pthread_t, name: *const c_char) -> c_int; } diff --git a/src/new/common/posix/mod.rs b/src/new/common/posix/mod.rs index 0428f6503a8a8..6008881d7469c 100644 --- a/src/new/common/posix/mod.rs +++ b/src/new/common/posix/mod.rs @@ -3,6 +3,6 @@ //! These can be found at: . // FIXME(pthread): eventually all platforms should use this module -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))] pub(crate) mod pthread; pub(crate) mod unistd; diff --git a/src/new/common/posix/pthread.rs b/src/new/common/posix/pthread.rs index 847467b6b965a..894957edc88c6 100644 --- a/src/new/common/posix/pthread.rs +++ b/src/new/common/posix/pthread.rs @@ -5,20 +5,20 @@ use crate::prelude::*; extern "C" { - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_atfork( prepare: Option, parent: Option, child: Option, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_attr_getguardsize( attr: *const crate::pthread_attr_t, guardsize: *mut size_t, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_attr_getinheritsched( attr: *const crate::pthread_attr_t, inheritsched: *mut c_int, @@ -36,10 +36,10 @@ extern "C" { policy: *mut c_int, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_attr_setguardsize(attr: *mut crate::pthread_attr_t, guardsize: size_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_attr_setinheritsched( attr: *mut crate::pthread_attr_t, inheritsched: c_int, @@ -54,32 +54,32 @@ extern "C" { #[cfg(target_os = "linux")] pub fn pthread_attr_setschedpolicy(attr: *mut crate::pthread_attr_t, policy: c_int) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_barrier_destroy(barrier: *mut crate::pthread_barrier_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_barrier_init( barrier: *mut crate::pthread_barrier_t, attr: *const crate::pthread_barrierattr_t, count: c_uint, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_barrier_wait(barrier: *mut crate::pthread_barrier_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_barrierattr_destroy(attr: *mut crate::pthread_barrierattr_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_barrierattr_getpshared( attr: *const crate::pthread_barrierattr_t, shared: *mut c_int, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_barrierattr_init(attr: *mut crate::pthread_barrierattr_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_barrierattr_setpshared( attr: *mut crate::pthread_barrierattr_t, shared: c_int, @@ -88,13 +88,13 @@ extern "C" { #[cfg(all(target_os = "linux", not(target_env = "ohos")))] pub fn pthread_cancel(thread: crate::pthread_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_condattr_getpshared( attr: *const crate::pthread_condattr_t, pshared: *mut c_int, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))] pub fn pthread_create( native: *mut crate::pthread_t, attr: *const crate::pthread_attr_t, @@ -102,10 +102,10 @@ extern "C" { value: *mut c_void, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_getcpuclockid(thread: crate::pthread_t, clk_id: *mut crate::clockid_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_getschedparam( native: crate::pthread_t, policy: *mut c_int, @@ -114,13 +114,13 @@ extern "C" { // FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required // in pthread. - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int; #[cfg(all(target_os = "linux", not(target_env = "ohos")))] pub fn pthread_mutex_consistent(mutex: *mut crate::pthread_mutex_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg_attr(gnu_time_bits64, link_name = "__pthread_mutex_timedlock64")] pub fn pthread_mutex_timedlock( lock: *mut crate::pthread_mutex_t, @@ -133,7 +133,7 @@ extern "C" { protocol: *mut c_int, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_mutexattr_getpshared( attr: *const crate::pthread_mutexattr_t, pshared: *mut c_int, @@ -160,7 +160,7 @@ extern "C" { #[cfg(target_os = "linux")] pub fn pthread_once(control: *mut crate::pthread_once_t, routine: extern "C" fn()) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_setschedparam( native: crate::pthread_t, policy: c_int, @@ -172,25 +172,25 @@ extern "C" { // FIXME(reorg): In recent POSIX versions, this is a signal.h function and not required // in pthread. - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_sigmask( how: c_int, set: *const crate::sigset_t, oldset: *mut crate::sigset_t, ) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_spin_destroy(lock: *mut crate::pthread_spinlock_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_spin_init(lock: *mut crate::pthread_spinlock_t, pshared: c_int) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_spin_lock(lock: *mut crate::pthread_spinlock_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_spin_trylock(lock: *mut crate::pthread_spinlock_t) -> c_int; - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "linux"))] pub fn pthread_spin_unlock(lock: *mut crate::pthread_spinlock_t) -> c_int; } diff --git a/src/new/emscripten/mod.rs b/src/new/emscripten/mod.rs index fec0fe3bfdd43..f0765d3e06fff 100644 --- a/src/new/emscripten/mod.rs +++ b/src/new/emscripten/mod.rs @@ -2,4 +2,5 @@ //! //! * Headers: +pub(crate) mod pthread; pub(crate) mod unistd; diff --git a/src/new/emscripten/pthread.rs b/src/new/emscripten/pthread.rs new file mode 100644 index 0000000000000..11da53ef4e243 --- /dev/null +++ b/src/new/emscripten/pthread.rs @@ -0,0 +1,3 @@ +//! Header: `pthread.h` + +pub use crate::new::common::posix::pthread::pthread_create; diff --git a/src/new/mod.rs b/src/new/mod.rs index ed25ec630581a..72e838fee6ecb 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -207,7 +207,7 @@ cfg_if! { cfg_if! { if #[cfg(target_family = "unix")] { // FIXME(pthread): eventually all platforms should use this module - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "linux"))] pub use pthread::*; pub use unistd::*; } diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 840def4a93bfc..5625704682e3d 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -3508,11 +3508,6 @@ extern "C" { timeout: c_int, ) -> c_int; pub fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *mut crate::epoll_event) -> c_int; - pub fn pthread_getschedparam( - native: crate::pthread_t, - policy: *mut c_int, - param: *mut crate::sched_param, - ) -> c_int; pub fn unshare(flags: c_int) -> c_int; pub fn umount(target: *const c_char) -> c_int; pub fn sched_get_priority_max(policy: c_int) -> c_int; @@ -3553,32 +3548,7 @@ extern "C" { timeout: *const crate::timespec, sigmask: *const sigset_t, ) -> c_int; - pub fn pthread_mutex_timedlock( - lock: *mut pthread_mutex_t, - abstime: *const crate::timespec, - ) -> c_int; - pub fn pthread_barrierattr_init(attr: *mut crate::pthread_barrierattr_t) -> c_int; - pub fn pthread_barrierattr_destroy(attr: *mut crate::pthread_barrierattr_t) -> c_int; - pub fn pthread_barrierattr_getpshared( - attr: *const crate::pthread_barrierattr_t, - shared: *mut c_int, - ) -> c_int; - pub fn pthread_barrierattr_setpshared( - attr: *mut crate::pthread_barrierattr_t, - shared: c_int, - ) -> c_int; - pub fn pthread_barrier_init( - barrier: *mut pthread_barrier_t, - attr: *const crate::pthread_barrierattr_t, - count: c_uint, - ) -> c_int; - pub fn pthread_barrier_destroy(barrier: *mut pthread_barrier_t) -> c_int; - pub fn pthread_barrier_wait(barrier: *mut pthread_barrier_t) -> c_int; - pub fn pthread_spin_init(lock: *mut crate::pthread_spinlock_t, pshared: c_int) -> c_int; - pub fn pthread_spin_destroy(lock: *mut crate::pthread_spinlock_t) -> c_int; - pub fn pthread_spin_lock(lock: *mut crate::pthread_spinlock_t) -> c_int; - pub fn pthread_spin_trylock(lock: *mut crate::pthread_spinlock_t) -> c_int; - pub fn pthread_spin_unlock(lock: *mut crate::pthread_spinlock_t) -> c_int; + pub fn clone( cb: extern "C" fn(*mut c_void) -> c_int, child_stack: *mut c_void, @@ -3593,29 +3563,11 @@ extern "C" { rqtp: *const crate::timespec, rmtp: *mut crate::timespec, ) -> c_int; - pub fn pthread_attr_getguardsize( - attr: *const crate::pthread_attr_t, - guardsize: *mut size_t, - ) -> c_int; - pub fn pthread_attr_setguardsize(attr: *mut crate::pthread_attr_t, guardsize: size_t) -> c_int; - pub fn pthread_attr_getinheritsched( - attr: *const crate::pthread_attr_t, - flag: *mut c_int, - ) -> c_int; - pub fn pthread_attr_setinheritsched(attr: *mut crate::pthread_attr_t, flag: c_int) -> c_int; + pub fn sethostname(name: *const c_char, len: size_t) -> c_int; pub fn sched_get_priority_min(policy: c_int) -> c_int; - pub fn pthread_condattr_getpshared( - attr: *const pthread_condattr_t, - pshared: *mut c_int, - ) -> c_int; pub fn sysinfo(info: *mut crate::sysinfo) -> c_int; pub fn umount2(target: *const c_char, flags: c_int) -> c_int; - pub fn pthread_setschedparam( - native: crate::pthread_t, - policy: c_int, - param: *const crate::sched_param, - ) -> c_int; pub fn swapon(path: *const c_char, swapflags: c_int) -> c_int; pub fn sched_setscheduler( pid: crate::pid_t, @@ -3643,10 +3595,8 @@ extern "C" { buflen: size_t, result: *mut *mut crate::group, ) -> c_int; - pub fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int; pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t; pub fn getgrnam(name: *const c_char) -> *mut crate::group; - pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int; pub fn sem_unlink(name: *const c_char) -> c_int; pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int; pub fn getpwnam_r( @@ -3669,11 +3619,6 @@ extern "C" { timeout: *const crate::timespec, ) -> c_int; pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int; - pub fn pthread_atfork( - prepare: Option, - parent: Option, - child: Option, - ) -> c_int; pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group; pub fn getgrouplist( user: *const c_char, @@ -3682,18 +3627,8 @@ extern "C" { ngroups: *mut c_int, ) -> c_int; pub fn initgroups(user: *const c_char, group: crate::gid_t) -> c_int; - pub fn pthread_mutexattr_getpshared( - attr: *const pthread_mutexattr_t, - pshared: *mut c_int, - ) -> c_int; pub fn popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE; pub fn faccessat(dirfd: c_int, pathname: *const c_char, mode: c_int, flags: c_int) -> c_int; - pub fn pthread_create( - native: *mut crate::pthread_t, - attr: *const crate::pthread_attr_t, - f: extern "C" fn(*mut c_void) -> *mut c_void, - value: *mut c_void, - ) -> c_int; pub fn __errno() -> *mut c_int; pub fn inotify_rm_watch(fd: c_int, wd: u32) -> c_int; pub fn inotify_init() -> c_int; @@ -3729,8 +3664,6 @@ extern "C" { pub fn getrandom(buf: *mut c_void, buflen: size_t, flags: c_uint) -> ssize_t; pub fn getentropy(buf: *mut c_void, buflen: size_t) -> c_int; - pub fn pthread_setname_np(thread: crate::pthread_t, name: *const c_char) -> c_int; - pub fn __system_property_set(__name: *const c_char, __value: *const c_char) -> c_int; pub fn __system_property_get(__name: *const c_char, __value: *mut c_char) -> c_int; pub fn __system_property_find(__name: *const c_char) -> *const prop_info; @@ -3755,8 +3688,6 @@ extern "C" { pub fn reallocarray(ptr: *mut c_void, nmemb: size_t, size: size_t) -> *mut c_void; - pub fn pthread_getcpuclockid(thread: crate::pthread_t, clk_id: *mut crate::clockid_t) -> c_int; - pub fn dirname(path: *const c_char) -> *mut c_char; pub fn basename(path: *const c_char) -> *mut c_char; pub fn getopt_long( diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 820480213883b..8996527e2e8e1 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -1436,12 +1436,6 @@ extern "C" { pub fn ioctl(fd: c_int, request: c_int, ...) -> c_int; pub fn getpriority(which: c_int, who: crate::id_t) -> c_int; pub fn setpriority(which: c_int, who: crate::id_t, prio: c_int) -> c_int; - pub fn pthread_create( - native: *mut crate::pthread_t, - attr: *const crate::pthread_attr_t, - f: extern "C" fn(*mut c_void) -> *mut c_void, - value: *mut c_void, - ) -> c_int; pub fn getentropy(buf: *mut c_void, buflen: size_t) -> c_int;