From 9ae59c02ca68da5bb45152c85c4cab6fd6f7aba2 Mon Sep 17 00:00:00 2001 From: Bernhard Rosenkraenzer Date: Wed, 18 Sep 2013 23:29:08 +0200 Subject: [PATCH] Declare __page_shift and __page_size with C linkage. __page_shift and __page_size were accidentally declared in unistd.h with C linkage - their implementation needs to use the same linkage. Going forward, though, let's stop the inlining madness and let's kill the non-standard __getpageshift(). This patch takes getpagesize(3) out of line and removes __getpageshift but fixes __page_shift and __page_size for backwards binary compatibility. Change-Id: I35ed66a08989ced1db422eb03e4d154a5d6b5bda Signed-off-by: Bernhard Rosenkraenzer --- libc/bionic/libc_init_common.cpp | 4 ---- libc/bionic/stubs.cpp | 12 ++++++++++++ libc/include/unistd.h | 9 +-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp index f5cb1e53b..714d0bc64 100644 --- a/libc/bionic/libc_init_common.cpp +++ b/libc/bionic/libc_init_common.cpp @@ -60,10 +60,6 @@ char** environ; // Declared in . uintptr_t __stack_chk_guard = 0; -// Declared in . -unsigned int __page_size = PAGE_SIZE; -unsigned int __page_shift = PAGE_SHIFT; - static size_t get_main_thread_stack_size() { rlimit stack_limit; int rlimit_result = getrlimit(RLIMIT_STACK, &stack_limit); diff --git a/libc/bionic/stubs.cpp b/libc/bionic/stubs.cpp index e8411b774..56f5c045f 100644 --- a/libc/bionic/stubs.cpp +++ b/libc/bionic/stubs.cpp @@ -469,3 +469,15 @@ void setusershell() { void endusershell() { UNIMPLEMENTED; } + +// Portable code should use sysconf(_SC_PAGESIZE) directly instead. +int getpagesize() { + return sysconf(_SC_PAGESIZE); +} + +// These were accidentally declared in because we stupidly used to inline +// getpagesize() and __getpageshift(). Needed for backwards compatibility with old NDK apps. +extern "C" { + unsigned int __page_size = PAGE_SIZE; + unsigned int __page_shift = PAGE_SHIFT; +} diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 98970aee3..61d3d6edc 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -170,14 +170,7 @@ extern int ttyname_r(int, char*, size_t); extern int acct(const char* filepath); -static __inline__ int getpagesize(void) { - extern unsigned int __page_size; - return __page_size; -} -static __inline__ int __getpageshift(void) { - extern unsigned int __page_shift; - return __page_shift; -} +int getpagesize(void); extern int sysconf(int name); -- 2.11.0