summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid CARLIER <devnexen@gmail.com>2021-10-15 19:30:38 +0100
committerDavid Carlier <devnexen@gmail.com>2021-10-15 20:18:48 +0100
commit7c2847927f6e65c131d61debcc83a74e7b9b36dc (patch)
tree5aad387b7d78e38b010532fc617dbee08459e967
parent5b308d9ba98c215d9b320e962f25836af3fd17b6 (diff)
downloadrust-libc-7c2847927f6e65c131d61debcc83a74e7b9b36dc.tar.gz
apple introduces pthread introspection api
-rw-r--r--libc-test/build.rs22
-rw-r--r--libc-test/semver/apple.txt8
-rw-r--r--src/unix/bsd/apple/mod.rs23
3 files changed, 50 insertions, 3 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs
index d97285ca45..1f38a19a6b 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -284,6 +284,14 @@ fn test_apple(target: &str) {
}
});
+ cfg.skip_type(move |ty| {
+ match ty {
+ // requires macOs 11.0 or higher
+ "pthread_introspection_hook_t" => true,
+ _ => false,
+ }
+ });
+
cfg.skip_const(move |name| {
// They're declared via `deprecated_mach` and we don't support it anymore.
if name.starts_with("VM_FLAGS_") {
@@ -297,8 +305,12 @@ fn test_apple(target: &str) {
"SF_SETTABLE" => true,
// FIXME: the values have been changed since Big Sur
"HW_TARGET" | "HW_PRODUCT" | "HW_MAXID" => true,
- // this const requires macOS 11.0 or higher
- "RTF_GLOBAL" => true,
+ // these consts requires macOS 11.0 or higher
+ "PTHREAD_INTROSPECTION_THREAD_CREATE"
+ | "PTHREAD_INTROSPECTION_THREAD_DESTROY"
+ | "PTHREAD_INTROSPECTION_THREAD_START"
+ | "PTHREAD_INTROSPECTION_THREAD_TERMINATE"
+ | "RTF_GLOBAL" => true,
_ => false,
}
});
@@ -313,7 +325,11 @@ fn test_apple(target: &str) {
"close" => true,
// these calls require macOS 11.0 or higher
- "preadv" | "pwritev" => true,
+ "pthread_introspection_hook_install"
+ | "pthread_introspection_getspecific_np"
+ | "pthread_introspection_setspecific_np"
+ | "preadv"
+ | "pwritev" => true,
_ => false,
}
diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt
index 300ea84e9d..8592469ddb 100644
--- a/libc-test/semver/apple.txt
+++ b/libc-test/semver/apple.txt
@@ -942,6 +942,10 @@ PROC_PIDTASKINFO
PROC_PIDTHREADINFO
PTHREAD_CREATE_DETACHED
PTHREAD_CREATE_JOINABLE
+PTHREAD_INTROSPECTION_THREAD_CREATE
+PTHREAD_INTROSPECTION_THREAD_DESTROY
+PTHREAD_INTROSPECTION_THREAD_START
+PTHREAD_INTROSPECTION_THREAD_TERMINATE
PTHREAD_MUTEX_DEFAULT
PTHREAD_MUTEX_ERRORCHECK
PTHREAD_PROCESS_PRIVATE
@@ -1826,6 +1830,10 @@ pthread_attr_getschedparam
pthread_attr_setschedparam
pthread_create_from_mach_thread
pthread_getschedparam
+pthread_introspection_getspecific_np
+pthread_introspection_hook_t
+pthread_introspection_hook_install
+pthread_introspection_setspecific_np
pthread_setschedparam
pthread_cancel
pthread_condattr_getpshared
diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs
index d1ac0c339a..51319a5b6d 100644
--- a/src/unix/bsd/apple/mod.rs
+++ b/src/unix/bsd/apple/mod.rs
@@ -112,6 +112,9 @@ pub type thread_latency_qos_policy_t = *mut thread_latency_qos_policy;
pub type thread_throughput_qos_policy_data_t = thread_throughput_qos_policy;
pub type thread_throughput_qos_policy_t = *mut thread_throughput_qos_policy;
+pub type pthread_introspection_hook_t =
+ extern "C" fn(event: ::c_uint, thread: ::pthread_t, addr: *mut ::c_void, size: ::size_t);
+
pub type vm_statistics_t = *mut vm_statistics;
pub type vm_statistics_data_t = vm_statistics;
pub type vm_statistics64_t = *mut vm_statistics64;
@@ -2959,6 +2962,11 @@ pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x0020;
pub const AT_SYMLINK_FOLLOW: ::c_int = 0x0040;
pub const AT_REMOVEDIR: ::c_int = 0x0080;
+pub const PTHREAD_INTROSPECTION_THREAD_CREATE: ::c_uint = 1;
+pub const PTHREAD_INTROSPECTION_THREAD_START: ::c_uint = 2;
+pub const PTHREAD_INTROSPECTION_THREAD_TERMINATE: ::c_uint = 3;
+pub const PTHREAD_INTROSPECTION_THREAD_DESTROY: ::c_uint = 4;
+
pub const TIOCMODG: ::c_ulong = 0x40047403;
pub const TIOCMODS: ::c_ulong = 0x80047404;
pub const TIOCM_LE: ::c_int = 0x1;
@@ -4851,6 +4859,21 @@ extern "C" {
policy: ::c_int,
param: *const sched_param,
) -> ::c_int;
+
+ // Available from Big Sur
+ pub fn pthread_introspection_hook_install(
+ hook: ::pthread_introspection_hook_t,
+ ) -> ::pthread_introspection_hook_t;
+ pub fn pthread_introspection_setspecific_np(
+ thread: ::pthread_t,
+ key: ::pthread_key_t,
+ value: *const ::c_void,
+ ) -> ::c_int;
+ pub fn pthread_introspection_getspecific_np(
+ thread: ::pthread_t,
+ key: ::pthread_key_t,
+ ) -> *mut ::c_void;
+
pub fn thread_policy_set(
thread: thread_t,
flavor: thread_policy_flavor_t,