[libc-commits] [libc] fe99de3 - [libc] Enable spawn lib in riscv
Mikhail R. Gadelha via libc-commits
libc-commits at lists.llvm.org
Thu Mar 16 02:18:01 PDT 2023
Author: Mikhail R. Gadelha
Date: 2023-03-16T06:16:14-03:00
New Revision: fe99de31d949187fa9759de581041bb1aff460ea
URL: https://github.com/llvm/llvm-project/commit/fe99de31d949187fa9759de581041bb1aff460ea
DIFF: https://github.com/llvm/llvm-project/commit/fe99de31d949187fa9759de581041bb1aff460ea.diff
LOG: [libc] Enable spawn lib in riscv
In this patch we add support for the spawn lib in riscv.
Only small changes were required, the biggest one was to use of dup3
instead of dup2, if the latter is not available. This follows our
implementation of dup2.
Differential Revision: https://reviews.llvm.org/D146145
Added:
Modified:
libc/config/linux/riscv64/entrypoints.txt
libc/config/linux/riscv64/headers.txt
libc/src/spawn/linux/posix_spawn.cpp
Removed:
################################################################################
diff --git a/libc/config/linux/riscv64/entrypoints.txt b/libc/config/linux/riscv64/entrypoints.txt
index 2d0df5cde2671..042671fa1833a 100644
--- a/libc/config/linux/riscv64/entrypoints.txt
+++ b/libc/config/linux/riscv64/entrypoints.txt
@@ -431,6 +431,14 @@ if(LLVM_LIBC_FULL_BUILD)
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
index 1b6dea68e238a..6d7e53790ec12 100644
--- a/libc/config/linux/riscv64/headers.txt
+++ b/libc/config/linux/riscv64/headers.txt
@@ -9,6 +9,7 @@ set(TARGET_PUBLIC_HEADERS
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
index 2f8287238ec86..504ac5d0a3938 100644
--- 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 <fcntl.h>
+#include <signal.h> // For SIGCHLD
#include <spawn.h>
#include <sys/syscall.h> // For syscall numbers.
@@ -50,8 +51,15 @@ cpp::optional<int> open(const char *path, int oflags, mode_t mode) {
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;
}
More information about the libc-commits
mailing list