Skip to content

Commit 134e9d1

Browse files
author
Siva Chandra Reddy
committed
[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.
1 parent d345ce6 commit 134e9d1

File tree

14 files changed

+37
-34
lines changed

14 files changed

+37
-34
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,11 @@ set(TARGET_LIBM_ENTRYPOINTS
169169
libc.src.math.trunc
170170
libc.src.math.truncf
171171
libc.src.math.truncl
172-
)
173172

174-
if(LLVM_LIBC_FULL_BUILD)
175-
list(APPEND TARGET_LIBC_ENTRYPOINTS
176173
# sys/mman.h entrypoints
177174
libc.src.sys.mman.mmap
178175
libc.src.sys.mman.munmap
179-
)
180-
endif()
176+
)
181177

182178
set(TARGET_LLVMLIBC_ENTRYPOINTS
183179
${TARGET_LIBC_ENTRYPOINTS}

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ set(TARGET_LIBC_ENTRYPOINTS
7575
libc.src.stdlib.strtoll
7676
libc.src.stdlib.strtoul
7777
libc.src.stdlib.strtoull
78+
79+
# sys/mman.h entrypoints
80+
libc.src.sys.mman.mmap
81+
libc.src.sys.mman.munmap
7882
)
7983

8084
set(TARGET_LIBM_ENTRYPOINTS
@@ -203,10 +207,6 @@ if(LLVM_LIBC_FULL_BUILD)
203207
# libc.src.signal.sigfillset
204208
# libc.src.signal.signal
205209

206-
# sys/mman.h entrypoints
207-
libc.src.sys.mman.mmap
208-
libc.src.sys.mman.munmap
209-
210210
# threads.h entrypoints
211211
libc.src.threads.call_once
212212
libc.src.threads.cnd_broadcast

libc/loader/linux/x86_64/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_loader_object(
77
libc.include.sys_syscall
88
libc.src.__support.OSUtil.osutil
99
libc.src.string.memcpy
10-
libc.src.sys.mman.mmap
1110
COMPILE_OPTIONS
1211
-fno-omit-frame-pointer
1312
-ffreestanding # To avoid compiler warnings about calling the main function.

libc/loader/linux/x86_64/start.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "include/sys/syscall.h"
1212
#include "src/__support/OSUtil/syscall.h"
1313
#include "src/string/memcpy.h"
14-
#include "src/sys/mman/mmap.h"
1514

1615
#include <asm/prctl.h>
1716
#include <linux/auxvec.h>

libc/src/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ add_subdirectory(math)
88
add_subdirectory(string)
99
add_subdirectory(stdlib)
1010

11+
if(${LIBC_TARGET_OS} STREQUAL "linux")
12+
add_subdirectory(sys)
13+
endif()
14+
1115
if(NOT LLVM_LIBC_FULL_BUILD)
1216
return()
1317
endif()
@@ -17,8 +21,6 @@ endif()
1721
# add_subdirectory(assert)
1822
# add_subdirectory(signal)
1923
add_subdirectory(stdio)
20-
# TODO: Add this target conditional to the target OS.
21-
add_subdirectory(sys)
2224
add_subdirectory(threads)
2325
add_subdirectory(time)
2426
add_subdirectory(unistd)

libc/src/sys/mman/linux/mmap.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
#include "src/sys/mman/mmap.h"
1010

11-
#include "include/sys/syscall.h" // For syscall numbers.
1211
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1312
#include "src/__support/common.h"
14-
#include "src/errno/llvmlibc_errno.h"
1513

14+
#include <errno.h>
1615
#include <linux/param.h> // For EXEC_PAGESIZE.
16+
#include <sys/syscall.h> // For syscall numbers.
1717

1818
namespace __llvm_libc {
1919

@@ -53,7 +53,7 @@ LLVM_LIBC_FUNCTION(void *, mmap,
5353
// return value corresponding to a location in the last page is an error
5454
// value.
5555
if (ret_val < 0 && ret_val > -EXEC_PAGESIZE) {
56-
llvmlibc_errno = -ret_val;
56+
errno = -ret_val;
5757
return MAP_FAILED;
5858
}
5959

libc/src/sys/mman/linux/munmap.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
#include "src/sys/mman/munmap.h"
1010

11-
#include "include/sys/syscall.h" // For syscall numbers.
1211
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1312
#include "src/__support/common.h"
14-
#include "src/errno/llvmlibc_errno.h"
13+
14+
#include <errno.h>
15+
#include <sys/syscall.h> // For syscall numbers.
1516

1617
namespace __llvm_libc {
1718

@@ -24,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, munmap, (void *addr, size_t size)) {
2425
// A negative return value indicates an error with the magnitude of the
2526
// value being the error code.
2627
if (ret_val < 0) {
27-
llvmlibc_errno = -ret_val;
28+
errno = -ret_val;
2829
return -1;
2930
}
3031

libc/src/sys/mman/mmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_SYS_MMAN_MMAP_H
1010
#define LLVM_LIBC_SRC_SYS_MMAN_MMAP_H
1111

12-
#include "include/sys/mman.h" // For size_t and off_t
12+
#include <sys/mman.h> // For size_t and off_t
1313

1414
namespace __llvm_libc {
1515

libc/src/sys/mman/munmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_SYS_MMAN_MUNMAP_H
1010
#define LLVM_LIBC_SRC_SYS_MMAN_MUNMAP_H
1111

12-
#include "include/sys/mman.h" // For size_t.
12+
#include <sys/mman.h> // For size_t.
1313

1414
namespace __llvm_libc {
1515

libc/src/unistd/linux/write.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
#include "include/sys/syscall.h" // For syscall numbers.
1212
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1313
#include "src/__support/common.h"
14-
#include "src/errno/llvmlibc_errno.h"
14+
15+
#include <errno.h>
1516

1617
namespace __llvm_libc {
1718

1819
LLVM_LIBC_FUNCTION(ssize_t, write, (int fd, const void *buf, size_t count)) {
1920
long ret = __llvm_libc::syscall(SYS_write, fd, buf, count);
2021
if (ret < 0) {
21-
llvmlibc_errno = -ret;
22+
errno = -ret;
2223
return -1;
2324
}
2425
return ret;

libc/test/ErrnoSetterMatcher.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#ifndef LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H
1010
#define LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H
1111

12-
#include "src/errno/llvmlibc_errno.h"
1312
#include "utils/UnitTest/Test.h"
1413

14+
#include <errno.h>
15+
1516
namespace __llvm_libc {
1617
namespace testing {
1718

@@ -42,8 +43,8 @@ template <typename T> class ErrnoSetterMatcher : public Matcher<T> {
4243

4344
bool match(T Got) {
4445
ActualReturn = Got;
45-
ActualErrno = llvmlibc_errno;
46-
llvmlibc_errno = 0;
46+
ActualErrno = errno;
47+
errno = 0;
4748
return Got == ExpectedReturn && ActualErrno == ExpectedErrno;
4849
}
4950
};

libc/test/src/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ add_subdirectory(math)
3434
add_subdirectory(string)
3535
add_subdirectory(stdlib)
3636

37+
if(${LIBC_TARGET_OS} STREQUAL "linux")
38+
add_subdirectory(sys)
39+
endif()
40+
3741
if(NOT LLVM_LIBC_FULL_BUILD)
3842
return()
3943
endif()
@@ -43,7 +47,6 @@ endif()
4347
# add_subdirectory(assert)
4448
# add_subdirectory(signal)
4549
add_subdirectory(stdio)
46-
add_subdirectory(sys)
4750
add_subdirectory(threads)
4851
add_subdirectory(time)
4952
add_subdirectory(unistd)

libc/test/src/sys/mman/linux/mmap_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "include/errno.h"
10-
#include "include/sys/mman.h"
11-
#include "src/errno/llvmlibc_errno.h"
129
#include "src/sys/mman/mmap.h"
1310
#include "src/sys/mman/munmap.h"
1411
#include "test/ErrnoSetterMatcher.h"
1512
#include "utils/UnitTest/Test.h"
1613

14+
#include <errno.h>
15+
#include <sys/mman.h>
16+
1717
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
1818
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
1919

2020
TEST(LlvmLibcMMapTest, NoError) {
2121
size_t alloc_size = 128;
22-
llvmlibc_errno = 0;
22+
errno = 0;
2323
void *addr = __llvm_libc::mmap(nullptr, alloc_size, PROT_READ,
2424
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
25-
EXPECT_EQ(0, llvmlibc_errno);
25+
EXPECT_EQ(0, errno);
2626
EXPECT_NE(addr, MAP_FAILED);
2727

2828
int *array = reinterpret_cast<int *>(addr);
@@ -34,7 +34,7 @@ TEST(LlvmLibcMMapTest, NoError) {
3434
}
3535

3636
TEST(LlvmLibcMMapTest, Error_InvalidSize) {
37-
llvmlibc_errno = 0;
37+
errno = 0;
3838
void *addr = __llvm_libc::mmap(nullptr, 0, PROT_READ,
3939
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
4040
EXPECT_THAT(addr, Fails(EINVAL, MAP_FAILED));

libc/test/src/unistd/write_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "include/errno.h"
109
#include "src/unistd/write.h"
1110
#include "test/ErrnoSetterMatcher.h"
1211
#include "utils/UnitTest/Test.h"
1312
#include "utils/testutils/FDReader.h"
1413

14+
#include <errno.h>
15+
1516
TEST(LlvmLibcUniStd, WriteBasic) {
1617
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
1718
constexpr const char *HELLO = "hello";

0 commit comments

Comments
 (0)