Skip to content

Commit

Permalink
Auto merge of #3328 - vincentisambart:apple-additional-decls, r=JohnT…
Browse files Browse the repository at this point in the history
…itor

Add a few declarations for Apple systems

I added the following definitions for Apple systems:

<del>

- `_POSIX_SPAWN_DISABLE_ASLR`
  - It is a private flag for `posix_spawnattr_setflags` that disables [ASLR](https://en.wikipedia.org/wiki/Address_space_layout_randomization) for the child process.
  - It is mainly used by debuggers. Its declaration in LLDB's source code:
https://github.com/llvm/llvm-project/blob/2051a4121957a4bfc015b5102d06ffd6d0852d33/lldb/tools/debugserver/source/MacOSX/MachProcess.mm#L507-L509
- `pthread_chdir_np` and `pthread_fchdir_np`
  - Private functions that change the working directory only for the current thread.
  - They are declared and documented in Apple's libpthread:
https://github.com/apple-oss-distributions/libpthread/blob/67e155c94093be9a204b69637d198eceff2c7c46/private/pthread/private.h#L44-L89
  - They are for example used by Chromium in [this file](https://chromium.googlesource.com/chromium/src/base/+/master/process/launch_mac.cc).
  - LLDB also uses the [equivalent](https://github.com/apple-oss-distributions/libpthread/blob/main/src/pthread_cwd.c) `__pthread_chdir` and `__pthread_fchdir` in [this file](https://github.com/llvm/llvm-project/blob/main/lldb/source/Host/macosx/objcxx/Host.mm).

</del>

- `posix_spawnattr_getbinpref_np` and `posix_spawnattr_setbinpref_np`
  - These methods are public and declared in `/usr/include/spawn.h`.
  - They are pretty close to the already present `posix_spawnattr_getarchpref_np` and `posix_spawnattr_setarchpref_np`, but you can see that in [this file](https://github.com/llvm/llvm-project/blob/main/lldb/source/Host/macosx/objcxx/Host.mm) LLDB does use both `binpref` and `archpref`.
  • Loading branch information
bors committed Nov 1, 2023
2 parents a104192 + c861aca commit f367fa2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,8 @@ posix_spawnattr_setflags
posix_spawnattr_setpgroup
posix_spawnattr_setsigdefault
posix_spawnattr_setsigmask
posix_spawnattr_getbinpref_np
posix_spawnattr_setbinpref_np
posix_spawnattr_t
posix_spawnp
preadv
Expand Down
24 changes: 18 additions & 6 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4998,12 +4998,12 @@ pub const MNT_SNAPSHOT: ::c_int = 0x40000000;
pub const MNT_NOBLOCK: ::c_int = 0x00020000;

// sys/spawn.h:
pub const POSIX_SPAWN_RESETIDS: ::c_int = 0x01;
pub const POSIX_SPAWN_SETPGROUP: ::c_int = 0x02;
pub const POSIX_SPAWN_SETSIGDEF: ::c_int = 0x04;
pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x08;
pub const POSIX_SPAWN_SETEXEC: ::c_int = 0x40;
pub const POSIX_SPAWN_START_SUSPENDED: ::c_int = 0x80;
pub const POSIX_SPAWN_RESETIDS: ::c_int = 0x0001;
pub const POSIX_SPAWN_SETPGROUP: ::c_int = 0x0002;
pub const POSIX_SPAWN_SETSIGDEF: ::c_int = 0x0004;
pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x0008;
pub const POSIX_SPAWN_SETEXEC: ::c_int = 0x0040;
pub const POSIX_SPAWN_START_SUSPENDED: ::c_int = 0x0080;
pub const POSIX_SPAWN_CLOEXEC_DEFAULT: ::c_int = 0x4000;

// sys/ipc.h:
Expand Down Expand Up @@ -6058,6 +6058,18 @@ extern "C" {
subpref: *mut ::cpu_subtype_t,
ocount: *mut ::size_t,
) -> ::c_int;
pub fn posix_spawnattr_getbinpref_np(
attr: *const posix_spawnattr_t,
count: ::size_t,
pref: *mut ::cpu_type_t,
ocount: *mut ::size_t,
) -> ::c_int;
pub fn posix_spawnattr_setbinpref_np(
attr: *mut posix_spawnattr_t,
count: ::size_t,
pref: *mut ::cpu_type_t,
ocount: *mut ::size_t,
) -> ::c_int;
pub fn posix_spawnattr_set_qos_class_np(
attr: *mut posix_spawnattr_t,
qos_class: ::qos_class_t,
Expand Down

0 comments on commit f367fa2

Please sign in to comment.