Skip to content

Commit 88088ec

Browse files
committed
Support posix_spawn on Android
Android exposes the same functions and constants as the other linux_like platforms, but its posix_spawnattr_t and posix_spawn_file_actions_t are opaque. See: https://github.com/aosp-mirror/platform_bionic/blob/2215ad406b253f12e270cdd0876e19e9df2aa6d4/libc/include/spawn.h Since the fields in the linux implementation are private, let's make it opaque on all linux_like platforms.
1 parent 7ab4d52 commit 88088ec

File tree

3 files changed

+126
-110
lines changed

3 files changed

+126
-110
lines changed

libc-test/build.rs

+31-5
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,7 @@ fn test_android(target: &str) {
16131613
"sched.h",
16141614
"semaphore.h",
16151615
"signal.h",
1616+
"spawn.h",
16161617
"stddef.h",
16171618
"stdint.h",
16181619
"stdio.h",
@@ -1979,14 +1980,30 @@ fn test_android(target: &str) {
19791980

19801981
// Added in API level 28, but some tests use level 24.
19811982
"getrandom" => true,
1982-
1983-
// Added in API level 28, but some tests use level 24.
19841983
"syncfs" => true,
1985-
1986-
// Added in API level 28, but some tests use level 24.
19871984
"pthread_attr_getinheritsched" | "pthread_attr_setinheritsched" => true,
1988-
// Added in API level 28, but some tests use level 24.
19891985
"fread_unlocked" | "fwrite_unlocked" | "fgets_unlocked" | "fflush_unlocked" => true,
1986+
"posix_spawn"
1987+
| "posix_spawnp"
1988+
| "posix_spawnattr_init"
1989+
| "posix_spawnattr_destroy"
1990+
| "posix_spawnattr_getsigdefault"
1991+
| "posix_spawnattr_setsigdefault"
1992+
| "posix_spawnattr_getsigmask"
1993+
| "posix_spawnattr_setsigmask"
1994+
| "posix_spawnattr_getflags"
1995+
| "posix_spawnattr_setflags"
1996+
| "posix_spawnattr_getpgroup"
1997+
| "posix_spawnattr_setpgroup"
1998+
| "posix_spawnattr_getschedpolicy"
1999+
| "posix_spawnattr_setschedpolicy"
2000+
| "posix_spawnattr_getschedparam"
2001+
| "posix_spawnattr_setschedparam"
2002+
| "posix_spawn_file_actions_init"
2003+
| "posix_spawn_file_actions_destroy"
2004+
| "posix_spawn_file_actions_addopen"
2005+
| "posix_spawn_file_actions_addclose"
2006+
| "posix_spawn_file_actions_adddup2" => true,
19902007

19912008
// FIXME: bad function pointers:
19922009
"isalnum" | "isalpha" | "iscntrl" | "isdigit" | "isgraph" | "islower" | "isprint"
@@ -2706,6 +2723,7 @@ fn test_emscripten(target: &str) {
27062723
"semaphore.h",
27072724
"shadow.h",
27082725
"signal.h",
2726+
"spawn.h",
27092727
"stddef.h",
27102728
"stdint.h",
27112729
"stdio.h",
@@ -3597,6 +3615,10 @@ fn test_linux(target: &str) {
35973615
"priority_t" if musl => true,
35983616
"name_t" if musl => true,
35993617

3618+
// These are intended to be opaque, but glibc and musl define them.
3619+
"posix_spawn_file_actions_t" => true,
3620+
"posix_spawnattr_t" => true,
3621+
36003622
t => {
36013623
if musl {
36023624
// LFS64 types have been removed in musl 1.2.4+
@@ -3745,6 +3767,10 @@ fn test_linux(target: &str) {
37453767
// kernel so we can drop this and test the type once this new version is used in CI.
37463768
"sched_attr" => true,
37473769

3770+
// These are intended to be opaque, but glibc and musl define them.
3771+
"posix_spawn_file_actions_t" => true,
3772+
"posix_spawnattr_t" => true,
3773+
37483774
_ => false,
37493775
}
37503776
});

src/unix/linux_like/linux/mod.rs

-105
Original file line numberDiff line numberDiff line change
@@ -452,26 +452,6 @@ s! {
452452
pub mnt_passno: ::c_int,
453453
}
454454

455-
pub struct posix_spawn_file_actions_t {
456-
__allocated: ::c_int,
457-
__used: ::c_int,
458-
__actions: *mut ::c_int,
459-
__pad: [::c_int; 16],
460-
}
461-
462-
pub struct posix_spawnattr_t {
463-
__flags: ::c_short,
464-
__pgrp: ::pid_t,
465-
__sd: ::sigset_t,
466-
__ss: ::sigset_t,
467-
#[cfg(any(target_env = "musl", target_env = "ohos"))]
468-
__prio: ::c_int,
469-
#[cfg(not(any(target_env = "musl", target_env = "ohos")))]
470-
__sp: ::sched_param,
471-
__policy: ::c_int,
472-
__pad: [::c_int; 16],
473-
}
474-
475455
pub struct genlmsghdr {
476456
pub cmd: u8,
477457
pub version: u8,
@@ -1858,8 +1838,6 @@ pub const POSIX_MADV_NORMAL: ::c_int = 0;
18581838
pub const POSIX_MADV_RANDOM: ::c_int = 1;
18591839
pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2;
18601840
pub const POSIX_MADV_WILLNEED: ::c_int = 3;
1861-
pub const POSIX_SPAWN_USEVFORK: ::c_int = 64;
1862-
pub const POSIX_SPAWN_SETSID: ::c_int = 128;
18631841

18641842
pub const S_IEXEC: mode_t = 64;
18651843
pub const S_IWRITE: mode_t = 128;
@@ -2617,13 +2595,6 @@ pub const ETH_P_PHONET: ::c_int = 0x00F5;
26172595
pub const ETH_P_IEEE802154: ::c_int = 0x00F6;
26182596
pub const ETH_P_CAIF: ::c_int = 0x00F7;
26192597

2620-
pub const POSIX_SPAWN_RESETIDS: ::c_int = 0x01;
2621-
pub const POSIX_SPAWN_SETPGROUP: ::c_int = 0x02;
2622-
pub const POSIX_SPAWN_SETSIGDEF: ::c_int = 0x04;
2623-
pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x08;
2624-
pub const POSIX_SPAWN_SETSCHEDPARAM: ::c_int = 0x10;
2625-
pub const POSIX_SPAWN_SETSCHEDULER: ::c_int = 0x20;
2626-
26272598
pub const NLMSG_NOOP: ::c_int = 0x1;
26282599
pub const NLMSG_ERROR: ::c_int = 0x2;
26292600
pub const NLMSG_DONE: ::c_int = 0x3;
@@ -5453,82 +5424,6 @@ extern "C" {
54535424
pub fn endmntent(streamp: *mut ::FILE) -> ::c_int;
54545425
pub fn hasmntopt(mnt: *const ::mntent, opt: *const ::c_char) -> *mut ::c_char;
54555426

5456-
pub fn posix_spawn(
5457-
pid: *mut ::pid_t,
5458-
path: *const ::c_char,
5459-
file_actions: *const ::posix_spawn_file_actions_t,
5460-
attrp: *const ::posix_spawnattr_t,
5461-
argv: *const *mut ::c_char,
5462-
envp: *const *mut ::c_char,
5463-
) -> ::c_int;
5464-
pub fn posix_spawnp(
5465-
pid: *mut ::pid_t,
5466-
file: *const ::c_char,
5467-
file_actions: *const ::posix_spawn_file_actions_t,
5468-
attrp: *const ::posix_spawnattr_t,
5469-
argv: *const *mut ::c_char,
5470-
envp: *const *mut ::c_char,
5471-
) -> ::c_int;
5472-
pub fn posix_spawnattr_init(attr: *mut posix_spawnattr_t) -> ::c_int;
5473-
pub fn posix_spawnattr_destroy(attr: *mut posix_spawnattr_t) -> ::c_int;
5474-
pub fn posix_spawnattr_getsigdefault(
5475-
attr: *const posix_spawnattr_t,
5476-
default: *mut ::sigset_t,
5477-
) -> ::c_int;
5478-
pub fn posix_spawnattr_setsigdefault(
5479-
attr: *mut posix_spawnattr_t,
5480-
default: *const ::sigset_t,
5481-
) -> ::c_int;
5482-
pub fn posix_spawnattr_getsigmask(
5483-
attr: *const posix_spawnattr_t,
5484-
default: *mut ::sigset_t,
5485-
) -> ::c_int;
5486-
pub fn posix_spawnattr_setsigmask(
5487-
attr: *mut posix_spawnattr_t,
5488-
default: *const ::sigset_t,
5489-
) -> ::c_int;
5490-
pub fn posix_spawnattr_getflags(
5491-
attr: *const posix_spawnattr_t,
5492-
flags: *mut ::c_short,
5493-
) -> ::c_int;
5494-
pub fn posix_spawnattr_setflags(attr: *mut posix_spawnattr_t, flags: ::c_short) -> ::c_int;
5495-
pub fn posix_spawnattr_getpgroup(
5496-
attr: *const posix_spawnattr_t,
5497-
flags: *mut ::pid_t,
5498-
) -> ::c_int;
5499-
pub fn posix_spawnattr_setpgroup(attr: *mut posix_spawnattr_t, flags: ::pid_t) -> ::c_int;
5500-
pub fn posix_spawnattr_getschedpolicy(
5501-
attr: *const posix_spawnattr_t,
5502-
flags: *mut ::c_int,
5503-
) -> ::c_int;
5504-
pub fn posix_spawnattr_setschedpolicy(attr: *mut posix_spawnattr_t, flags: ::c_int) -> ::c_int;
5505-
pub fn posix_spawnattr_getschedparam(
5506-
attr: *const posix_spawnattr_t,
5507-
param: *mut ::sched_param,
5508-
) -> ::c_int;
5509-
pub fn posix_spawnattr_setschedparam(
5510-
attr: *mut posix_spawnattr_t,
5511-
param: *const ::sched_param,
5512-
) -> ::c_int;
5513-
5514-
pub fn posix_spawn_file_actions_init(actions: *mut posix_spawn_file_actions_t) -> ::c_int;
5515-
pub fn posix_spawn_file_actions_destroy(actions: *mut posix_spawn_file_actions_t) -> ::c_int;
5516-
pub fn posix_spawn_file_actions_addopen(
5517-
actions: *mut posix_spawn_file_actions_t,
5518-
fd: ::c_int,
5519-
path: *const ::c_char,
5520-
oflag: ::c_int,
5521-
mode: ::mode_t,
5522-
) -> ::c_int;
5523-
pub fn posix_spawn_file_actions_addclose(
5524-
actions: *mut posix_spawn_file_actions_t,
5525-
fd: ::c_int,
5526-
) -> ::c_int;
5527-
pub fn posix_spawn_file_actions_adddup2(
5528-
actions: *mut posix_spawn_file_actions_t,
5529-
fd: ::c_int,
5530-
newfd: ::c_int,
5531-
) -> ::c_int;
55325427
pub fn fread_unlocked(
55335428
buf: *mut ::c_void,
55345429
size: ::size_t,

src/unix/linux_like/mod.rs

+95
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,101 @@ cfg_if! {
18801880
}
18811881
}
18821882

1883+
cfg_if! {
1884+
if #[cfg(not(target_os = "emscripten"))] {
1885+
pub type posix_spawn_file_actions_t = *mut ::c_void;
1886+
pub type posix_spawnattr_t = *mut ::c_void;
1887+
1888+
pub const POSIX_SPAWN_RESETIDS: ::c_int = 0x01;
1889+
pub const POSIX_SPAWN_SETPGROUP: ::c_int = 0x02;
1890+
pub const POSIX_SPAWN_SETSIGDEF: ::c_int = 0x04;
1891+
pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x08;
1892+
pub const POSIX_SPAWN_SETSCHEDPARAM: ::c_int = 0x10;
1893+
pub const POSIX_SPAWN_SETSCHEDULER: ::c_int = 0x20;
1894+
pub const POSIX_SPAWN_USEVFORK: ::c_int = 0x40;
1895+
pub const POSIX_SPAWN_SETSID: ::c_int = 0x80;
1896+
1897+
extern "C" {
1898+
pub fn posix_spawn(
1899+
pid: *mut ::pid_t,
1900+
path: *const ::c_char,
1901+
file_actions: *const ::posix_spawn_file_actions_t,
1902+
attrp: *const ::posix_spawnattr_t,
1903+
argv: *const *mut ::c_char,
1904+
envp: *const *mut ::c_char,
1905+
) -> ::c_int;
1906+
pub fn posix_spawnp(
1907+
pid: *mut ::pid_t,
1908+
file: *const ::c_char,
1909+
file_actions: *const ::posix_spawn_file_actions_t,
1910+
attrp: *const ::posix_spawnattr_t,
1911+
argv: *const *mut ::c_char,
1912+
envp: *const *mut ::c_char,
1913+
) -> ::c_int;
1914+
pub fn posix_spawnattr_init(attr: *mut posix_spawnattr_t) -> ::c_int;
1915+
pub fn posix_spawnattr_destroy(attr: *mut posix_spawnattr_t) -> ::c_int;
1916+
pub fn posix_spawnattr_getsigdefault(
1917+
attr: *const posix_spawnattr_t,
1918+
default: *mut ::sigset_t,
1919+
) -> ::c_int;
1920+
pub fn posix_spawnattr_setsigdefault(
1921+
attr: *mut posix_spawnattr_t,
1922+
default: *const ::sigset_t,
1923+
) -> ::c_int;
1924+
pub fn posix_spawnattr_getsigmask(
1925+
attr: *const posix_spawnattr_t,
1926+
default: *mut ::sigset_t,
1927+
) -> ::c_int;
1928+
pub fn posix_spawnattr_setsigmask(
1929+
attr: *mut posix_spawnattr_t,
1930+
default: *const ::sigset_t,
1931+
) -> ::c_int;
1932+
pub fn posix_spawnattr_getflags(
1933+
attr: *const posix_spawnattr_t,
1934+
flags: *mut ::c_short,
1935+
) -> ::c_int;
1936+
pub fn posix_spawnattr_setflags(attr: *mut posix_spawnattr_t, flags: ::c_short) -> ::c_int;
1937+
pub fn posix_spawnattr_getpgroup(
1938+
attr: *const posix_spawnattr_t,
1939+
flags: *mut ::pid_t,
1940+
) -> ::c_int;
1941+
pub fn posix_spawnattr_setpgroup(attr: *mut posix_spawnattr_t, flags: ::pid_t) -> ::c_int;
1942+
pub fn posix_spawnattr_getschedpolicy(
1943+
attr: *const posix_spawnattr_t,
1944+
flags: *mut ::c_int,
1945+
) -> ::c_int;
1946+
pub fn posix_spawnattr_setschedpolicy(attr: *mut posix_spawnattr_t, flags: ::c_int) -> ::c_int;
1947+
pub fn posix_spawnattr_getschedparam(
1948+
attr: *const posix_spawnattr_t,
1949+
param: *mut ::sched_param,
1950+
) -> ::c_int;
1951+
pub fn posix_spawnattr_setschedparam(
1952+
attr: *mut posix_spawnattr_t,
1953+
param: *const ::sched_param,
1954+
) -> ::c_int;
1955+
1956+
pub fn posix_spawn_file_actions_init(actions: *mut posix_spawn_file_actions_t) -> ::c_int;
1957+
pub fn posix_spawn_file_actions_destroy(actions: *mut posix_spawn_file_actions_t) -> ::c_int;
1958+
pub fn posix_spawn_file_actions_addopen(
1959+
actions: *mut posix_spawn_file_actions_t,
1960+
fd: ::c_int,
1961+
path: *const ::c_char,
1962+
oflag: ::c_int,
1963+
mode: ::mode_t,
1964+
) -> ::c_int;
1965+
pub fn posix_spawn_file_actions_addclose(
1966+
actions: *mut posix_spawn_file_actions_t,
1967+
fd: ::c_int,
1968+
) -> ::c_int;
1969+
pub fn posix_spawn_file_actions_adddup2(
1970+
actions: *mut posix_spawn_file_actions_t,
1971+
fd: ::c_int,
1972+
newfd: ::c_int,
1973+
) -> ::c_int;
1974+
}
1975+
}
1976+
}
1977+
18831978
cfg_if! {
18841979
if #[cfg(target_os = "emscripten")] {
18851980
mod emscripten;

0 commit comments

Comments
 (0)