From 03e47e6e770504a75f776127c5c9c1b44b6833b2 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 3 May 2024 09:11:04 +0900 Subject: [PATCH] Revert "Support posix_spawn on Android" --- libc-test/build.rs | 36 ++-------- src/unix/linux_like/linux/mod.rs | 105 ++++++++++++++++++++++++++++ src/unix/linux_like/mod.rs | 116 ------------------------------- 3 files changed, 110 insertions(+), 147 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index ee211ebbf227f..2b15c958d2d51 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1613,7 +1613,6 @@ fn test_android(target: &str) { "sched.h", "semaphore.h", "signal.h", - "spawn.h", "stddef.h", "stdint.h", "stdio.h", @@ -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" @@ -2726,7 +2709,6 @@ fn test_emscripten(target: &str) { "semaphore.h", "shadow.h", "signal.h", - "spawn.h", "stddef.h", "stdint.h", "stdio.h", @@ -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+ @@ -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, } }); diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 99c06426771f1..dc0d3eaca5335 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -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, @@ -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; @@ -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; @@ -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, diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index e4740d76aeef6..749c8a16d0148 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -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 {} @@ -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::() - 1 & !(::mem::size_of::() - 1) @@ -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;