[libc-commits] [libc] 1990ce7 - [libc] Enable __llvm_libc_syscall and fork
Mikhail R. Gadelha via libc-commits
libc-commits at lists.llvm.org
Thu Mar 16 02:18:03 PDT 2023
Author: Mikhail R. Gadelha
Date: 2023-03-16T06:16:14-03:00
New Revision: 1990ce74dcbd5fbb5c71672b50730007be3dcd5e
URL: https://github.com/llvm/llvm-project/commit/1990ce74dcbd5fbb5c71672b50730007be3dcd5e
DIFF: https://github.com/llvm/llvm-project/commit/1990ce74dcbd5fbb5c71672b50730007be3dcd5e.diff
LOG: [libc] Enable __llvm_libc_syscall and fork
This patch enables the remaining calls from unistd.
The test cases had to be updated to:
1. Use SYS_symlinkat if SYS_symlink is not available
2. Use SYS_readlinkat if SYS_readlink is not available
3. Use SYS_unlinkat if SYS_unlink is not available
4. Use SYS_openat if SYS_open is not available
We also abort compilation if neither of the syscalls mentioned above are
available.
Differential Revision: https://reviews.llvm.org/D146161
Added:
Modified:
libc/config/linux/riscv64/entrypoints.txt
libc/src/unistd/linux/fork.cpp
libc/test/src/unistd/syscall_test.cpp
Removed:
################################################################################
diff --git a/libc/config/linux/riscv64/entrypoints.txt b/libc/config/linux/riscv64/entrypoints.txt
index 042671fa1833a..95e3c1e5bf509 100644
--- a/libc/config/linux/riscv64/entrypoints.txt
+++ b/libc/config/linux/riscv64/entrypoints.txt
@@ -477,6 +477,8 @@ if(LLVM_LIBC_FULL_BUILD)
# unistd.h entrypoints
libc.src.unistd.environ
libc.src.unistd.execv
+ libc.src.unistd.fork
+ libc.src.unistd.__llvm_libc_syscall
libc.src.unistd.getopt
libc.src.unistd.optarg
libc.src.unistd.optind
diff --git a/libc/src/unistd/linux/fork.cpp b/libc/src/unistd/linux/fork.cpp
index 92d19e253ea42..89d27d3c36f89 100644
--- a/libc/src/unistd/linux/fork.cpp
+++ b/libc/src/unistd/linux/fork.cpp
@@ -14,6 +14,7 @@
#include "src/__support/threads/thread.h" // For thread self object
#include "src/errno/libc_errno.h"
+#include <signal.h> // For SIGCHLD
#include <sys/syscall.h> // For syscall numbers.
namespace __llvm_libc {
diff --git a/libc/test/src/unistd/syscall_test.cpp b/libc/test/src/unistd/syscall_test.cpp
index 3f95f18041d2b..9c9e24282a0de 100644
--- a/libc/test/src/unistd/syscall_test.cpp
+++ b/libc/test/src/unistd/syscall_test.cpp
@@ -36,15 +36,33 @@ TEST(LlvmLibcSyscallTest, SymlinkCreateDestroy) {
constexpr const char LINK_VAL[] = "syscall_readlink_test_value";
constexpr const char LINK[] = "testdata/syscall_readlink.test.link";
+#ifdef SYS_symlink
ASSERT_GE(__llvm_libc::syscall(SYS_symlink, LINK_VAL, LINK), 0l);
+#elif defined(SYS_symlinkat)
+ ASSERT_GE(__llvm_libc::syscall(SYS_symlinkat, LINK_VAL, AT_FDCWD, LINK), 0l);
+#else
+#error "Symlink syscalls not available."
+#endif
ASSERT_EQ(libc_errno, 0);
char buf[sizeof(LINK_VAL)];
+#ifdef SYS_readlink
ASSERT_GE(__llvm_libc::syscall(SYS_readlink, LINK, buf, sizeof(buf)), 0l);
+#elif defined(SYS_readlinkat)
+ ASSERT_GE(
+ __llvm_libc::syscall(SYS_readlinkat, AT_FDCWD, LINK, buf, sizeof(buf)),
+ 0l);
+#endif
ASSERT_EQ(libc_errno, 0);
+#ifdef SYS_unlink
ASSERT_GE(__llvm_libc::syscall(SYS_unlink, LINK), 0l);
+#elif defined(SYS_unlinkat)
+ ASSERT_GE(__llvm_libc::syscall(SYS_unlinkat, AT_FDCWD, LINK, 0), 0l);
+#else
+#error "Unlink syscalls not available."
+#endif
ASSERT_EQ(libc_errno, 0);
}
@@ -54,8 +72,15 @@ TEST(LlvmLibcSyscallTest, FileReadWrite) {
constexpr const char *TEST_FILE = "testdata/syscall_pread_pwrite.test";
+#ifdef SYS_open
int fd =
__llvm_libc::syscall(SYS_open, TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
+#elif defined(SYS_openat)
+ int fd = __llvm_libc::syscall(SYS_openat, AT_FDCWD, TEST_FILE,
+ O_WRONLY | O_CREAT, S_IRWXU);
+#else
+#error "Open syscalls not available to available."
+#endif
ASSERT_GT(fd, 0);
ASSERT_EQ(libc_errno, 0);
@@ -83,15 +108,29 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
// 3. Open the link to check that the link was created.
// 4. Cleanup the file and its link.
+#ifdef SYS_open
int write_fd = __llvm_libc::syscall(SYS_open, TEST_FILE_PATH,
O_WRONLY | O_CREAT, S_IRWXU);
+#elif defined(SYS_openat)
+ int write_fd = __llvm_libc::syscall(SYS_openat, AT_FDCWD, TEST_FILE_PATH,
+ O_WRONLY | O_CREAT, S_IRWXU);
+#else
+#error "Open syscalls not available to available."
+#endif
ASSERT_GT(write_fd, 0);
ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_close, write_fd), 0l);
ASSERT_EQ(libc_errno, 0);
+#ifdef SYS_open
int dir_fd = __llvm_libc::syscall(SYS_open, TEST_DIR, O_DIRECTORY, 0);
+#elif defined(SYS_openat)
+ int dir_fd =
+ __llvm_libc::syscall(SYS_openat, AT_FDCWD, TEST_DIR, O_DIRECTORY, 0);
+#else
+#error "Open syscalls not available to available."
+#endif
ASSERT_GT(dir_fd, 0);
ASSERT_EQ(libc_errno, 0);
@@ -99,15 +138,35 @@ TEST(LlvmLibcSyscallTest, FileLinkCreateDestroy) {
TEST_FILE_LINK, 0),
0l);
ASSERT_EQ(libc_errno, 0);
-
+#ifdef SYS_open
int link_fd = __llvm_libc::syscall(SYS_open, TEST_FILE_LINK_PATH, O_PATH, 0);
+#elif defined(SYS_openat)
+ int link_fd = __llvm_libc::syscall(SYS_openat, AT_FDCWD, TEST_FILE_LINK_PATH,
+ O_PATH, 0);
+#else
+#error "Open syscalls not available to available."
+#endif
ASSERT_GT(link_fd, 0);
ASSERT_EQ(libc_errno, 0);
+#ifdef SYS_unlink
ASSERT_GE(__llvm_libc::syscall(SYS_unlink, TEST_FILE_PATH), 0l);
+#elif defined(SYS_unlinkat)
+ ASSERT_GE(__llvm_libc::syscall(SYS_unlinkat, AT_FDCWD, TEST_FILE_PATH, 0),
+ 0l);
+#else
+#error "Unlink syscalls not available."
+#endif
ASSERT_EQ(libc_errno, 0);
+#ifdef SYS_unlink
ASSERT_GE(__llvm_libc::syscall(SYS_unlink, TEST_FILE_LINK_PATH), 0l);
+#elif defined(SYS_unlinkat)
+ ASSERT_GE(
+ __llvm_libc::syscall(SYS_unlinkat, AT_FDCWD, TEST_FILE_LINK_PATH, 0), 0l);
+#else
+#error "Unlink syscalls not available."
+#endif
ASSERT_EQ(libc_errno, 0);
ASSERT_GE(__llvm_libc::syscall(SYS_close, dir_fd), 0l);
More information about the libc-commits
mailing list