Skip to content

Commit

Permalink
Merge pull request #3678 from rust-lang/revert-3602-posix_spawn
Browse files Browse the repository at this point in the history
Revert "Support posix_spawn on Android"
  • Loading branch information
JohnTitor authored May 3, 2024
2 parents 73efe14 + 03e47e6 commit 2918100
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 147 deletions.
36 changes: 5 additions & 31 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,6 @@ fn test_android(target: &str) {
"sched.h",
"semaphore.h",
"signal.h",
"spawn.h",
"stddef.h",
"stdint.h",
"stdio.h",
Expand Down Expand Up @@ -1980,30 +1979,14 @@ fn test_android(target: &str) {

// Added in API level 28, but some tests use level 24.
"getrandom" => true,

// Added in API level 28, but some tests use level 24.
"syncfs" => true,

// Added in API level 28, but some tests use level 24.
"pthread_attr_getinheritsched" | "pthread_attr_setinheritsched" => true,
// Added in API level 28, but some tests use level 24.
"fread_unlocked" | "fwrite_unlocked" | "fgets_unlocked" | "fflush_unlocked" => true,
"posix_spawn"
| "posix_spawnp"
| "posix_spawnattr_init"
| "posix_spawnattr_destroy"
| "posix_spawnattr_getsigdefault"
| "posix_spawnattr_setsigdefault"
| "posix_spawnattr_getsigmask"
| "posix_spawnattr_setsigmask"
| "posix_spawnattr_getflags"
| "posix_spawnattr_setflags"
| "posix_spawnattr_getpgroup"
| "posix_spawnattr_setpgroup"
| "posix_spawnattr_getschedpolicy"
| "posix_spawnattr_setschedpolicy"
| "posix_spawnattr_getschedparam"
| "posix_spawnattr_setschedparam"
| "posix_spawn_file_actions_init"
| "posix_spawn_file_actions_destroy"
| "posix_spawn_file_actions_addopen"
| "posix_spawn_file_actions_addclose"
| "posix_spawn_file_actions_adddup2" => true,

// FIXME: bad function pointers:
"isalnum" | "isalpha" | "iscntrl" | "isdigit" | "isgraph" | "islower" | "isprint"
Expand Down Expand Up @@ -2726,7 +2709,6 @@ fn test_emscripten(target: &str) {
"semaphore.h",
"shadow.h",
"signal.h",
"spawn.h",
"stddef.h",
"stdint.h",
"stdio.h",
Expand Down Expand Up @@ -3620,10 +3602,6 @@ fn test_linux(target: &str) {
"priority_t" if musl => true,
"name_t" if musl => true,

// These are intended to be opaque, but glibc and musl define them.
"posix_spawn_file_actions_t" => true,
"posix_spawnattr_t" => true,

t => {
if musl {
// LFS64 types have been removed in musl 1.2.4+
Expand Down Expand Up @@ -3772,10 +3750,6 @@ fn test_linux(target: &str) {
// kernel so we can drop this and test the type once this new version is used in CI.
"sched_attr" => true,

// These are intended to be opaque, but glibc and musl define them.
"posix_spawn_file_actions_t" => true,
"posix_spawnattr_t" => true,

_ => false,
}
});
Expand Down
105 changes: 105 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,26 @@ s! {
pub mnt_passno: ::c_int,
}

pub struct posix_spawn_file_actions_t {
__allocated: ::c_int,
__used: ::c_int,
__actions: *mut ::c_int,
__pad: [::c_int; 16],
}

pub struct posix_spawnattr_t {
__flags: ::c_short,
__pgrp: ::pid_t,
__sd: ::sigset_t,
__ss: ::sigset_t,
#[cfg(any(target_env = "musl", target_env = "ohos"))]
__prio: ::c_int,
#[cfg(not(any(target_env = "musl", target_env = "ohos")))]
__sp: ::sched_param,
__policy: ::c_int,
__pad: [::c_int; 16],
}

pub struct genlmsghdr {
pub cmd: u8,
pub version: u8,
Expand Down Expand Up @@ -1839,6 +1859,8 @@ pub const POSIX_MADV_NORMAL: ::c_int = 0;
pub const POSIX_MADV_RANDOM: ::c_int = 1;
pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2;
pub const POSIX_MADV_WILLNEED: ::c_int = 3;
pub const POSIX_SPAWN_USEVFORK: ::c_int = 64;
pub const POSIX_SPAWN_SETSID: ::c_int = 128;

pub const S_IEXEC: mode_t = 64;
pub const S_IWRITE: mode_t = 128;
Expand Down Expand Up @@ -2596,6 +2618,13 @@ pub const ETH_P_PHONET: ::c_int = 0x00F5;
pub const ETH_P_IEEE802154: ::c_int = 0x00F6;
pub const ETH_P_CAIF: ::c_int = 0x00F7;

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_SETSCHEDPARAM: ::c_int = 0x10;
pub const POSIX_SPAWN_SETSCHEDULER: ::c_int = 0x20;

pub const NLMSG_NOOP: ::c_int = 0x1;
pub const NLMSG_ERROR: ::c_int = 0x2;
pub const NLMSG_DONE: ::c_int = 0x3;
Expand Down Expand Up @@ -5425,6 +5454,82 @@ extern "C" {
pub fn endmntent(streamp: *mut ::FILE) -> ::c_int;
pub fn hasmntopt(mnt: *const ::mntent, opt: *const ::c_char) -> *mut ::c_char;

pub fn posix_spawn(
pid: *mut ::pid_t,
path: *const ::c_char,
file_actions: *const ::posix_spawn_file_actions_t,
attrp: *const ::posix_spawnattr_t,
argv: *const *mut ::c_char,
envp: *const *mut ::c_char,
) -> ::c_int;
pub fn posix_spawnp(
pid: *mut ::pid_t,
file: *const ::c_char,
file_actions: *const ::posix_spawn_file_actions_t,
attrp: *const ::posix_spawnattr_t,
argv: *const *mut ::c_char,
envp: *const *mut ::c_char,
) -> ::c_int;
pub fn posix_spawnattr_init(attr: *mut posix_spawnattr_t) -> ::c_int;
pub fn posix_spawnattr_destroy(attr: *mut posix_spawnattr_t) -> ::c_int;
pub fn posix_spawnattr_getsigdefault(
attr: *const posix_spawnattr_t,
default: *mut ::sigset_t,
) -> ::c_int;
pub fn posix_spawnattr_setsigdefault(
attr: *mut posix_spawnattr_t,
default: *const ::sigset_t,
) -> ::c_int;
pub fn posix_spawnattr_getsigmask(
attr: *const posix_spawnattr_t,
default: *mut ::sigset_t,
) -> ::c_int;
pub fn posix_spawnattr_setsigmask(
attr: *mut posix_spawnattr_t,
default: *const ::sigset_t,
) -> ::c_int;
pub fn posix_spawnattr_getflags(
attr: *const posix_spawnattr_t,
flags: *mut ::c_short,
) -> ::c_int;
pub fn posix_spawnattr_setflags(attr: *mut posix_spawnattr_t, flags: ::c_short) -> ::c_int;
pub fn posix_spawnattr_getpgroup(
attr: *const posix_spawnattr_t,
flags: *mut ::pid_t,
) -> ::c_int;
pub fn posix_spawnattr_setpgroup(attr: *mut posix_spawnattr_t, flags: ::pid_t) -> ::c_int;
pub fn posix_spawnattr_getschedpolicy(
attr: *const posix_spawnattr_t,
flags: *mut ::c_int,
) -> ::c_int;
pub fn posix_spawnattr_setschedpolicy(attr: *mut posix_spawnattr_t, flags: ::c_int) -> ::c_int;
pub fn posix_spawnattr_getschedparam(
attr: *const posix_spawnattr_t,
param: *mut ::sched_param,
) -> ::c_int;
pub fn posix_spawnattr_setschedparam(
attr: *mut posix_spawnattr_t,
param: *const ::sched_param,
) -> ::c_int;

pub fn posix_spawn_file_actions_init(actions: *mut posix_spawn_file_actions_t) -> ::c_int;
pub fn posix_spawn_file_actions_destroy(actions: *mut posix_spawn_file_actions_t) -> ::c_int;
pub fn posix_spawn_file_actions_addopen(
actions: *mut posix_spawn_file_actions_t,
fd: ::c_int,
path: *const ::c_char,
oflag: ::c_int,
mode: ::mode_t,
) -> ::c_int;
pub fn posix_spawn_file_actions_addclose(
actions: *mut posix_spawn_file_actions_t,
fd: ::c_int,
) -> ::c_int;
pub fn posix_spawn_file_actions_adddup2(
actions: *mut posix_spawn_file_actions_t,
fd: ::c_int,
newfd: ::c_int,
) -> ::c_int;
pub fn fread_unlocked(
buf: *mut ::c_void,
size: ::size_t,
Expand Down
116 changes: 0 additions & 116 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ pub type timer_t = *mut ::c_void;
pub type key_t = ::c_int;
pub type id_t = ::c_uint;

cfg_if! {
if #[cfg(not(target_os = "emscripten"))] {
pub type posix_spawn_file_actions_t = *mut ::c_void;
pub type posix_spawnattr_t = *mut ::c_void;
}
}

missing! {
#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum timezone {}
Expand Down Expand Up @@ -1538,19 +1531,6 @@ cfg_if! {
}
}

cfg_if! {
if #[cfg(not(target_os = "emscripten"))] {
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_SETSCHEDPARAM: ::c_int = 0x10;
pub const POSIX_SPAWN_SETSCHEDULER: ::c_int = 0x20;
pub const POSIX_SPAWN_USEVFORK: ::c_int = 0x40;
pub const POSIX_SPAWN_SETSID: ::c_int = 0x80;
}
}

const_fn! {
{const} fn CMSG_ALIGN(len: usize) -> usize {
len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1)
Expand Down Expand Up @@ -1915,102 +1895,6 @@ cfg_if! {
}
}

cfg_if! {
if #[cfg(not(target_os = "emscripten"))] {
extern "C" {
pub fn posix_spawn(
pid: *mut ::pid_t,
path: *const ::c_char,
file_actions: *const ::posix_spawn_file_actions_t,
attrp: *const ::posix_spawnattr_t,
argv: *const *mut ::c_char,
envp: *const *mut ::c_char,
) -> ::c_int;
pub fn posix_spawnp(
pid: *mut ::pid_t,
file: *const ::c_char,
file_actions: *const ::posix_spawn_file_actions_t,
attrp: *const ::posix_spawnattr_t,
argv: *const *mut ::c_char,
envp: *const *mut ::c_char,
) -> ::c_int;
pub fn posix_spawnattr_init(attr: *mut posix_spawnattr_t) -> ::c_int;
pub fn posix_spawnattr_destroy(attr: *mut posix_spawnattr_t) -> ::c_int;
pub fn posix_spawnattr_getsigdefault(
attr: *const posix_spawnattr_t,
default: *mut ::sigset_t,
) -> ::c_int;
pub fn posix_spawnattr_setsigdefault(
attr: *mut posix_spawnattr_t,
default: *const ::sigset_t,
) -> ::c_int;
pub fn posix_spawnattr_getsigmask(
attr: *const posix_spawnattr_t,
default: *mut ::sigset_t,
) -> ::c_int;
pub fn posix_spawnattr_setsigmask(
attr: *mut posix_spawnattr_t,
default: *const ::sigset_t,
) -> ::c_int;
pub fn posix_spawnattr_getflags(
attr: *const posix_spawnattr_t,
flags: *mut ::c_short,
) -> ::c_int;
pub fn posix_spawnattr_setflags(
attr: *mut posix_spawnattr_t,
flags: ::c_short,
) -> ::c_int;
pub fn posix_spawnattr_getpgroup(
attr: *const posix_spawnattr_t,
flags: *mut ::pid_t,
) -> ::c_int;
pub fn posix_spawnattr_setpgroup(
attr: *mut posix_spawnattr_t,
flags: ::pid_t,
) -> ::c_int;
pub fn posix_spawnattr_getschedpolicy(
attr: *const posix_spawnattr_t,
flags: *mut ::c_int,
) -> ::c_int;
pub fn posix_spawnattr_setschedpolicy(
attr: *mut posix_spawnattr_t,
flags: ::c_int,
) -> ::c_int;
pub fn posix_spawnattr_getschedparam(
attr: *const posix_spawnattr_t,
param: *mut ::sched_param,
) -> ::c_int;
pub fn posix_spawnattr_setschedparam(
attr: *mut posix_spawnattr_t,
param: *const ::sched_param,
) -> ::c_int;

pub fn posix_spawn_file_actions_init(
actions: *mut posix_spawn_file_actions_t,
) -> ::c_int;
pub fn posix_spawn_file_actions_destroy(
actions: *mut posix_spawn_file_actions_t,
) -> ::c_int;
pub fn posix_spawn_file_actions_addopen(
actions: *mut posix_spawn_file_actions_t,
fd: ::c_int,
path: *const ::c_char,
oflag: ::c_int,
mode: ::mode_t,
) -> ::c_int;
pub fn posix_spawn_file_actions_addclose(
actions: *mut posix_spawn_file_actions_t,
fd: ::c_int,
) -> ::c_int;
pub fn posix_spawn_file_actions_adddup2(
actions: *mut posix_spawn_file_actions_t,
fd: ::c_int,
newfd: ::c_int,
) -> ::c_int;
}
}
}

cfg_if! {
if #[cfg(target_os = "emscripten")] {
mod emscripten;
Expand Down

0 comments on commit 2918100

Please sign in to comment.