Skip to content

Commit 7c28479

Browse files
committed
apple introduces pthread introspection api
1 parent 5b308d9 commit 7c28479

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

libc-test/build.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ fn test_apple(target: &str) {
284284
}
285285
});
286286

287+
cfg.skip_type(move |ty| {
288+
match ty {
289+
// requires macOs 11.0 or higher
290+
"pthread_introspection_hook_t" => true,
291+
_ => false,
292+
}
293+
});
294+
287295
cfg.skip_const(move |name| {
288296
// They're declared via `deprecated_mach` and we don't support it anymore.
289297
if name.starts_with("VM_FLAGS_") {
@@ -297,8 +305,12 @@ fn test_apple(target: &str) {
297305
"SF_SETTABLE" => true,
298306
// FIXME: the values have been changed since Big Sur
299307
"HW_TARGET" | "HW_PRODUCT" | "HW_MAXID" => true,
300-
// this const requires macOS 11.0 or higher
301-
"RTF_GLOBAL" => true,
308+
// these consts requires macOS 11.0 or higher
309+
"PTHREAD_INTROSPECTION_THREAD_CREATE"
310+
| "PTHREAD_INTROSPECTION_THREAD_DESTROY"
311+
| "PTHREAD_INTROSPECTION_THREAD_START"
312+
| "PTHREAD_INTROSPECTION_THREAD_TERMINATE"
313+
| "RTF_GLOBAL" => true,
302314
_ => false,
303315
}
304316
});
@@ -313,7 +325,11 @@ fn test_apple(target: &str) {
313325
"close" => true,
314326

315327
// these calls require macOS 11.0 or higher
316-
"preadv" | "pwritev" => true,
328+
"pthread_introspection_hook_install"
329+
| "pthread_introspection_getspecific_np"
330+
| "pthread_introspection_setspecific_np"
331+
| "preadv"
332+
| "pwritev" => true,
317333

318334
_ => false,
319335
}

libc-test/semver/apple.txt

+8
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,10 @@ PROC_PIDTASKINFO
942942
PROC_PIDTHREADINFO
943943
PTHREAD_CREATE_DETACHED
944944
PTHREAD_CREATE_JOINABLE
945+
PTHREAD_INTROSPECTION_THREAD_CREATE
946+
PTHREAD_INTROSPECTION_THREAD_DESTROY
947+
PTHREAD_INTROSPECTION_THREAD_START
948+
PTHREAD_INTROSPECTION_THREAD_TERMINATE
945949
PTHREAD_MUTEX_DEFAULT
946950
PTHREAD_MUTEX_ERRORCHECK
947951
PTHREAD_PROCESS_PRIVATE
@@ -1826,6 +1830,10 @@ pthread_attr_getschedparam
18261830
pthread_attr_setschedparam
18271831
pthread_create_from_mach_thread
18281832
pthread_getschedparam
1833+
pthread_introspection_getspecific_np
1834+
pthread_introspection_hook_t
1835+
pthread_introspection_hook_install
1836+
pthread_introspection_setspecific_np
18291837
pthread_setschedparam
18301838
pthread_cancel
18311839
pthread_condattr_getpshared

src/unix/bsd/apple/mod.rs

+23
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ pub type thread_latency_qos_policy_t = *mut thread_latency_qos_policy;
112112
pub type thread_throughput_qos_policy_data_t = thread_throughput_qos_policy;
113113
pub type thread_throughput_qos_policy_t = *mut thread_throughput_qos_policy;
114114

115+
pub type pthread_introspection_hook_t =
116+
extern "C" fn(event: ::c_uint, thread: ::pthread_t, addr: *mut ::c_void, size: ::size_t);
117+
115118
pub type vm_statistics_t = *mut vm_statistics;
116119
pub type vm_statistics_data_t = vm_statistics;
117120
pub type vm_statistics64_t = *mut vm_statistics64;
@@ -2959,6 +2962,11 @@ pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x0020;
29592962
pub const AT_SYMLINK_FOLLOW: ::c_int = 0x0040;
29602963
pub const AT_REMOVEDIR: ::c_int = 0x0080;
29612964

2965+
pub const PTHREAD_INTROSPECTION_THREAD_CREATE: ::c_uint = 1;
2966+
pub const PTHREAD_INTROSPECTION_THREAD_START: ::c_uint = 2;
2967+
pub const PTHREAD_INTROSPECTION_THREAD_TERMINATE: ::c_uint = 3;
2968+
pub const PTHREAD_INTROSPECTION_THREAD_DESTROY: ::c_uint = 4;
2969+
29622970
pub const TIOCMODG: ::c_ulong = 0x40047403;
29632971
pub const TIOCMODS: ::c_ulong = 0x80047404;
29642972
pub const TIOCM_LE: ::c_int = 0x1;
@@ -4851,6 +4859,21 @@ extern "C" {
48514859
policy: ::c_int,
48524860
param: *const sched_param,
48534861
) -> ::c_int;
4862+
4863+
// Available from Big Sur
4864+
pub fn pthread_introspection_hook_install(
4865+
hook: ::pthread_introspection_hook_t,
4866+
) -> ::pthread_introspection_hook_t;
4867+
pub fn pthread_introspection_setspecific_np(
4868+
thread: ::pthread_t,
4869+
key: ::pthread_key_t,
4870+
value: *const ::c_void,
4871+
) -> ::c_int;
4872+
pub fn pthread_introspection_getspecific_np(
4873+
thread: ::pthread_t,
4874+
key: ::pthread_key_t,
4875+
) -> *mut ::c_void;
4876+
48544877
pub fn thread_policy_set(
48554878
thread: thread_t,
48564879
flavor: thread_policy_flavor_t,

0 commit comments

Comments
 (0)