[libc-commits] [PATCH] D146145: [libc] Enable spawn lib in riscv
Mikhail Ramalho via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Mar 15 08:42:57 PDT 2023
mikhail.ramalho created this revision.
mikhail.ramalho added a reviewer: sivachandra.
Herald added subscribers: libc-commits, luke, VincentWu, vkmr, frasercrmck, ecnelises, evandro, luismarques, apazos, sameer.abuasal, tschuett, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, arichardson.
Herald added projects: libc-project, All.
mikhail.ramalho requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146145
Files:
libc/config/linux/riscv64/entrypoints.txt
libc/config/linux/riscv64/headers.txt
libc/src/spawn/linux/posix_spawn.cpp
Index: libc/src/spawn/linux/posix_spawn.cpp
===================================================================
--- libc/src/spawn/linux/posix_spawn.cpp
+++ libc/src/spawn/linux/posix_spawn.cpp
@@ -17,6 +17,10 @@
#include <spawn.h>
#include <sys/syscall.h> // For syscall numbers.
+#ifdef SYS_clone
+#include <llvm-libc-macros/signal-macros.h> // For SIGCHLD
+#endif
+
namespace __llvm_libc {
namespace {
@@ -50,8 +54,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;
}
Index: libc/config/linux/riscv64/headers.txt
===================================================================
--- libc/config/linux/riscv64/headers.txt
+++ libc/config/linux/riscv64/headers.txt
@@ -9,6 +9,7 @@
libc.include.pthread
libc.include.sched
libc.include.signal
+ libc.include.spawn
libc.include.setjmp
libc.include.stdio
libc.include.stdlib
Index: libc/config/linux/riscv64/entrypoints.txt
===================================================================
--- libc/config/linux/riscv64/entrypoints.txt
+++ libc/config/linux/riscv64/entrypoints.txt
@@ -435,6 +435,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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146145.505509.patch
Type: text/x-patch
Size: 1998 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230315/9eae2584/attachment-0001.bin>
More information about the libc-commits
mailing list