Skip to content

Commit b282dfd

Browse files
committed
Improve posix_spawn(3) interface
Don't unconditionally use `fexecve(2)`, but also use `execve(2)`, and do program-path lookup within the child, rather than within the parent.
1 parent 035a792 commit b282dfd

File tree

13 files changed

+1512
-1156
lines changed

13 files changed

+1512
-1156
lines changed

kos/include/bits/posix_opt.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* HASH CRC-32:0x28859381 */
1+
/* HASH CRC-32:0xbb4e2eb9 */
22
/* Copyright (c) 2019-2025 Griefer@Work *
33
* *
44
* This software is provided 'as-is', without any express or implied *
@@ -155,9 +155,9 @@
155155
#include <asm/os/vfork.h>
156156
#include <asm/os/features.h>
157157
#include <hybrid/__alloca.h>
158-
#if (defined(__CRT_HAVE_posix_spawn) || ((defined(__CRT_HAVE_open64) || defined(__CRT_HAVE___open64) || defined(__CRT_HAVE_open) || defined(__CRT_HAVE__open) || defined(__CRT_HAVE___open) || defined(__CRT_HAVE___libc_open) || (defined(__AT_FDCWD) && (defined(__CRT_HAVE_openat64) || defined(__CRT_HAVE_openat)))) && (defined(__CRT_HAVE_posix_fspawn_np) || (defined(__POSIX_SPAWN_USE_KOS) && ((defined(__ARCH_HAVE_SHARED_VM_VFORK) && (defined(__CRT_HAVE_vfork) || defined(__CRT_HAVE___vfork) || defined(__CRT_HAVE___libc_vfork))) || ((defined(__CRT_HAVE_fork) || defined(__CRT_HAVE___fork) || defined(__CRT_HAVE___libc_fork)) && (defined(__CRT_HAVE_pipe2) || defined(__CRT_HAVE_pipe) || defined(__CRT_HAVE___pipe) || defined(__CRT_HAVE___libc_pipe) || defined(__CRT_HAVE__pipe)) && defined(__O_CLOEXEC) && (defined(__CRT_HAVE_read) || defined(__CRT_HAVE__read) || defined(__CRT_HAVE___read) || defined(__CRT_HAVE___libc_read)) && (defined(__CRT_HAVE_write) || defined(__CRT_HAVE__write) || defined(__CRT_HAVE___write) || defined(__CRT_HAVE___libc_write)) && (defined(__CRT_HAVE_close) || defined(__CRT_HAVE__close) || defined(__CRT_HAVE___close) || defined(__CRT_HAVE___libc_close)))) && defined(__CRT_HAVE_fexecve) && (defined(__CRT_HAVE_waitpid) || defined(__CRT_HAVE___waitpid)))))) && (defined(__CRT_HAVE_posix_spawnp) || ((defined(__CRT_HAVE_getenv) || defined(__LOCAL_environ)) && defined(__hybrid_alloca))) && (defined(__CRT_HAVE_posix_spawn_file_actions_addclose) || (defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_realloc) || defined(__CRT_HAVE___libc_realloc)))) && (defined(__CRT_HAVE_posix_spawn_file_actions_adddup2) || (defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_realloc) || defined(__CRT_HAVE___libc_realloc)))) && (defined(__CRT_HAVE_posix_spawn_file_actions_addopen) || (defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_realloc) || defined(__CRT_HAVE___libc_realloc)))) && (defined(__CRT_HAVE_posix_spawn_file_actions_destroy) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_getsigdefault) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_getflags) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_getpgroup) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_getsigmask) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_setsigdefault) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_setflags) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_setpgroup) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_setsigmask) || defined(__POSIX_SPAWN_USE_KOS))
158+
#if (defined(__CRT_HAVE_posix_spawn) || (((defined(__ARCH_HAVE_SHARED_VM_VFORK) && (defined(__CRT_HAVE_vfork) || defined(__CRT_HAVE___vfork) || defined(__CRT_HAVE___libc_vfork))) || ((defined(__CRT_HAVE_fork) || defined(__CRT_HAVE___fork) || defined(__CRT_HAVE___libc_fork)) && (defined(__CRT_HAVE_pipe2) || defined(__CRT_HAVE_pipe) || defined(__CRT_HAVE___pipe) || defined(__CRT_HAVE___libc_pipe) || defined(__CRT_HAVE__pipe)) && defined(__O_CLOEXEC) && (defined(__CRT_HAVE_read) || defined(__CRT_HAVE__read) || defined(__CRT_HAVE___read) || defined(__CRT_HAVE___libc_read)) && (defined(__CRT_HAVE_write) || defined(__CRT_HAVE__write) || defined(__CRT_HAVE___write) || defined(__CRT_HAVE___libc_write)) && (defined(__CRT_HAVE_close) || defined(__CRT_HAVE__close) || defined(__CRT_HAVE___close) || defined(__CRT_HAVE___libc_close)))) && defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_waitpid) || defined(__CRT_HAVE___waitpid)) && (defined(__CRT_HAVE_execve) || defined(__CRT_HAVE__execve) || defined(__CRT_HAVE___execve) || defined(__CRT_HAVE___libc_execve))) || ((defined(__CRT_HAVE_open64) || defined(__CRT_HAVE___open64) || defined(__CRT_HAVE_open) || defined(__CRT_HAVE__open) || defined(__CRT_HAVE___open) || defined(__CRT_HAVE___libc_open) || (defined(__AT_FDCWD) && (defined(__CRT_HAVE_openat64) || defined(__CRT_HAVE_openat)))) && (defined(__CRT_HAVE_posix_fspawn_np) || (((defined(__ARCH_HAVE_SHARED_VM_VFORK) && (defined(__CRT_HAVE_vfork) || defined(__CRT_HAVE___vfork) || defined(__CRT_HAVE___libc_vfork))) || ((defined(__CRT_HAVE_fork) || defined(__CRT_HAVE___fork) || defined(__CRT_HAVE___libc_fork)) && (defined(__CRT_HAVE_pipe2) || defined(__CRT_HAVE_pipe) || defined(__CRT_HAVE___pipe) || defined(__CRT_HAVE___libc_pipe) || defined(__CRT_HAVE__pipe)) && defined(__O_CLOEXEC) && (defined(__CRT_HAVE_read) || defined(__CRT_HAVE__read) || defined(__CRT_HAVE___read) || defined(__CRT_HAVE___libc_read)) && (defined(__CRT_HAVE_write) || defined(__CRT_HAVE__write) || defined(__CRT_HAVE___write) || defined(__CRT_HAVE___libc_write)) && (defined(__CRT_HAVE_close) || defined(__CRT_HAVE__close) || defined(__CRT_HAVE___close) || defined(__CRT_HAVE___libc_close)))) && defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_waitpid) || defined(__CRT_HAVE___waitpid)) && (defined(__CRT_HAVE_fexecve) || (defined(__OS_HAVE_PROCFS_SELF_FD) && (defined(__CRT_HAVE_execve) || defined(__CRT_HAVE__execve) || defined(__CRT_HAVE___execve) || defined(__CRT_HAVE___libc_execve)))))))) && (defined(__CRT_HAVE_posix_spawnp) || (((defined(__ARCH_HAVE_SHARED_VM_VFORK) && (defined(__CRT_HAVE_vfork) || defined(__CRT_HAVE___vfork) || defined(__CRT_HAVE___libc_vfork))) || ((defined(__CRT_HAVE_fork) || defined(__CRT_HAVE___fork) || defined(__CRT_HAVE___libc_fork)) && (defined(__CRT_HAVE_pipe2) || defined(__CRT_HAVE_pipe) || defined(__CRT_HAVE___pipe) || defined(__CRT_HAVE___libc_pipe) || defined(__CRT_HAVE__pipe)) && defined(__O_CLOEXEC) && (defined(__CRT_HAVE_read) || defined(__CRT_HAVE__read) || defined(__CRT_HAVE___read) || defined(__CRT_HAVE___libc_read)) && (defined(__CRT_HAVE_write) || defined(__CRT_HAVE__write) || defined(__CRT_HAVE___write) || defined(__CRT_HAVE___libc_write)) && (defined(__CRT_HAVE_close) || defined(__CRT_HAVE__close) || defined(__CRT_HAVE___close) || defined(__CRT_HAVE___libc_close)))) && defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_waitpid) || defined(__CRT_HAVE___waitpid)) && (defined(__CRT_HAVE_execvpe) || defined(__CRT_HAVE__execvpe))) || ((defined(__CRT_HAVE_getenv) || defined(__LOCAL_environ)) && defined(__hybrid_alloca))) && (defined(__CRT_HAVE_posix_spawn_file_actions_addclose) || (defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_realloc) || defined(__CRT_HAVE___libc_realloc)))) && (defined(__CRT_HAVE_posix_spawn_file_actions_adddup2) || (defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_realloc) || defined(__CRT_HAVE___libc_realloc)))) && (defined(__CRT_HAVE_posix_spawn_file_actions_addopen) || (defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_realloc) || defined(__CRT_HAVE___libc_realloc)))) && (defined(__CRT_HAVE_posix_spawn_file_actions_destroy) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_getsigdefault) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_getflags) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_getpgroup) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_getsigmask) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_setsigdefault) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_setflags) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_setpgroup) || defined(__POSIX_SPAWN_USE_KOS)) && (defined(__CRT_HAVE_posix_spawnattr_setsigmask) || defined(__POSIX_SPAWN_USE_KOS))
159159
#define _POSIX_SPAWN 200809L /* The `spawn' function family is supported. */
160-
#endif /* (__CRT_HAVE_posix_spawn || ((__CRT_HAVE_open64 || __CRT_HAVE___open64 || __CRT_HAVE_open || __CRT_HAVE__open || __CRT_HAVE___open || __CRT_HAVE___libc_open || (__AT_FDCWD && (__CRT_HAVE_openat64 || __CRT_HAVE_openat))) && (__CRT_HAVE_posix_fspawn_np || (__POSIX_SPAWN_USE_KOS && ((__ARCH_HAVE_SHARED_VM_VFORK && (__CRT_HAVE_vfork || __CRT_HAVE___vfork || __CRT_HAVE___libc_vfork)) || ((__CRT_HAVE_fork || __CRT_HAVE___fork || __CRT_HAVE___libc_fork) && (__CRT_HAVE_pipe2 || __CRT_HAVE_pipe || __CRT_HAVE___pipe || __CRT_HAVE___libc_pipe || __CRT_HAVE__pipe) && __O_CLOEXEC && (__CRT_HAVE_read || __CRT_HAVE__read || __CRT_HAVE___read || __CRT_HAVE___libc_read) && (__CRT_HAVE_write || __CRT_HAVE__write || __CRT_HAVE___write || __CRT_HAVE___libc_write) && (__CRT_HAVE_close || __CRT_HAVE__close || __CRT_HAVE___close || __CRT_HAVE___libc_close))) && __CRT_HAVE_fexecve && (__CRT_HAVE_waitpid || __CRT_HAVE___waitpid))))) && (__CRT_HAVE_posix_spawnp || ((__CRT_HAVE_getenv || __LOCAL_environ) && __hybrid_alloca)) && (__CRT_HAVE_posix_spawn_file_actions_addclose || (__POSIX_SPAWN_USE_KOS && (__CRT_HAVE_realloc || __CRT_HAVE___libc_realloc))) && (__CRT_HAVE_posix_spawn_file_actions_adddup2 || (__POSIX_SPAWN_USE_KOS && (__CRT_HAVE_realloc || __CRT_HAVE___libc_realloc))) && (__CRT_HAVE_posix_spawn_file_actions_addopen || (__POSIX_SPAWN_USE_KOS && (__CRT_HAVE_realloc || __CRT_HAVE___libc_realloc))) && (__CRT_HAVE_posix_spawn_file_actions_destroy || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_getsigdefault || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_getflags || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_getpgroup || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_getsigmask || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_setsigdefault || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_setflags || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_setpgroup || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_setsigmask || __POSIX_SPAWN_USE_KOS) */
160+
#endif /* (__CRT_HAVE_posix_spawn || (((__ARCH_HAVE_SHARED_VM_VFORK && (__CRT_HAVE_vfork || __CRT_HAVE___vfork || __CRT_HAVE___libc_vfork)) || ((__CRT_HAVE_fork || __CRT_HAVE___fork || __CRT_HAVE___libc_fork) && (__CRT_HAVE_pipe2 || __CRT_HAVE_pipe || __CRT_HAVE___pipe || __CRT_HAVE___libc_pipe || __CRT_HAVE__pipe) && __O_CLOEXEC && (__CRT_HAVE_read || __CRT_HAVE__read || __CRT_HAVE___read || __CRT_HAVE___libc_read) && (__CRT_HAVE_write || __CRT_HAVE__write || __CRT_HAVE___write || __CRT_HAVE___libc_write) && (__CRT_HAVE_close || __CRT_HAVE__close || __CRT_HAVE___close || __CRT_HAVE___libc_close))) && __POSIX_SPAWN_USE_KOS && (__CRT_HAVE_waitpid || __CRT_HAVE___waitpid) && (__CRT_HAVE_execve || __CRT_HAVE__execve || __CRT_HAVE___execve || __CRT_HAVE___libc_execve)) || ((__CRT_HAVE_open64 || __CRT_HAVE___open64 || __CRT_HAVE_open || __CRT_HAVE__open || __CRT_HAVE___open || __CRT_HAVE___libc_open || (__AT_FDCWD && (__CRT_HAVE_openat64 || __CRT_HAVE_openat))) && (__CRT_HAVE_posix_fspawn_np || (((__ARCH_HAVE_SHARED_VM_VFORK && (__CRT_HAVE_vfork || __CRT_HAVE___vfork || __CRT_HAVE___libc_vfork)) || ((__CRT_HAVE_fork || __CRT_HAVE___fork || __CRT_HAVE___libc_fork) && (__CRT_HAVE_pipe2 || __CRT_HAVE_pipe || __CRT_HAVE___pipe || __CRT_HAVE___libc_pipe || __CRT_HAVE__pipe) && __O_CLOEXEC && (__CRT_HAVE_read || __CRT_HAVE__read || __CRT_HAVE___read || __CRT_HAVE___libc_read) && (__CRT_HAVE_write || __CRT_HAVE__write || __CRT_HAVE___write || __CRT_HAVE___libc_write) && (__CRT_HAVE_close || __CRT_HAVE__close || __CRT_HAVE___close || __CRT_HAVE___libc_close))) && __POSIX_SPAWN_USE_KOS && (__CRT_HAVE_waitpid || __CRT_HAVE___waitpid) && (__CRT_HAVE_fexecve || (__OS_HAVE_PROCFS_SELF_FD && (__CRT_HAVE_execve || __CRT_HAVE__execve || __CRT_HAVE___execve || __CRT_HAVE___libc_execve))))))) && (__CRT_HAVE_posix_spawnp || (((__ARCH_HAVE_SHARED_VM_VFORK && (__CRT_HAVE_vfork || __CRT_HAVE___vfork || __CRT_HAVE___libc_vfork)) || ((__CRT_HAVE_fork || __CRT_HAVE___fork || __CRT_HAVE___libc_fork) && (__CRT_HAVE_pipe2 || __CRT_HAVE_pipe || __CRT_HAVE___pipe || __CRT_HAVE___libc_pipe || __CRT_HAVE__pipe) && __O_CLOEXEC && (__CRT_HAVE_read || __CRT_HAVE__read || __CRT_HAVE___read || __CRT_HAVE___libc_read) && (__CRT_HAVE_write || __CRT_HAVE__write || __CRT_HAVE___write || __CRT_HAVE___libc_write) && (__CRT_HAVE_close || __CRT_HAVE__close || __CRT_HAVE___close || __CRT_HAVE___libc_close))) && __POSIX_SPAWN_USE_KOS && (__CRT_HAVE_waitpid || __CRT_HAVE___waitpid) && (__CRT_HAVE_execvpe || __CRT_HAVE__execvpe)) || ((__CRT_HAVE_getenv || __LOCAL_environ) && __hybrid_alloca)) && (__CRT_HAVE_posix_spawn_file_actions_addclose || (__POSIX_SPAWN_USE_KOS && (__CRT_HAVE_realloc || __CRT_HAVE___libc_realloc))) && (__CRT_HAVE_posix_spawn_file_actions_adddup2 || (__POSIX_SPAWN_USE_KOS && (__CRT_HAVE_realloc || __CRT_HAVE___libc_realloc))) && (__CRT_HAVE_posix_spawn_file_actions_addopen || (__POSIX_SPAWN_USE_KOS && (__CRT_HAVE_realloc || __CRT_HAVE___libc_realloc))) && (__CRT_HAVE_posix_spawn_file_actions_destroy || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_getsigdefault || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_getflags || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_getpgroup || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_getsigmask || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_setsigdefault || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_setflags || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_setpgroup || __POSIX_SPAWN_USE_KOS) && (__CRT_HAVE_posix_spawnattr_setsigmask || __POSIX_SPAWN_USE_KOS) */
161161
#if defined(__CRT_HAVE_timer_create) && defined(__CRT_HAVE_timer_delete) && (defined(__CRT_HAVE_timer_gettime64) || defined(__CRT_HAVE___timer_gettime64) || defined(__CRT_HAVE_timer_gettime)) && defined(__CRT_HAVE_timer_getoverrun) && (defined(__CRT_HAVE_timer_settime64) || defined(__CRT_HAVE___timer_settime64) || defined(__CRT_HAVE_timer_settime))
162162
#define _POSIX_TIMERS 200809L /* We have POSIX timers. */
163163
#endif /* __CRT_HAVE_timer_create && __CRT_HAVE_timer_delete && (__CRT_HAVE_timer_gettime64 || __CRT_HAVE___timer_gettime64 || __CRT_HAVE_timer_gettime) && __CRT_HAVE_timer_getoverrun && (__CRT_HAVE_timer_settime64 || __CRT_HAVE___timer_settime64 || __CRT_HAVE_timer_settime) */

0 commit comments

Comments
 (0)