[libc-commits] [libc] [libc] fix sysconf (PR #79159)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Tue Jan 23 07:58:53 PST 2024


https://github.com/SchrodingerZhu created https://github.com/llvm/llvm-project/pull/79159

Reland previous fix for `sysconf`

>From d0e293901a9279290be0315e8f67adfe3928b4a2 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Tue, 23 Jan 2024 10:56:50 -0500
Subject: [PATCH] [libc] fix sysconf

---
 libc/src/unistd/linux/CMakeLists.txt | 2 ++
 libc/src/unistd/linux/sysconf.cpp    | 6 +++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index ab9eca19e65083..42190079141b06 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 b16e15551fc788..16ca8e6a27d3ce 100644
--- a/libc/src/unistd/linux/sysconf.cpp
+++ b/libc/src/unistd/linux/sysconf.cpp
@@ -11,7 +11,8 @@
 #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 {
@@ -19,8 +20,7 @@ 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;
+    return static_cast<long>(getauxval(AT_PAGESZ));
   }
   // TODO: Complete the rest of the sysconf options.
   if (ret < 0) {



More information about the libc-commits mailing list