Merge "bionic: max_android_page_size to 16384" into main am: 5dd8ce7284 am: 8e73c1fe6b

Original change: https://android-review.googlesource.com/c/platform/bionic/+/3063230

Change-Id: I74180ef8083100567fd0a4099ecc490f8e5a4d51
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Steven Moreland 2024-05-22 22:22:14 +00:00 committed by Automerger Merge Worker
commit 9ac6de1863
4 changed files with 13 additions and 11 deletions

View file

@ -240,7 +240,7 @@ __LIBC_HIDDEN__ void pthread_key_clean_all(void);
// On LP64, we could use more but there's no obvious advantage to doing
// so, and the various media processes use RLIMIT_AS as a way to limit
// the amount of allocation they'll do.
#define PTHREAD_GUARD_SIZE max_page_size()
#define PTHREAD_GUARD_SIZE max_android_page_size()
// SIGSTKSZ (8KiB) is not big enough.
// An snprintf to a stack buffer of size PATH_MAX consumes ~7KiB of stack.

View file

@ -32,11 +32,13 @@ inline size_t page_size() {
#endif
}
constexpr size_t max_page_size() {
// The maximum page size supported on any Android device. As
// of API level 35, this is limited by ART.
constexpr size_t max_android_page_size() {
#if defined(PAGE_SIZE)
return PAGE_SIZE;
#else
return 65536;
return 16384;
#endif
}

View file

@ -30,11 +30,11 @@
template <typename T>
union WriteProtectedContents {
T value;
char padding[max_page_size()];
char padding[max_android_page_size()];
WriteProtectedContents() = default;
BIONIC_DISALLOW_COPY_AND_ASSIGN(WriteProtectedContents);
} __attribute__((aligned(max_page_size())));
} __attribute__((aligned(max_android_page_size())));
// Write protected wrapper class that aligns its contents to a page boundary,
// and sets the memory protection to be non-writable, except when being modified
@ -42,8 +42,8 @@ union WriteProtectedContents {
template <typename T>
class WriteProtected {
public:
static_assert(sizeof(T) < max_page_size(),
"WriteProtected only supports contents up to max_page_size()");
static_assert(sizeof(T) < max_android_page_size(),
"WriteProtected only supports contents up to max_android_page_size()");
WriteProtected() = default;
BIONIC_DISALLOW_COPY_AND_ASSIGN(WriteProtected);
@ -89,7 +89,7 @@ class WriteProtected {
// ourselves.
addr = untag_address(addr);
#endif
if (mprotect(reinterpret_cast<void*>(addr), max_page_size(), prot) == -1) {
if (mprotect(reinterpret_cast<void*>(addr), max_android_page_size(), prot) == -1) {
async_safe_fatal("WriteProtected mprotect %x failed: %s", prot, strerror(errno));
}
}

View file

@ -26,15 +26,15 @@ __attribute__((__weak__, visibility("default"))) extern "C" void __loader_cfi_fa
// dlopen/dlclose.
static struct {
uintptr_t v;
char padding[max_page_size() - sizeof(v)];
} shadow_base_storage alignas(max_page_size());
char padding[max_android_page_size() - sizeof(v)];
} shadow_base_storage alignas(max_android_page_size());
// __cfi_init is called by the loader as soon as the shadow is mapped. This may happen very early
// during startup, before libdl.so global constructors, and, on i386, even before __libc_sysinfo is
// initialized. This function should not do any system calls.
extern "C" uintptr_t* __cfi_init(uintptr_t shadow_base) {
shadow_base_storage.v = shadow_base;
static_assert(sizeof(shadow_base_storage) == max_page_size(), "");
static_assert(sizeof(shadow_base_storage) == max_android_page_size(), "");
return &shadow_base_storage.v;
}