Skip to content

Commit a6f7cb5

Browse files
[Support] Prefer AUX vector for page size (llvm#126863)
Prefers the page size to come from the AUX vector, `getpagesize` is removed from POSIX.1-2001. Also throws in a couple asserts to ensure the page size is a valid value.
1 parent 51d8255 commit a6f7cb5

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

llvm/cmake/config-ix.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ if (ANDROID OR CYGWIN OR CMAKE_SYSTEM_NAME MATCHES "AIX|DragonFly|FreeBSD|Haiku|
2121
set(HAVE_MACH_MACH_H 0)
2222
set(HAVE_MALLOC_MALLOC_H 0)
2323
set(HAVE_PTHREAD_H 1)
24+
set(HAVE_SYS_AUXV_H 1)
2425
set(HAVE_SYS_MMAN_H 1)
2526
set(HAVE_SYSEXITS_H 1)
2627
set(HAVE_UNISTD_H 1)
@@ -52,6 +53,7 @@ else()
5253
check_include_file(mach/mach.h HAVE_MACH_MACH_H)
5354
check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
5455
check_include_file(pthread.h HAVE_PTHREAD_H)
56+
check_include_file(sys/auxv.h HAVE_SYS_AUXV_H)
5557
check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
5658
check_include_file(sysexits.h HAVE_SYSEXITS_H)
5759
check_include_file(unistd.h HAVE_UNISTD_H)

llvm/include/llvm/Config/config.h.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,6 @@
295295

296296
#cmakedefine HAVE_BUILTIN_THREAD_POINTER ${HAVE_BUILTIN_THREAD_POINTER}
297297

298+
#cmakedefine HAVE_SYS_AUXV_H ${HAVE_SYS_AUXV_H}
299+
298300
#endif

llvm/lib/Support/Unix/Process.inc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#ifdef HAVE_MALLOC_MALLOC_H
3232
#include <malloc/malloc.h>
3333
#endif
34+
#ifdef HAVE_SYS_AUXV_H
35+
#include <sys/auxv.h>
36+
#endif
3437

3538
//===----------------------------------------------------------------------===//
3639
//=== WARNING: Implementation here must contain only generic UNIX code that
@@ -63,7 +66,9 @@ Process::Pid Process::getProcessId() {
6366
// On Cygwin, getpagesize() returns 64k(AllocationGranularity) and
6467
// offset in mmap(3) should be aligned to the AllocationGranularity.
6568
Expected<unsigned> Process::getPageSize() {
66-
#if defined(HAVE_GETPAGESIZE)
69+
#if defined(HAVE_SYS_AUXV_H)
70+
static const int page_size = ::getauxval(AT_PAGESZ);
71+
#elif defined(HAVE_GETPAGESIZE)
6772
static const int page_size = ::getpagesize();
6873
#elif defined(HAVE_SYSCONF)
6974
static long page_size = ::sysconf(_SC_PAGE_SIZE);
@@ -73,6 +78,8 @@ Expected<unsigned> Process::getPageSize() {
7378
if (page_size == -1)
7479
return errorCodeToError(errnoAsErrorCode());
7580

81+
assert(page_size > 0 && "Page size cannot be 0");
82+
assert((page_size % 1024) == 0 && "Page size must be aligned by 1024");
7683
return static_cast<unsigned>(page_size);
7784
}
7885

0 commit comments

Comments
 (0)