From f7c7b949fda718d3811261fda003f2d9e3e2d9f4 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Fri, 29 Jan 2021 00:10:06 -0800 Subject: [PATCH] Explore comfort level with posix_spawn Justine says nay for the time being. Only XNU implements this. It's not clear what ABI XNU is using but it's obviously not the one in the POSIX documentation link below. Since all platforms implement vfork, it might be better to empirically gauge the intersection of consensus which will have better performance than this interface. https://pubs.opengroup.org/onlinepubs/009696699/xrat/xsh_chap03.html --- libc/calls/scheduler.h | 14 +++++++ libc/sysv/calls/posix_spawn-sysv.s | 2 + libc/sysv/calls/posix_spawn.s | 2 - libc/sysv/consts.sh | 12 ------ libc/sysv/consts/POSIX_SPAWN_RESETIDS.s | 2 - libc/sysv/consts/POSIX_SPAWN_SETPGROUP.s | 2 - libc/sysv/consts/POSIX_SPAWN_SETSCHEDPARAM.s | 2 - libc/sysv/consts/POSIX_SPAWN_SETSCHEDULER.s | 2 - libc/sysv/consts/POSIX_SPAWN_SETSIGDEF.s | 2 - libc/sysv/consts/POSIX_SPAWN_SETSIGMASK.s | 2 - libc/sysv/consts/POSIX_SPAWN_USEVFORK.s | 2 - libc/sysv/consts/posix.h | 40 +++++++------------- libc/sysv/syscalls.sh | 2 +- 13 files changed, 30 insertions(+), 56 deletions(-) create mode 100644 libc/calls/scheduler.h create mode 100644 libc/sysv/calls/posix_spawn-sysv.s delete mode 100644 libc/sysv/calls/posix_spawn.s delete mode 100644 libc/sysv/consts/POSIX_SPAWN_RESETIDS.s delete mode 100644 libc/sysv/consts/POSIX_SPAWN_SETPGROUP.s delete mode 100644 libc/sysv/consts/POSIX_SPAWN_SETSCHEDPARAM.s delete mode 100644 libc/sysv/consts/POSIX_SPAWN_SETSCHEDULER.s delete mode 100644 libc/sysv/consts/POSIX_SPAWN_SETSIGDEF.s delete mode 100644 libc/sysv/consts/POSIX_SPAWN_SETSIGMASK.s delete mode 100644 libc/sysv/consts/POSIX_SPAWN_USEVFORK.s diff --git a/libc/calls/scheduler.h b/libc/calls/scheduler.h new file mode 100644 index 00000000..079f33c5 --- /dev/null +++ b/libc/calls/scheduler.h @@ -0,0 +1,14 @@ +#ifndef COSMOPOLITAN_LIBC_CALLS_SCHED_H_ +#define COSMOPOLITAN_LIBC_CALLS_SCHED_H_ +#include "libc/calls/struct/sched_param.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int sched_setscheduler(int, int, const struct sched_param *); +int sched_getscheduler(int); +int sched_setparam(int, const struct sched_param *); +int sched_getparam(int, struct sched_param *); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_CALLS_SCHED_H_ */ diff --git a/libc/sysv/calls/posix_spawn-sysv.s b/libc/sysv/calls/posix_spawn-sysv.s new file mode 100644 index 00000000..8cb423ba --- /dev/null +++ b/libc/sysv/calls/posix_spawn-sysv.s @@ -0,0 +1,2 @@ +.include "o/libc/sysv/macros.internal.inc" +.scall posix_spawn$sysv 0xffffffff20f4ffff globl hidden diff --git a/libc/sysv/calls/posix_spawn.s b/libc/sysv/calls/posix_spawn.s deleted file mode 100644 index 6125485b..00000000 --- a/libc/sysv/calls/posix_spawn.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/sysv/macros.internal.inc" -.scall posix_spawn 0xffffffff20f4ffff globl hidden diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index 04b7d49c..37ce65cc 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -280,18 +280,6 @@ syscon madv MADV_HWPOISON 100 0 0 0 0 # TODO(jart): what is it? syscon madv MADV_REMOVE 9 0 0 0 0 # TODO(jart): what is it? syscon fadv POSIX_FADV_NOREUSE 5 0 5 0 0 # wut -# posix_spawn() -# only native on xnu -# -# group name GNU/Systemd XNU's Not UNIX FreeBSD OpenBSD XENIX Commentary -syscon spawn POSIX_SPAWN_RESETIDS 1 1 1 1 0 # unix consensus -syscon spawn POSIX_SPAWN_SETPGROUP 2 2 2 2 0 # unix consensus -syscon spawn POSIX_SPAWN_SETSIGDEF 4 4 0x10 0x10 0 -syscon spawn POSIX_SPAWN_SETSIGMASK 8 8 0x20 0x20 0 -syscon spawn POSIX_SPAWN_SETSCHEDPARAM 0x10 0 4 4 0 -syscon spawn POSIX_SPAWN_SETSCHEDULER 0x20 0 8 8 0 -syscon spawn POSIX_SPAWN_USEVFORK 0x40 0 0 0 0 - # mmap(), mprotect(), etc. # digital restrictions management for the people # diff --git a/libc/sysv/consts/POSIX_SPAWN_RESETIDS.s b/libc/sysv/consts/POSIX_SPAWN_RESETIDS.s deleted file mode 100644 index fb41004b..00000000 --- a/libc/sysv/consts/POSIX_SPAWN_RESETIDS.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "libc/sysv/consts/syscon.inc" -.syscon spawn POSIX_SPAWN_RESETIDS 1 1 1 1 0 diff --git a/libc/sysv/consts/POSIX_SPAWN_SETPGROUP.s b/libc/sysv/consts/POSIX_SPAWN_SETPGROUP.s deleted file mode 100644 index 7d1cb651..00000000 --- a/libc/sysv/consts/POSIX_SPAWN_SETPGROUP.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "libc/sysv/consts/syscon.inc" -.syscon spawn POSIX_SPAWN_SETPGROUP 2 2 2 2 0 diff --git a/libc/sysv/consts/POSIX_SPAWN_SETSCHEDPARAM.s b/libc/sysv/consts/POSIX_SPAWN_SETSCHEDPARAM.s deleted file mode 100644 index 7c73533f..00000000 --- a/libc/sysv/consts/POSIX_SPAWN_SETSCHEDPARAM.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "libc/sysv/consts/syscon.inc" -.syscon spawn POSIX_SPAWN_SETSCHEDPARAM 0x10 0 4 4 0 diff --git a/libc/sysv/consts/POSIX_SPAWN_SETSCHEDULER.s b/libc/sysv/consts/POSIX_SPAWN_SETSCHEDULER.s deleted file mode 100644 index a26af3fe..00000000 --- a/libc/sysv/consts/POSIX_SPAWN_SETSCHEDULER.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "libc/sysv/consts/syscon.inc" -.syscon spawn POSIX_SPAWN_SETSCHEDULER 0x20 0 8 8 0 diff --git a/libc/sysv/consts/POSIX_SPAWN_SETSIGDEF.s b/libc/sysv/consts/POSIX_SPAWN_SETSIGDEF.s deleted file mode 100644 index 7941dcaf..00000000 --- a/libc/sysv/consts/POSIX_SPAWN_SETSIGDEF.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "libc/sysv/consts/syscon.inc" -.syscon spawn POSIX_SPAWN_SETSIGDEF 4 4 0x10 0x10 0 diff --git a/libc/sysv/consts/POSIX_SPAWN_SETSIGMASK.s b/libc/sysv/consts/POSIX_SPAWN_SETSIGMASK.s deleted file mode 100644 index 87788e65..00000000 --- a/libc/sysv/consts/POSIX_SPAWN_SETSIGMASK.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "libc/sysv/consts/syscon.inc" -.syscon spawn POSIX_SPAWN_SETSIGMASK 8 8 0x20 0x20 0 diff --git a/libc/sysv/consts/POSIX_SPAWN_USEVFORK.s b/libc/sysv/consts/POSIX_SPAWN_USEVFORK.s deleted file mode 100644 index eef33de2..00000000 --- a/libc/sysv/consts/POSIX_SPAWN_USEVFORK.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "libc/sysv/consts/syscon.inc" -.syscon spawn POSIX_SPAWN_USEVFORK 0x40 0 0 0 0 diff --git a/libc/sysv/consts/posix.h b/libc/sysv/consts/posix.h index 36bec0bb..37410b5e 100644 --- a/libc/sysv/consts/posix.h +++ b/libc/sysv/consts/posix.h @@ -1,26 +1,6 @@ #ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_POSIX_H_ #define COSMOPOLITAN_LIBC_SYSV_CONSTS_POSIX_H_ #include "libc/runtime/symbolic.h" - -#define POSIX_FADV_DONTNEED SYMBOLIC(POSIX_FADV_DONTNEED) -#define POSIX_FADV_NOREUSE SYMBOLIC(POSIX_FADV_NOREUSE) -#define POSIX_FADV_NORMAL SYMBOLIC(POSIX_FADV_NORMAL) -#define POSIX_FADV_RANDOM SYMBOLIC(POSIX_FADV_RANDOM) -#define POSIX_FADV_SEQUENTIAL SYMBOLIC(POSIX_FADV_SEQUENTIAL) -#define POSIX_FADV_WILLNEED SYMBOLIC(POSIX_FADV_WILLNEED) -#define POSIX_MADV_DONTNEED SYMBOLIC(POSIX_MADV_DONTNEED) -#define POSIX_MADV_NORMAL SYMBOLIC(POSIX_MADV_NORMAL) -#define POSIX_MADV_RANDOM SYMBOLIC(POSIX_MADV_RANDOM) -#define POSIX_MADV_SEQUENTIAL SYMBOLIC(POSIX_MADV_SEQUENTIAL) -#define POSIX_MADV_WILLNEED SYMBOLIC(POSIX_MADV_WILLNEED) -#define POSIX_SPAWN_RESETIDS SYMBOLIC(POSIX_SPAWN_RESETIDS) -#define POSIX_SPAWN_SETPGROUP SYMBOLIC(POSIX_SPAWN_SETPGROUP) -#define POSIX_SPAWN_SETSCHEDPARAM SYMBOLIC(POSIX_SPAWN_SETSCHEDPARAM) -#define POSIX_SPAWN_SETSCHEDULER SYMBOLIC(POSIX_SPAWN_SETSCHEDULER) -#define POSIX_SPAWN_SETSIGDEF SYMBOLIC(POSIX_SPAWN_SETSIGDEF) -#define POSIX_SPAWN_SETSIGMASK SYMBOLIC(POSIX_SPAWN_SETSIGMASK) -#define POSIX_SPAWN_USEVFORK SYMBOLIC(POSIX_SPAWN_USEVFORK) - #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -35,14 +15,20 @@ hidden extern const long POSIX_MADV_NORMAL; hidden extern const long POSIX_MADV_RANDOM; hidden extern const long POSIX_MADV_SEQUENTIAL; hidden extern const long POSIX_MADV_WILLNEED; -hidden extern const long POSIX_SPAWN_RESETIDS; -hidden extern const long POSIX_SPAWN_SETPGROUP; -hidden extern const long POSIX_SPAWN_SETSCHEDPARAM; -hidden extern const long POSIX_SPAWN_SETSCHEDULER; -hidden extern const long POSIX_SPAWN_SETSIGDEF; -hidden extern const long POSIX_SPAWN_SETSIGMASK; -hidden extern const long POSIX_SPAWN_USEVFORK; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ + +#define POSIX_FADV_DONTNEED SYMBOLIC(POSIX_FADV_DONTNEED) +#define POSIX_FADV_NOREUSE SYMBOLIC(POSIX_FADV_NOREUSE) +#define POSIX_FADV_NORMAL SYMBOLIC(POSIX_FADV_NORMAL) +#define POSIX_FADV_RANDOM SYMBOLIC(POSIX_FADV_RANDOM) +#define POSIX_FADV_SEQUENTIAL SYMBOLIC(POSIX_FADV_SEQUENTIAL) +#define POSIX_FADV_WILLNEED SYMBOLIC(POSIX_FADV_WILLNEED) +#define POSIX_MADV_DONTNEED SYMBOLIC(POSIX_MADV_DONTNEED) +#define POSIX_MADV_NORMAL SYMBOLIC(POSIX_MADV_NORMAL) +#define POSIX_MADV_RANDOM SYMBOLIC(POSIX_MADV_RANDOM) +#define POSIX_MADV_SEQUENTIAL SYMBOLIC(POSIX_MADV_SEQUENTIAL) +#define POSIX_MADV_WILLNEED SYMBOLIC(POSIX_MADV_WILLNEED) + #endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_POSIX_H_ */ diff --git a/libc/sysv/syscalls.sh b/libc/sysv/syscalls.sh index 7eb8d254..f57e55e2 100755 --- a/libc/sysv/syscalls.sh +++ b/libc/sysv/syscalls.sh @@ -91,7 +91,7 @@ scall 'setsockopt$sysv' 0x0069006920690036 globl hidden scall 'getsockopt$sysv' 0x0076007620760037 globl hidden scall '__fork$sysv' 0x0002000220020039 globl hidden # xnu needs eax=~-edx b/c eax always holds pid and edx is 0 for parent and 1 for child #scall vfork 0x004200422042003a globl # this syscall is from the moon so we implement it by hand in libc/calls/hefty/vfork.S -scall posix_spawn 0xffffffff20f4ffff globl hidden # TODO: put in spawnve() +scall 'posix_spawn$sysv' 0xffffffff20f4ffff globl hidden # good luck figuring out how xnu defines this scall '__execve$sysv' 0x003b003b203b003b globl hidden scall 'wait4$sysv' 0x000b00072007003d globl hidden scall 'kill$sysv' 0x007a00252025003e globl hidden # kill(pid, sig, 1) b/c xnu