diff --git a/libc/config/linux/riscv64/entrypoints.txt b/libc/config/linux/riscv64/entrypoints.txt --- a/libc/config/linux/riscv64/entrypoints.txt +++ b/libc/config/linux/riscv64/entrypoints.txt @@ -431,6 +431,14 @@ libc.src.signal.sigfillset libc.src.signal.signal + # spawn.h entrypoints + libc.src.spawn.posix_spawn + libc.src.spawn.posix_spawn_file_actions_addclose + libc.src.spawn.posix_spawn_file_actions_adddup2 + libc.src.spawn.posix_spawn_file_actions_addopen + libc.src.spawn.posix_spawn_file_actions_destroy + libc.src.spawn.posix_spawn_file_actions_init + # threads.h entrypoints libc.src.threads.call_once libc.src.threads.cnd_broadcast diff --git a/libc/config/linux/riscv64/headers.txt b/libc/config/linux/riscv64/headers.txt --- a/libc/config/linux/riscv64/headers.txt +++ b/libc/config/linux/riscv64/headers.txt @@ -9,6 +9,7 @@ libc.include.pthread libc.include.sched libc.include.signal + libc.include.spawn libc.include.stdio libc.include.stdlib libc.include.string diff --git a/libc/src/spawn/linux/posix_spawn.cpp b/libc/src/spawn/linux/posix_spawn.cpp --- a/libc/src/spawn/linux/posix_spawn.cpp +++ b/libc/src/spawn/linux/posix_spawn.cpp @@ -14,6 +14,7 @@ #include "src/spawn/file_actions.h" #include +#include // For SIGCHLD #include #include // For syscall numbers. @@ -50,8 +51,15 @@ void close(int fd) { __llvm_libc::syscall_impl(SYS_close, fd); } +// We use dup3 if dup2 is not available, similar to our implementation of dup2 bool dup2(int fd, int newfd) { +#ifdef SYS_dup2 long ret = __llvm_libc::syscall_impl(SYS_dup2, fd, newfd); +#elif defined(SYS_dup3) + long ret = __llvm_libc::syscall_impl(SYS_dup3, fd, newfd, 0); +#else +#error "SYS_dup2 and SYS_dup3 not available for the target." +#endif return ret < 0 ? false : true; }