[libc-commits] [libc] 72c6e4b - libc: Introduce calls to sysconf to get page size.
via libc-commits
libc-commits at lists.llvm.org
Wed Oct 15 12:31:30 PDT 2025
Author: Peter Collingbourne
Date: 2025-10-15T12:31:26-07:00
New Revision: 72c6e4b230ddb5ca85361e145e177245319b271e
URL: https://github.com/llvm/llvm-project/commit/72c6e4b230ddb5ca85361e145e177245319b271e
DIFF: https://github.com/llvm/llvm-project/commit/72c6e4b230ddb5ca85361e145e177245319b271e.diff
LOG: 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: https://github.com/llvm/llvm-project/pull/163462
Added:
Modified:
libc/test/src/sys/mman/linux/CMakeLists.txt
libc/test/src/sys/mman/linux/mincore_test.cpp
libc/test/src/sys/mman/linux/mlock_test.cpp
libc/test/src/sys/mman/linux/msync_test.cpp
libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
utils/bazel/llvm-project-overlay/libc/BUILD.bazel
utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel
Removed:
################################################################################
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index a362c1cf61cbc..32fee920321c0 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -99,6 +99,7 @@ add_libc_unittest(
libc.src.sys.mman.mincore
libc.src.sys.mman.mlock
libc.src.sys.mman.munlock
+ libc.src.unistd.sysconf
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
@@ -123,6 +124,7 @@ add_libc_unittest(
libc.src.sys.mman.mlockall
libc.src.sys.mman.munlockall
libc.src.sys.resource.getrlimit
+ libc.src.unistd.sysconf
libc.src.__support.OSUtil.osutil
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
@@ -144,6 +146,7 @@ add_libc_unittest(
libc.src.sys.mman.mincore
libc.src.sys.mman.mlock
libc.src.sys.mman.munlock
+ libc.src.unistd.sysconf
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
@@ -165,6 +168,7 @@ add_libc_unittest(
libc.src.sys.mman.munmap
libc.src.fcntl.open
libc.src.unistd.close
+ libc.src.unistd.sysconf
)
add_libc_unittest(
diff --git a/libc/test/src/sys/mman/linux/mincore_test.cpp b/libc/test/src/sys/mman/linux/mincore_test.cpp
index fb86252992def..1806bb1d671a2 100644
--- a/libc/test/src/sys/mman/linux/mincore_test.cpp
+++ b/libc/test/src/sys/mman/linux/mincore_test.cpp
@@ -12,6 +12,7 @@
#include "src/sys/mman/mmap.h"
#include "src/sys/mman/munlock.h"
#include "src/sys/mman/munmap.h"
+#include "src/unistd/sysconf.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
@@ -20,8 +21,7 @@ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
using LlvmLibcMincoreTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
-// TODO: Replace with sysconf call once the function is properly implemented.
-constexpr size_t PAGE_SIZE = 4096;
+const size_t PAGE_SIZE = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
TEST_F(LlvmLibcMincoreTest, UnMappedMemory) {
unsigned char vec;
diff --git a/libc/test/src/sys/mman/linux/mlock_test.cpp b/libc/test/src/sys/mman/linux/mlock_test.cpp
index f4a072ec18a31..0056ccf7f0b3d 100644
--- a/libc/test/src/sys/mman/linux/mlock_test.cpp
+++ b/libc/test/src/sys/mman/linux/mlock_test.cpp
@@ -22,14 +22,14 @@
#include "src/sys/mman/munlockall.h"
#include "src/sys/mman/munmap.h"
#include "src/sys/resource/getrlimit.h"
+#include "src/unistd/sysconf.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include <sys/syscall.h>
-// TODO: Replace with sysconf call once the function is properly implemented.
-constexpr size_t PAGE_SIZE = 4096;
+const size_t PAGE_SIZE = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
using LlvmLibcMlockTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
diff --git a/libc/test/src/sys/mman/linux/msync_test.cpp b/libc/test/src/sys/mman/linux/msync_test.cpp
index 764a67d02e3b1..bf9640d39ebd6 100644
--- a/libc/test/src/sys/mman/linux/msync_test.cpp
+++ b/libc/test/src/sys/mman/linux/msync_test.cpp
@@ -11,12 +11,12 @@
#include "src/sys/mman/msync.h"
#include "src/sys/mman/munlock.h"
#include "src/sys/mman/munmap.h"
+#include "src/unistd/sysconf.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-// TODO: Replace with sysconf call once the function is properly implemented.
-constexpr size_t PAGE_SIZE = 4096;
+const size_t PAGE_SIZE = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
using LlvmLibcMsyncTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
diff --git a/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp b/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
index 094bcb2c71427..08ffffe35ab2d 100644
--- a/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
+++ b/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
@@ -11,6 +11,7 @@
#include "src/sys/mman/munmap.h"
#include "src/sys/mman/remap_file_pages.h"
#include "src/unistd/close.h"
+#include "src/unistd/sysconf.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
@@ -18,8 +19,7 @@
#include <sys/mman.h>
#include <sys/stat.h> // For S_IRWXU
-// TODO: Replace with sysconf call once the function is properly implemented.
-constexpr size_t PAGE_SIZE = 4096;
+const size_t PAGE_SIZE = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 936bc1248b6ef..c7e3aa692b1fb 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -1501,6 +1501,21 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_osutil_linux_auxv",
+ hdrs = ["src/__support/OSUtil/linux/auxv.h"],
+ target_compatible_with = select({
+ "@platforms//os:linux": [],
+ "//conditions:default": ["@platforms//:incompatible"],
+ }),
+ deps = [
+ ":__support_common",
+ ":__support_osutil_syscall",
+ ":__support_threads_callonce",
+ ":hdr_fcntl_macros",
+ ],
+)
+
libc_support_library(
name = "__support_osutil_vdso",
hdrs = [
@@ -6336,6 +6351,19 @@ libc_function(
],
)
+# WARNING: NOT FULLY IMPLEMENTED, FOR TESTING USE ONLY
+libc_function(
+ name = "sysconf",
+ srcs = ["src/unistd/linux/sysconf.cpp"],
+ hdrs = ["src/unistd/sysconf.h"],
+ deps = [
+ ":__support_common",
+ ":__support_osutil_linux_auxv",
+ ":errno",
+ ":hdr_unistd_macros",
+ ],
+)
+
libc_function(
name = "write",
srcs = ["src/unistd/linux/write.cpp"],
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel
index e2c7f7a8bf60b..6de76e2357b70 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/sys/mman/BUILD.bazel
@@ -30,6 +30,7 @@ libc_test(
"//libc:mmap",
"//libc:munlock",
"//libc:munmap",
+ "//libc:sysconf",
],
)
@@ -48,6 +49,7 @@ libc_test(
"//libc:munlock",
"//libc:munlockall",
"//libc:munmap",
+ "//libc:sysconf",
],
)
@@ -89,6 +91,7 @@ libc_test(
"//libc:msync",
"//libc:munlock",
"//libc:munmap",
+ "//libc:sysconf",
],
)
@@ -111,6 +114,7 @@ libc_test(
"//libc:munmap",
"//libc:open",
"//libc:remap_file_pages",
+ "//libc:sysconf",
],
)
More information about the libc-commits
mailing list