Skip to content

macOS: add os_sync_wait_on_address and related definitions #3769

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 2 commits into from
Jul 13, 2024
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: 22 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,11 @@ fn test_apple(target: &str) {
"netinet/ip.h",
"netinet/tcp.h",
"netinet/udp.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 @@ -329,6 +332,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 @@ -347,6 +353,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 @@ -372,6 +385,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 @@ -1023,6 +1023,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 @@ -1031,6 +1032,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 @@ -2049,6 +2054,7 @@ open_memstream
open_wmemstream
openat
openpty
os_clockid_t
os_log_create
os_log_t
os_log_type_enabled
Expand All @@ -2058,6 +2064,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 @@ -121,6 +121,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 @@ -5441,6 +5446,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 @@ -5834,6 +5848,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
Loading