diff options
-rw-r--r-- | libc/config/linux/aarch64/entrypoints.txt | 6 | ||||
-rw-r--r-- | libc/config/linux/x86_64/entrypoints.txt | 8 | ||||
-rw-r--r-- | libc/loader/linux/x86_64/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libc/loader/linux/x86_64/start.cpp | 1 | ||||
-rw-r--r-- | libc/src/CMakeLists.txt | 6 | ||||
-rw-r--r-- | libc/src/sys/mman/linux/mmap.cpp | 6 | ||||
-rw-r--r-- | libc/src/sys/mman/linux/munmap.cpp | 7 | ||||
-rw-r--r-- | libc/src/sys/mman/mmap.h | 2 | ||||
-rw-r--r-- | libc/src/sys/mman/munmap.h | 2 | ||||
-rw-r--r-- | libc/src/unistd/linux/write.cpp | 5 | ||||
-rw-r--r-- | libc/test/ErrnoSetterMatcher.h | 7 | ||||
-rw-r--r-- | libc/test/src/CMakeLists.txt | 5 | ||||
-rw-r--r-- | libc/test/src/sys/mman/linux/mmap_test.cpp | 12 | ||||
-rw-r--r-- | libc/test/src/unistd/write_test.cpp | 3 |
14 files changed, 37 insertions, 34 deletions
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index c0072c619075..7b9027efa336 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -169,15 +169,11 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.trunc libc.src.math.truncf libc.src.math.truncl -) -if(LLVM_LIBC_FULL_BUILD) - list(APPEND TARGET_LIBC_ENTRYPOINTS # sys/mman.h entrypoints libc.src.sys.mman.mmap libc.src.sys.mman.munmap - ) -endif() +) set(TARGET_LLVMLIBC_ENTRYPOINTS ${TARGET_LIBC_ENTRYPOINTS} diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 38586a4eddce..3cca89338702 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -75,6 +75,10 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.stdlib.strtoll libc.src.stdlib.strtoul libc.src.stdlib.strtoull + + # sys/mman.h entrypoints + libc.src.sys.mman.mmap + libc.src.sys.mman.munmap ) set(TARGET_LIBM_ENTRYPOINTS @@ -203,10 +207,6 @@ if(LLVM_LIBC_FULL_BUILD) # libc.src.signal.sigfillset # libc.src.signal.signal - # sys/mman.h entrypoints - libc.src.sys.mman.mmap - libc.src.sys.mman.munmap - # threads.h entrypoints libc.src.threads.call_once libc.src.threads.cnd_broadcast diff --git a/libc/loader/linux/x86_64/CMakeLists.txt b/libc/loader/linux/x86_64/CMakeLists.txt index 75b8a23802e7..c8fa53bf3d75 100644 --- a/libc/loader/linux/x86_64/CMakeLists.txt +++ b/libc/loader/linux/x86_64/CMakeLists.txt @@ -7,7 +7,6 @@ add_loader_object( libc.include.sys_syscall libc.src.__support.OSUtil.osutil libc.src.string.memcpy - libc.src.sys.mman.mmap COMPILE_OPTIONS -fno-omit-frame-pointer -ffreestanding # To avoid compiler warnings about calling the main function. diff --git a/libc/loader/linux/x86_64/start.cpp b/libc/loader/linux/x86_64/start.cpp index 55ae00391927..774f01b54321 100644 --- a/libc/loader/linux/x86_64/start.cpp +++ b/libc/loader/linux/x86_64/start.cpp @@ -11,7 +11,6 @@ #include "include/sys/syscall.h" #include "src/__support/OSUtil/syscall.h" #include "src/string/memcpy.h" -#include "src/sys/mman/mmap.h" #include <asm/prctl.h> #include <linux/auxvec.h> diff --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt index 006bf5c7563b..99faf794c135 100644 --- a/libc/src/CMakeLists.txt +++ b/libc/src/CMakeLists.txt @@ -8,6 +8,10 @@ add_subdirectory(math) add_subdirectory(string) add_subdirectory(stdlib) +if(${LIBC_TARGET_OS} STREQUAL "linux") + add_subdirectory(sys) +endif() + if(NOT LLVM_LIBC_FULL_BUILD) return() endif() @@ -17,8 +21,6 @@ endif() # add_subdirectory(assert) # add_subdirectory(signal) add_subdirectory(stdio) -# TODO: Add this target conditional to the target OS. -add_subdirectory(sys) add_subdirectory(threads) add_subdirectory(time) add_subdirectory(unistd) diff --git a/libc/src/sys/mman/linux/mmap.cpp b/libc/src/sys/mman/linux/mmap.cpp index 0447ef129891..6ae482a8409a 100644 --- a/libc/src/sys/mman/linux/mmap.cpp +++ b/libc/src/sys/mman/linux/mmap.cpp @@ -8,12 +8,12 @@ #include "src/sys/mman/mmap.h" -#include "include/sys/syscall.h" // For syscall numbers. #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include "src/errno/llvmlibc_errno.h" +#include <errno.h> #include <linux/param.h> // For EXEC_PAGESIZE. +#include <sys/syscall.h> // For syscall numbers. namespace __llvm_libc { @@ -53,7 +53,7 @@ LLVM_LIBC_FUNCTION(void *, mmap, // return value corresponding to a location in the last page is an error // value. if (ret_val < 0 && ret_val > -EXEC_PAGESIZE) { - llvmlibc_errno = -ret_val; + errno = -ret_val; return MAP_FAILED; } diff --git a/libc/src/sys/mman/linux/munmap.cpp b/libc/src/sys/mman/linux/munmap.cpp index 7801a637f23f..2abeb3134242 100644 --- a/libc/src/sys/mman/linux/munmap.cpp +++ b/libc/src/sys/mman/linux/munmap.cpp @@ -8,10 +8,11 @@ #include "src/sys/mman/munmap.h" -#include "include/sys/syscall.h" // For syscall numbers. #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include "src/errno/llvmlibc_errno.h" + +#include <errno.h> +#include <sys/syscall.h> // For syscall numbers. namespace __llvm_libc { @@ -24,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, munmap, (void *addr, size_t size)) { // A negative return value indicates an error with the magnitude of the // value being the error code. if (ret_val < 0) { - llvmlibc_errno = -ret_val; + errno = -ret_val; return -1; } diff --git a/libc/src/sys/mman/mmap.h b/libc/src/sys/mman/mmap.h index c7aa404f6585..9f7fd8b9196b 100644 --- a/libc/src/sys/mman/mmap.h +++ b/libc/src/sys/mman/mmap.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SYS_MMAN_MMAP_H #define LLVM_LIBC_SRC_SYS_MMAN_MMAP_H -#include "include/sys/mman.h" // For size_t and off_t +#include <sys/mman.h> // For size_t and off_t namespace __llvm_libc { diff --git a/libc/src/sys/mman/munmap.h b/libc/src/sys/mman/munmap.h index ba272dc45e15..fa11d67823f6 100644 --- a/libc/src/sys/mman/munmap.h +++ b/libc/src/sys/mman/munmap.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SYS_MMAN_MUNMAP_H #define LLVM_LIBC_SRC_SYS_MMAN_MUNMAP_H -#include "include/sys/mman.h" // For size_t. +#include <sys/mman.h> // For size_t. namespace __llvm_libc { diff --git a/libc/src/unistd/linux/write.cpp b/libc/src/unistd/linux/write.cpp index 3554e3030943..0eaa632e5767 100644 --- a/libc/src/unistd/linux/write.cpp +++ b/libc/src/unistd/linux/write.cpp @@ -11,14 +11,15 @@ #include "include/sys/syscall.h" // For syscall numbers. #include "src/__support/OSUtil/syscall.h" // For internal syscall function. #include "src/__support/common.h" -#include "src/errno/llvmlibc_errno.h" + +#include <errno.h> namespace __llvm_libc { LLVM_LIBC_FUNCTION(ssize_t, write, (int fd, const void *buf, size_t count)) { long ret = __llvm_libc::syscall(SYS_write, fd, buf, count); if (ret < 0) { - llvmlibc_errno = -ret; + errno = -ret; return -1; } return ret; diff --git a/libc/test/ErrnoSetterMatcher.h b/libc/test/ErrnoSetterMatcher.h index 7f8311bfd5e6..007b2e6c0ae1 100644 --- a/libc/test/ErrnoSetterMatcher.h +++ b/libc/test/ErrnoSetterMatcher.h @@ -9,9 +9,10 @@ #ifndef LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H #define LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H -#include "src/errno/llvmlibc_errno.h" #include "utils/UnitTest/Test.h" +#include <errno.h> + namespace __llvm_libc { namespace testing { @@ -42,8 +43,8 @@ public: bool match(T Got) { ActualReturn = Got; - ActualErrno = llvmlibc_errno; - llvmlibc_errno = 0; + ActualErrno = errno; + errno = 0; return Got == ExpectedReturn && ActualErrno == ExpectedErrno; } }; diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt index d9b184e3790c..96bc7e6c2bc7 100644 --- a/libc/test/src/CMakeLists.txt +++ b/libc/test/src/CMakeLists.txt @@ -34,6 +34,10 @@ add_subdirectory(math) add_subdirectory(string) add_subdirectory(stdlib) +if(${LIBC_TARGET_OS} STREQUAL "linux") + add_subdirectory(sys) +endif() + if(NOT LLVM_LIBC_FULL_BUILD) return() endif() @@ -43,7 +47,6 @@ endif() # add_subdirectory(assert) # add_subdirectory(signal) add_subdirectory(stdio) -add_subdirectory(sys) add_subdirectory(threads) add_subdirectory(time) add_subdirectory(unistd) diff --git a/libc/test/src/sys/mman/linux/mmap_test.cpp b/libc/test/src/sys/mman/linux/mmap_test.cpp index 5311427ad522..a1a0a0879442 100644 --- a/libc/test/src/sys/mman/linux/mmap_test.cpp +++ b/libc/test/src/sys/mman/linux/mmap_test.cpp @@ -6,23 +6,23 @@ // //===----------------------------------------------------------------------===// -#include "include/errno.h" -#include "include/sys/mman.h" -#include "src/errno/llvmlibc_errno.h" #include "src/sys/mman/mmap.h" #include "src/sys/mman/munmap.h" #include "test/ErrnoSetterMatcher.h" #include "utils/UnitTest/Test.h" +#include <errno.h> +#include <sys/mman.h> + using __llvm_libc::testing::ErrnoSetterMatcher::Fails; using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; TEST(LlvmLibcMMapTest, NoError) { size_t alloc_size = 128; - llvmlibc_errno = 0; + errno = 0; void *addr = __llvm_libc::mmap(nullptr, alloc_size, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - EXPECT_EQ(0, llvmlibc_errno); + EXPECT_EQ(0, errno); EXPECT_NE(addr, MAP_FAILED); int *array = reinterpret_cast<int *>(addr); @@ -34,7 +34,7 @@ TEST(LlvmLibcMMapTest, NoError) { } TEST(LlvmLibcMMapTest, Error_InvalidSize) { - llvmlibc_errno = 0; + errno = 0; void *addr = __llvm_libc::mmap(nullptr, 0, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); EXPECT_THAT(addr, Fails(EINVAL, MAP_FAILED)); diff --git a/libc/test/src/unistd/write_test.cpp b/libc/test/src/unistd/write_test.cpp index 56243846083a..43914e87ef65 100644 --- a/libc/test/src/unistd/write_test.cpp +++ b/libc/test/src/unistd/write_test.cpp @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "include/errno.h" #include "src/unistd/write.h" #include "test/ErrnoSetterMatcher.h" #include "utils/UnitTest/Test.h" #include "utils/testutils/FDReader.h" +#include <errno.h> + TEST(LlvmLibcUniStd, WriteBasic) { using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; constexpr const char *HELLO = "hello"; |