Skip to content

apple introduces pthread introspection api #2452

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

Merged
merged 1 commit into from
Oct 15, 2021
Merged
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
22 changes: 19 additions & 3 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_") {
Expand All @@ -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,
}
});
Expand All @@ -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,
}
Expand Down
8 changes: 8 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down