diff options
author | bors <bors@rust-lang.org> | 2021-05-23 08:22:09 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2021-05-23 08:22:09 +0000 |
commit | f55661ea51997528f69098b3128efdb86944ff70 (patch) | |
tree | adae1d02e62ae33a58f2bebe6a76bf8762a1fd6e | |
parent | 23c29a03dcec523adc21bfec3c1cf1610f0154ef (diff) | |
parent | 5cd7c907aa390d47708fdfb0e6374a9ad6d3528d (diff) | |
download | rust-libc-f55661ea51997528f69098b3128efdb86944ff70.tar.gz |
Auto merge of #2179 - devnexen:apple_thread_policy_subset, r=JohnTitor
apple adding thread policy api
-rwxr-xr-x | libc-test/build.rs | 4 | ||||
-rw-r--r-- | libc-test/semver/apple.txt | 67 | ||||
-rw-r--r-- | src/unix/bsd/apple/mod.rs | 167 |
3 files changed, 238 insertions, 0 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs index 9040d659b7..3b1de56e7e 100755 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -187,7 +187,11 @@ fn test_apple(target: &str) { "limits.h", "locale.h", "mach-o/dyld.h", + "mach/mach_init.h", "mach/mach_time.h", + "mach/mach_types.h", + "mach/thread_act.h", + "mach/thread_policy.h", "malloc/malloc.h", "net/bpf.h", "net/if.h", diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 85753f5fed..4be61f9271 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -497,10 +497,12 @@ ITIMER_PROF ITIMER_REAL ITIMER_VIRTUAL IUTF8 +KERN_ABORTED KERN_AFFINITY KERN_AIOMAX KERN_AIOPROCMAX KERN_AIOTHREADS +KERN_ALREADY_WAITING KERN_ARGMAX KERN_BOOTFILE KERN_BOOTTIME @@ -508,16 +510,33 @@ KERN_CHECKOPENEVT KERN_CLASSIC KERN_CLASSICHANDLER KERN_CLOCKRATE +KERN_CODESIGN_ERROR KERN_COREDUMP KERN_COREFILE +KERN_DEFAULT_SET KERN_DOMAINNAME KERN_DUMMY KERN_DUMPDEV +KERN_EXCEPTION_PROTECTED KERN_EXEC +KERN_FAILURE KERN_FILE KERN_HOSTID KERN_HOSTNAME KERN_IPC +KERN_INSUFFICIENT_BUFFER_SIZE +KERN_INVALID_ADDRESS +KERN_INVALID_ARGUMENT +KERN_INVALID_HOST +KERN_INVALID_LEDGER +KERN_INVALID_MEMORY_CONTROL +KERN_INVALID_NAME +KERN_INVALID_POLICY +KERN_INVALID_OBJECT +KERN_INVALID_SECURITY +KERN_INVALID_TASK +KERN_INVALID_RIGHT +KERN_INVALID_VALUE KERN_JOB_CONTROL KERN_KDBUFWAIT KERN_KDCPUMAP @@ -542,6 +561,10 @@ KERN_KDTHRMAP KERN_KDWRITEMAP KERN_KDWRITETR KERN_LOGSIGEXIT +KERN_LOCK_OWNED +KERN_LOCK_OWNED_SELF +KERN_LOCK_SET_DESTROYED +KERN_LOCK_UNSTABLE KERN_LOW_PRI_DELAY KERN_LOW_PRI_WINDOW KERN_MAXFILES @@ -551,17 +574,30 @@ KERN_MAXPARTITIONS KERN_MAXPROC KERN_MAXPROCPERUID KERN_MAXVNODES +KERN_MEMORY_DATA_MOVED +KERN_MEMORY_PRESENT +KERN_MEMORY_RESTART_COPY +KERN_NAME_EXISTS KERN_NETBOOT KERN_NGROUPS KERN_NISDOMAINNAME +KERN_NODE_DOWN +KERN_NOT_DEPRESSED +KERN_NOT_IN_SET +KERN_NOT_RECEIVER +KERN_NOT_SUPPORTED +KERN_NOT_WAITING KERN_NTP_PLL KERN_NX_PROTECTION KERN_OPENEVT_PROC +KERN_OPERATION_TIMED_OUT KERN_OSRELDATE KERN_OSRELEASE KERN_OSREV KERN_OSTYPE KERN_OSVERSION +KERN_POLICY_LIMIT +KERN_POLICY_STATIC KERN_POSIX KERN_POSIX1 KERN_PROC @@ -582,14 +618,21 @@ KERN_PS_STRINGS KERN_RAGEVNODE KERN_RAGE_PROC KERN_RAGE_THREAD +KERN_RIGHT_EXISTS +KERN_RPC_CONTINUE_ORPHAN +KERN_RPC_SERVER_TERMINATED +KERN_RPC_TERMINATE_ORPHAN KERN_SAFEBOOT KERN_SAVED_IDS KERN_SECURELVL +KERN_SEMAPHORE_DESTROYED +KERN_SUCCESS KERN_SHREG_PRIVATIZABLE KERN_SPECULATIVE_READS KERN_SUGID_COREDUMP KERN_SYMFILE KERN_SYSV +KERN_TERMINATED KERN_TFP KERN_TFP_POLICY KERN_TFP_POLICY_DEFAULT @@ -602,6 +645,7 @@ KERN_UNOPENEVT_PROC KERN_UNRAGE_PROC KERN_UNRAGE_THREAD KERN_UPDATEINTERVAL +KERN_UREFS_OVERFLOW KERN_USRSTACK32 KERN_USRSTACK64 KERN_VERSION @@ -1142,6 +1186,24 @@ TCP_MAXSEG TCP_NOOPT TCP_NOPUSH THOUSEP +THREAD_BACKGROUND_POLICY +THREAD_BACKGROUND_POLICY_DARWIN_BG +THREAD_BACKGROUND_POLICY_COUNT +THREAD_AFFINITY_POLICY +THREAD_AFFINITY_POLICY_COUNT +THREAD_AFFINITY_TAG_NULL +THREAD_EXTENDED_POLICY +THREAD_EXTENDED_POLICY_COUNT +THREAD_LATENCY_QOS_POLICY +THREAD_LATENCY_QOS_POLICY_COUNT +THREAD_PRECEDENCE_POLICY +THREAD_PRECEDENCE_POLICY_COUNT +THREAD_STANDARD_POLICY +THREAD_STANDARD_POLICY_COUNT +THREAD_THROUGHPUT_QOS_POLICY +THREAD_THROUGHPUT_QOS_POLICY_COUNT +THREAD_TIME_CONSTRAINT_POLICY +THREAD_TIME_CONSTRAINT_POLICY_COUNT TIME_DEL TIME_ERROR TIME_INS @@ -1597,6 +1659,7 @@ in_pktinfo initgroups integer_t ipc_perm +kern_return_t kevent kevent64 kevent64_s @@ -1614,7 +1677,9 @@ lutimes mach_absolute_time mach_header mach_header_64 +mach_host_self mach_port_t +mach_thread_self mach_timebase_info mach_timebase_info_data_t madvise @@ -1762,6 +1827,8 @@ sysctl sysctlbyname sysctlnametomib telldir +thread_policy_set +thread_policy_get timeval32 timex truncate diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 5efc285dac..1190ee0121 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -28,6 +28,7 @@ pub type cpu_type_t = integer_t; pub type cpu_subtype_t = integer_t; pub type natural_t = u32; pub type mach_msg_type_number_t = natural_t; +pub type kern_return_t = ::c_int; pub type posix_spawnattr_t = *mut ::c_void; pub type posix_spawn_file_actions_t = *mut ::c_void; @@ -53,6 +54,28 @@ pub type processor_set_load_info_t = *mut processor_set_load_info; pub type processor_info_t = *mut integer_t; pub type processor_info_array_t = *mut integer_t; +pub type thread_t = mach_port_t; +pub type thread_policy_flavor_t = natural_t; +pub type thread_policy_t = *mut integer_t; +pub type thread_latency_qos_t = integer_t; +pub type thread_throughput_qos_t = integer_t; +pub type thread_standard_policy_data_t = thread_standard_policy; +pub type thread_standard_policy_t = *mut thread_standard_policy; +pub type thread_extended_policy_data_t = thread_extended_policy; +pub type thread_extended_policy_t = *mut thread_extended_policy; +pub type thread_time_constraint_policy_data_t = thread_time_constraint_policy; +pub type thread_time_constraint_policy_t = *mut thread_time_constraint_policy; +pub type thread_precedence_policy_data_t = thread_precedence_policy; +pub type thread_precedence_policy_t = *mut thread_precedence_policy; +pub type thread_affinity_policy_data_t = thread_affinity_policy; +pub type thread_affinity_policy_t = *mut thread_affinity_policy; +pub type thread_background_policy_data_t = thread_background_policy; +pub type thread_background_policy_t = *mut thread_background_policy; +pub type thread_latency_qos_policy_data_t = thread_latency_qos_policy; +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; + deprecated_mach! { pub type vm_prot_t = ::c_int; pub type vm_size_t = ::uintptr_t; @@ -570,6 +593,41 @@ s! { pub tai: ::c_long, pub time_state: ::c_int, } + + pub struct thread_standard_policy { + pub no_data: natural_t, + } + + pub struct thread_extended_policy { + pub timeshare: boolean_t, + } + + pub struct thread_time_constraint_policy { + pub period: u32, + pub computation: u32, + pub constraint: u32, + pub preemptible: boolean_t, + } + + pub struct thread_precedence_policy { + pub importance: integer_t, + } + + pub struct thread_affinity_policy { + pub affinity_tag: integer_t, + } + + pub struct thread_background_policy { + pub priority: integer_t, + } + + pub struct thread_latency_qos_policy { + pub thread_latency_qos_tier: thread_latency_qos_t, + } + + pub struct thread_throughput_qos_policy { + pub thread_throughput_qos_tier: thread_throughput_qos_t, + } } s_no_extra_traits! { @@ -2978,6 +3036,59 @@ pub const KERN_PROC_TTY: ::c_int = 4; pub const KERN_PROC_UID: ::c_int = 5; pub const KERN_PROC_RUID: ::c_int = 6; pub const KERN_PROC_LCID: ::c_int = 7; +pub const KERN_SUCCESS: ::c_int = 0; +pub const KERN_INVALID_ADDRESS: ::c_int = 1; +pub const KERN_PROTECTION_FAILURE: ::c_int = 2; +pub const KERN_NO_SPACE: ::c_int = 3; +pub const KERN_INVALID_ARGUMENT: ::c_int = 4; +pub const KERN_FAILURE: ::c_int = 5; +pub const KERN_RESOURCE_SHORTAGE: ::c_int = 6; +pub const KERN_NOT_RECEIVER: ::c_int = 7; +pub const KERN_NO_ACCESS: ::c_int = 8; +pub const KERN_MEMORY_FAILURE: ::c_int = 9; +pub const KERN_MEMORY_ERROR: ::c_int = 10; +pub const KERN_ALREADY_IN_SET: ::c_int = 11; +pub const KERN_NOT_IN_SET: ::c_int = 12; +pub const KERN_NAME_EXISTS: ::c_int = 13; +pub const KERN_ABORTED: ::c_int = 14; +pub const KERN_INVALID_NAME: ::c_int = 15; +pub const KERN_INVALID_TASK: ::c_int = 16; +pub const KERN_INVALID_RIGHT: ::c_int = 17; +pub const KERN_INVALID_VALUE: ::c_int = 18; +pub const KERN_UREFS_OVERFLOW: ::c_int = 19; +pub const KERN_INVALID_CAPABILITY: ::c_int = 20; +pub const KERN_RIGHT_EXISTS: ::c_int = 21; +pub const KERN_INVALID_HOST: ::c_int = 22; +pub const KERN_MEMORY_PRESENT: ::c_int = 23; +pub const KERN_MEMORY_DATA_MOVED: ::c_int = 24; +pub const KERN_MEMORY_RESTART_COPY: ::c_int = 25; +pub const KERN_INVALID_PROCESSOR_SET: ::c_int = 26; +pub const KERN_POLICY_LIMIT: ::c_int = 27; +pub const KERN_INVALID_POLICY: ::c_int = 28; +pub const KERN_INVALID_OBJECT: ::c_int = 29; +pub const KERN_ALREADY_WAITING: ::c_int = 30; +pub const KERN_DEFAULT_SET: ::c_int = 31; +pub const KERN_EXCEPTION_PROTECTED: ::c_int = 32; +pub const KERN_INVALID_LEDGER: ::c_int = 33; +pub const KERN_INVALID_MEMORY_CONTROL: ::c_int = 34; +pub const KERN_INVALID_SECURITY: ::c_int = 35; +pub const KERN_NOT_DEPRESSED: ::c_int = 36; +pub const KERN_TERMINATED: ::c_int = 37; +pub const KERN_LOCK_SET_DESTROYED: ::c_int = 38; +pub const KERN_LOCK_UNSTABLE: ::c_int = 39; +pub const KERN_LOCK_OWNED: ::c_int = 40; +pub const KERN_LOCK_OWNED_SELF: ::c_int = 41; +pub const KERN_SEMAPHORE_DESTROYED: ::c_int = 42; +pub const KERN_RPC_SERVER_TERMINATED: ::c_int = 43; +pub const KERN_RPC_TERMINATE_ORPHAN: ::c_int = 44; +pub const KERN_RPC_CONTINUE_ORPHAN: ::c_int = 45; +pub const KERN_NOT_SUPPORTED: ::c_int = 46; +pub const KERN_NODE_DOWN: ::c_int = 47; +pub const KERN_NOT_WAITING: ::c_int = 48; +pub const KERN_OPERATION_TIMED_OUT: ::c_int = 49; +pub const KERN_CODESIGN_ERROR: ::c_int = 50; +pub const KERN_POLICY_STATIC: ::c_int = 51; +pub const KERN_INSUFFICIENT_BUFFER_SIZE: ::c_int = 52; pub const KIPC_MAXSOCKBUF: ::c_int = 1; pub const KIPC_SOCKBUF_WASTE: ::c_int = 2; pub const KIPC_SOMAXCONN: ::c_int = 3; @@ -3380,6 +3491,19 @@ pub const TIME_ERROR: ::c_int = 5; pub const MNT_WAIT: ::c_int = 1; pub const MNT_NOWAIT: ::c_int = 2; +// <mach/thread_policy.h> +pub const THREAD_STANDARD_POLICY: ::c_int = 1; +pub const THREAD_STANDARD_POLICY_COUNT: ::c_int = 0; +pub const THREAD_EXTENDED_POLICY: ::c_int = 1; +pub const THREAD_TIME_CONSTRAINT_POLICY: ::c_int = 2; +pub const THREAD_PRECEDENCE_POLICY: ::c_int = 3; +pub const THREAD_AFFINITY_POLICY: ::c_int = 4; +pub const THREAD_AFFINITY_TAG_NULL: ::c_int = 0; +pub const THREAD_BACKGROUND_POLICY: ::c_int = 5; +pub const THREAD_BACKGROUND_POLICY_DARWIN_BG: ::c_int = 0x1000; +pub const THREAD_LATENCY_QOS_POLICY: ::c_int = 7; +pub const THREAD_THROUGHPUT_QOS_POLICY: ::c_int = 8; + cfg_if! { if #[cfg(libc_const_extern_fn)] { const fn __DARWIN_ALIGN32(p: usize) -> usize { @@ -3391,11 +3515,39 @@ cfg_if! { const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1; p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 } + pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t = + (::mem::size_of::<thread_extended_policy_data_t>() / ::mem::size_of::<integer_t>()) + as mach_msg_type_number_t; + pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t = + (::mem::size_of::<thread_time_constraint_policy_data_t>() / + ::mem::size_of::<integer_t>()) as mach_msg_type_number_t; + pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t = + (::mem::size_of::<thread_precedence_policy_data_t>() / ::mem::size_of::<integer_t>()) + as mach_msg_type_number_t; + pub const THREAD_AFFINITY_POLICY_COUNT: mach_msg_type_number_t = + (::mem::size_of::<thread_affinity_policy_data_t>() / ::mem::size_of::<integer_t>()) + as mach_msg_type_number_t; + pub const THREAD_BACKGROUND_POLICY_COUNT: mach_msg_type_number_t = + (::mem::size_of::<thread_background_policy_data_t>() / ::mem::size_of::<integer_t>()) + as mach_msg_type_number_t; + pub const THREAD_LATENCY_QOS_POLICY_COUNT: mach_msg_type_number_t = + (::mem::size_of::<thread_latency_qos_policy_data_t>() / ::mem::size_of::<integer_t>()) + as mach_msg_type_number_t; + pub const THREAD_THROUGHPUT_QOS_POLICY_COUNT: mach_msg_type_number_t = + (::mem::size_of::<thread_throughput_qos_policy_data_t>() / + ::mem::size_of::<integer_t>()) as mach_msg_type_number_t; } else { fn __DARWIN_ALIGN32(p: usize) -> usize { let __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1; p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 } + pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t = 1; + pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t = 4; + pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t = 1; + pub const THREAD_AFFINITY_POLICY_COUNT: mach_msg_type_number_t = 1; + pub const THREAD_BACKGROUND_POLICY_COUNT: mach_msg_type_number_t = 1; + pub const THREAD_LATENCY_QOS_POLICY_COUNT: mach_msg_type_number_t = 1; + pub const THREAD_THROUGHPUT_QOS_POLICY_COUNT: mach_msg_type_number_t = 1; } } @@ -3563,6 +3715,8 @@ extern "C" { #[deprecated(since = "0.2.55", note = "Use the mach crate")] #[allow(deprecated)] pub fn mach_timebase_info(info: *mut ::mach_timebase_info) -> ::c_int; + pub fn mach_host_self() -> mach_port_t; + pub fn mach_thread_self() -> mach_port_t; 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_from_mach_thread_np(port: ::mach_port_t) -> ::pthread_t; @@ -3603,6 +3757,19 @@ extern "C" { class: *mut qos_class_t, priority: *mut ::c_int, ) -> ::c_int; + pub fn thread_policy_set( + thread: thread_t, + flavor: thread_policy_flavor_t, + policy_info: thread_policy_t, + count: mach_msg_type_number_t, + ) -> kern_return_t; + pub fn thread_policy_get( + thread: thread_t, + flavor: thread_policy_flavor_t, + policy_info: thread_policy_t, + count: *mut mach_msg_type_number_t, + get_default: *mut boolean_t, + ) -> kern_return_t; pub fn __error() -> *mut ::c_int; pub fn backtrace(buf: *mut *mut ::c_void, sz: ::c_int) -> ::c_int; #[cfg_attr( |