[libc-commits] [libc] 0cf20c2 - [libc] fix sysconf (#79159)

via libc-commits libc-commits at lists.llvm.org
Tue Jan 23 10:31:52 PST 2024


Author: Schrodinger ZHU Yifan
Date: 2024-01-23T13:31:48-05:00
New Revision: 0cf20c2971375ea200035f2e99bd81bd00f5f27d

URL: https://github.com/llvm/llvm-project/commit/0cf20c2971375ea200035f2e99bd81bd00f5f27d
DIFF: https://github.com/llvm/llvm-project/commit/0cf20c2971375ea200035f2e99bd81bd00f5f27d.diff

LOG: [libc] fix sysconf (#79159)

Apply previously discussed fix for `sysconf`

Added: 
    

Modified: 
    libc/src/unistd/linux/CMakeLists.txt
    libc/src/unistd/linux/sysconf.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index ab9eca19e650834..42190079141b067 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -402,7 +402,9 @@ add_entrypoint_object(
     ../sysconf.h
   DEPENDS
     libc.include.unistd
+    libc.include.sys_auxv
     libc.src.errno.errno
+    libc.src.sys.auxv.getauxval
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/unistd/linux/sysconf.cpp b/libc/src/unistd/linux/sysconf.cpp
index b16e15551fc7889..d4577c8d3d7690b 100644
--- a/libc/src/unistd/linux/sysconf.cpp
+++ b/libc/src/unistd/linux/sysconf.cpp
@@ -11,17 +11,17 @@
 #include "src/__support/common.h"
 
 #include "src/errno/libc_errno.h"
-#include <linux/param.h> // For EXEC_PAGESIZE.
+#include "src/sys/auxv/getauxval.h"
+#include <sys/auxv.h>
 #include <unistd.h>
 
 namespace LIBC_NAMESPACE {
 
 LLVM_LIBC_FUNCTION(long, sysconf, (int name)) {
   long ret = 0;
-  if (name == _SC_PAGESIZE) {
-    // TODO: get this information from the auxvector.
-    return EXEC_PAGESIZE;
-  }
+  if (name == _SC_PAGESIZE)
+    return static_cast<long>(getauxval(AT_PAGESZ));
+
   // TODO: Complete the rest of the sysconf options.
   if (ret < 0) {
     libc_errno = EINVAL;


        


More information about the libc-commits mailing list