Skip to content

Commit 72c6e4b

Browse files
authored
libc: Introduce calls to sysconf to get page size.
sysconf(_SC_PAGESIZE) is implemented now. Reviewers: michaelrj-google, aaronmondal, rupprecht, keith Reviewed By: michaelrj-google Pull Request: #163462
1 parent 422c0f3 commit 72c6e4b

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

libc/test/src/sys/mman/linux/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ add_libc_unittest(
9999
libc.src.sys.mman.mincore
100100
libc.src.sys.mman.mlock
101101
libc.src.sys.mman.munlock
102+
libc.src.unistd.sysconf
102103
libc.test.UnitTest.ErrnoCheckingTest
103104
libc.test.UnitTest.ErrnoSetterMatcher
104105
)
@@ -123,6 +124,7 @@ add_libc_unittest(
123124
libc.src.sys.mman.mlockall
124125
libc.src.sys.mman.munlockall
125126
libc.src.sys.resource.getrlimit
127+
libc.src.unistd.sysconf
126128
libc.src.__support.OSUtil.osutil
127129
libc.test.UnitTest.ErrnoCheckingTest
128130
libc.test.UnitTest.ErrnoSetterMatcher
@@ -144,6 +146,7 @@ add_libc_unittest(
144146
libc.src.sys.mman.mincore
145147
libc.src.sys.mman.mlock
146148
libc.src.sys.mman.munlock
149+
libc.src.unistd.sysconf
147150
libc.test.UnitTest.ErrnoCheckingTest
148151
libc.test.UnitTest.ErrnoSetterMatcher
149152
)
@@ -165,6 +168,7 @@ add_libc_unittest(
165168
libc.src.sys.mman.munmap
166169
libc.src.fcntl.open
167170
libc.src.unistd.close
171+
libc.src.unistd.sysconf
168172
)
169173

170174
add_libc_unittest(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "src/sys/mman/mmap.h"
1313
#include "src/sys/mman/munlock.h"
1414
#include "src/sys/mman/munmap.h"
15+
#include "src/unistd/sysconf.h"
1516
#include "test/UnitTest/ErrnoCheckingTest.h"
1617
#include "test/UnitTest/ErrnoSetterMatcher.h"
1718
#include "test/UnitTest/Test.h"
@@ -20,8 +21,7 @@ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
2021
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
2122
using LlvmLibcMincoreTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
2223

23-
// TODO: Replace with sysconf call once the function is properly implemented.
24-
constexpr size_t PAGE_SIZE = 4096;
24+
const size_t PAGE_SIZE = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
2525

2626
TEST_F(LlvmLibcMincoreTest, UnMappedMemory) {
2727
unsigned char vec;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
#include "src/sys/mman/munlockall.h"
2323
#include "src/sys/mman/munmap.h"
2424
#include "src/sys/resource/getrlimit.h"
25+
#include "src/unistd/sysconf.h"
2526
#include "test/UnitTest/ErrnoCheckingTest.h"
2627
#include "test/UnitTest/ErrnoSetterMatcher.h"
2728
#include "test/UnitTest/Test.h"
2829

2930
#include <sys/syscall.h>
3031

31-
// TODO: Replace with sysconf call once the function is properly implemented.
32-
constexpr size_t PAGE_SIZE = 4096;
32+
const size_t PAGE_SIZE = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
3333

3434
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
3535
using LlvmLibcMlockTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#include "src/sys/mman/msync.h"
1212
#include "src/sys/mman/munlock.h"
1313
#include "src/sys/mman/munmap.h"
14+
#include "src/unistd/sysconf.h"
1415
#include "test/UnitTest/ErrnoCheckingTest.h"
1516
#include "test/UnitTest/ErrnoSetterMatcher.h"
1617
#include "test/UnitTest/Test.h"
1718

18-
// TODO: Replace with sysconf call once the function is properly implemented.
19-
constexpr size_t PAGE_SIZE = 4096;
19+
const size_t PAGE_SIZE = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
2020

2121
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
2222
using LlvmLibcMsyncTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
#include "src/sys/mman/munmap.h"
1212
#include "src/sys/mman/remap_file_pages.h"
1313
#include "src/unistd/close.h"
14+
#include "src/unistd/sysconf.h"
1415
#include "test/UnitTest/ErrnoCheckingTest.h"
1516
#include "test/UnitTest/ErrnoSetterMatcher.h"
1617
#include "test/UnitTest/Test.h"
1718

1819
#include <sys/mman.h>
1920
#include <sys/stat.h> // For S_IRWXU
2021

21-
// TODO: Replace with sysconf call once the function is properly implemented.
22-
constexpr size_t PAGE_SIZE = 4096;
22+
const size_t PAGE_SIZE = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
2323

2424
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
2525
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,21 @@ libc_support_library(
15011501
],
15021502
)
15031503

1504+
libc_support_library(
1505+
name = "__support_osutil_linux_auxv",
1506+
hdrs = ["src/__support/OSUtil/linux/auxv.h"],
1507+
target_compatible_with = select({
1508+
"@platforms//os:linux": [],
1509+
"//conditions:default": ["@platforms//:incompatible"],
1510+
}),
1511+
deps = [
1512+
":__support_common",
1513+
":__support_osutil_syscall",
1514+
":__support_threads_callonce",
1515+
":hdr_fcntl_macros",
1516+
],
1517+
)
1518+
15041519
libc_support_library(
15051520
name = "__support_osutil_vdso",
15061521
hdrs = [
@@ -6336,6 +6351,19 @@ libc_function(
63366351
],
63376352
)
63386353

6354+
# WARNING: NOT FULLY IMPLEMENTED, FOR TESTING USE ONLY
6355+
libc_function(
6356+
name = "sysconf",
6357+
srcs = ["src/unistd/linux/sysconf.cpp"],
6358+
hdrs = ["src/unistd/sysconf.h"],
6359+
deps = [
6360+
":__support_common",
6361+
":__support_osutil_linux_auxv",
6362+
":errno",
6363+
":hdr_unistd_macros",
6364+
],
6365+
)
6366+
63396367
libc_function(
63406368
name = "write",
63416369
srcs = ["src/unistd/linux/write.cpp"],

utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ libc_test(
3030
"//libc:mmap",
3131
"//libc:munlock",
3232
"//libc:munmap",
33+
"//libc:sysconf",
3334
],
3435
)
3536

@@ -48,6 +49,7 @@ libc_test(
4849
"//libc:munlock",
4950
"//libc:munlockall",
5051
"//libc:munmap",
52+
"//libc:sysconf",
5153
],
5254
)
5355

@@ -89,6 +91,7 @@ libc_test(
8991
"//libc:msync",
9092
"//libc:munlock",
9193
"//libc:munmap",
94+
"//libc:sysconf",
9295
],
9396
)
9497

@@ -111,6 +114,7 @@ libc_test(
111114
"//libc:munmap",
112115
"//libc:open",
113116
"//libc:remap_file_pages",
117+
"//libc:sysconf",
114118
],
115119
)
116120

0 commit comments

Comments
 (0)