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 @@ -477,6 +477,8 @@ # 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 --- 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 // For SIGCHLD #include // For syscall numbers. namespace __llvm_libc { diff --git a/libc/test/src/unistd/syscall_test.cpp b/libc/test/src/unistd/syscall_test.cpp --- a/libc/test/src/unistd/syscall_test.cpp +++ b/libc/test/src/unistd/syscall_test.cpp @@ -36,15 +36,33 @@ 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 @@ 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 @@ // 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_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);