[libc][NFC] Move sys/mman entrypoints to the default build configs.
Specifically, mmap and munmap have been moved to the default build list of entrypoints. To support this, certain deps and includes have been adjusted. The use of errno in some cases has been updated.
This commit is contained in:
parent
d345ce65ff
commit
134e9d1914
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue
Block a user