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

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Tue Jan 23 09:18:50 PST 2024


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

>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 1/2] [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) {

>From 2ed12d356ba01b2a9c7def7345166b59475a4192 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Tue, 23 Jan 2024 12:18:42 -0500
Subject: [PATCH 2/2] address CR on style

---
 libc/src/unistd/linux/sysconf.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/src/unistd/linux/sysconf.cpp b/libc/src/unistd/linux/sysconf.cpp
index 16ca8e6a27d3ce..d4577c8d3d7690 100644
--- a/libc/src/unistd/linux/sysconf.cpp
+++ b/libc/src/unistd/linux/sysconf.cpp
@@ -19,9 +19,9 @@ namespace LIBC_NAMESPACE {
 
 LLVM_LIBC_FUNCTION(long, sysconf, (int name)) {
   long ret = 0;
-  if (name == _SC_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