[libc-commits] [libc] [llvm] [libc] add basic arena allocator (PR #121173)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Tue Jan 7 09:44:43 PST 2025
================
@@ -0,0 +1,29 @@
+//===-- Implementation of getpagesize -------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/unistd/getpagesize.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/page_size.h"
+#include "src/sys/auxv/getauxval.h"
+#include "src/unistd/sysconf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, getpagesize, ()) {
+#if LIBC_PAGE_SIZE == LIBC_PAGE_SIZE_SYSTEM
+ int r = (int)LIBC_NAMESPACE::getauxval(AT_PAGESZ);
+ if (r == 0)
+ return (int)LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
+ return r;
+#else
+ return LIBC_PAGE_SIZE;
+#endif
----------------
nickdesaulniers wrote:
> Why? There's malloc implementations out there which support hardcoded page sizes.
And there's programs that just hardcode the page size and don't use `getpagesize` or `sysconf(_SC_PAGESIZE)` and those programs wind up with portability issues when they join the 21st century where the page size isn't 4k.
https://github.com/llvm/llvm-project/pull/121173
More information about the libc-commits
mailing list