Skip to content

Commit

Permalink
Merge pull request #3886 from tgross35/main-macos-sync-woa
Browse files Browse the repository at this point in the history
[main]  macOS: add `os_sync_wait_on_address` and related definitions
  • Loading branch information
tgross35 authored Aug 29, 2024
2 parents b4b5fbe + f0b2a0e commit 0f9b760
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@ fn test_apple(target: &str) {
"netinet/tcp.h",
"netinet/udp.h",
"netinet6/in6_var.h",
"os/clock.h",
"os/lock.h",
"os/signpost.h",
// FIXME: Requires the macOS 14.4 SDK.
//"os/os_sync_wait_on_address.h",
"poll.h",
"pthread.h",
"pthread_spis.h",
Expand Down Expand Up @@ -311,6 +314,9 @@ fn test_apple(target: &str) {
return true;
}
match ty {
// FIXME: Requires the macOS 14.4 SDK.
"os_sync_wake_by_address_flags_t" | "os_sync_wait_on_address_flags_t" => true,

_ => false,
}
});
Expand All @@ -325,6 +331,13 @@ fn test_apple(target: &str) {

// FIXME: XCode 13.1 doesn't have it.
"TIOCREMOTE" => true,

// FIXME: Requires the macOS 14.4 SDK.
"OS_SYNC_WAKE_BY_ADDRESS_NONE"
| "OS_SYNC_WAKE_BY_ADDRESS_SHARED"
| "OS_SYNC_WAIT_ON_ADDRESS_NONE"
| "OS_SYNC_WAIT_ON_ADDRESS_SHARED" => true,

_ => false,
}
});
Expand All @@ -347,6 +360,15 @@ fn test_apple(target: &str) {
// FIXME: Once the SDK get updated to Ventura's level
"freadlink" | "mknodat" | "mkfifoat" => true,

// FIXME: Requires the macOS 14.4 SDK.
"os_sync_wake_by_address_any"
| "os_sync_wake_by_address_all"
| "os_sync_wake_by_address_flags_t"
| "os_sync_wait_on_address"
| "os_sync_wait_on_address_flags_t"
| "os_sync_wait_on_address_with_deadline"
| "os_sync_wait_on_address_with_timeout" => true,

_ => false,
}
});
Expand Down
13 changes: 13 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ OFDEL
OFILL
OLD_TIME
ONOEOT
OS_CLOCK_MACH_ABSOLUTE_TIME
OS_LOG_TYPE_DEBUG
OS_LOG_TYPE_DEFAULT
OS_LOG_TYPE_ERROR
Expand All @@ -1034,6 +1035,10 @@ OS_LOG_TYPE_INFO
OS_SIGNPOST_EVENT
OS_SIGNPOST_INTERVAL_BEGIN
OS_SIGNPOST_INTERVAL_END
OS_SYNC_WAKE_BY_ADDRESS_NONE
OS_SYNC_WAKE_BY_ADDRESS_SHARED
OS_SYNC_WAIT_ON_ADDRESS_NONE
OS_SYNC_WAIT_ON_ADDRESS_SHARED
OS_UNFAIR_LOCK_INIT
OXTABS
O_ASYNC
Expand Down Expand Up @@ -1951,6 +1956,7 @@ open_memstream
open_wmemstream
openat
openpty
os_clockid_t
os_log_create
os_log_t
os_log_type_enabled
Expand All @@ -1960,6 +1966,13 @@ os_signpost_id_generate
os_signpost_id_make_with_pointer
os_signpost_id_t
os_signpost_type_t
os_sync_wake_by_address_any
os_sync_wake_by_address_all
os_sync_wake_by_address_flags_t
os_sync_wait_on_address
os_sync_wait_on_address_flags_t
os_sync_wait_on_address_with_deadline
os_sync_wait_on_address_with_timeout
os_unfair_lock
os_unfair_lock_assert_not_owner
os_unfair_lock_assert_owner
Expand Down
48 changes: 48 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ pub type pthread_introspection_hook_t =
extern "C" fn(event: ::c_uint, thread: ::pthread_t, addr: *mut ::c_void, size: ::size_t);
pub type pthread_jit_write_callback_t = ::Option<extern "C" fn(ctx: *mut ::c_void) -> ::c_int>;

pub type os_clockid_t = u32;

pub type os_sync_wait_on_address_flags_t = u32;
pub type os_sync_wake_by_address_flags_t = u32;

pub type os_unfair_lock = os_unfair_lock_s;
pub type os_unfair_lock_t = *mut os_unfair_lock;

Expand Down Expand Up @@ -5422,6 +5427,15 @@ pub const VOL_CAP_INT_RENAME_SWAP: attrgroup_t = 0x00040000;
pub const VOL_CAP_INT_RENAME_EXCL: attrgroup_t = 0x00080000;
pub const VOL_CAP_INT_RENAME_OPENFAIL: attrgroup_t = 0x00100000;

// os/clock.h
pub const OS_CLOCK_MACH_ABSOLUTE_TIME: os_clockid_t = 32;

// os/os_sync_wait_on_address.h
pub const OS_SYNC_WAIT_ON_ADDRESS_NONE: os_sync_wait_on_address_flags_t = 0x00000000;
pub const OS_SYNC_WAIT_ON_ADDRESS_SHARED: os_sync_wait_on_address_flags_t = 0x00000001;
pub const OS_SYNC_WAKE_BY_ADDRESS_NONE: os_sync_wake_by_address_flags_t = 0x00000000;
pub const OS_SYNC_WAKE_BY_ADDRESS_SHARED: os_sync_wake_by_address_flags_t = 0x00000001;

// <proc.h>
/// Process being created by fork.
pub const SIDL: u32 = 1;
Expand Down Expand Up @@ -5775,6 +5789,40 @@ extern "C" {
pub fn pthread_jit_write_freeze_callbacks_np();
pub fn pthread_cpu_number_np(cpu_number_out: *mut ::size_t) -> ::c_int;

// Available starting with macOS 14.4.
pub fn os_sync_wait_on_address(
addr: *mut ::c_void,
value: u64,
size: ::size_t,
flags: os_sync_wait_on_address_flags_t,
) -> ::c_int;
pub fn os_sync_wait_on_address_with_deadline(
addr: *mut ::c_void,
value: u64,
size: ::size_t,
flags: os_sync_wait_on_address_flags_t,
clockid: os_clockid_t,
deadline: u64,
) -> ::c_int;
pub fn os_sync_wait_on_address_with_timeout(
addr: *mut ::c_void,
value: u64,
size: ::size_t,
flags: os_sync_wait_on_address_flags_t,
clockid: os_clockid_t,
timeout_ns: u64,
) -> ::c_int;
pub fn os_sync_wake_by_address_any(
addr: *mut ::c_void,
size: ::size_t,
flags: os_sync_wake_by_address_flags_t,
) -> ::c_int;
pub fn os_sync_wake_by_address_all(
addr: *mut ::c_void,
size: ::size_t,
flags: os_sync_wake_by_address_flags_t,
) -> ::c_int;

pub fn os_unfair_lock_lock(lock: os_unfair_lock_t);
pub fn os_unfair_lock_trylock(lock: os_unfair_lock_t) -> bool;
pub fn os_unfair_lock_unlock(lock: os_unfair_lock_t);
Expand Down

0 comments on commit 0f9b760

Please sign in to comment.