From 8401230be6a396b10659de62639792f149daf811 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Sat, 27 Apr 2024 01:17:21 +0000 Subject: [PATCH] bionic: max_android_page_size to 16384 The maximum page size Android supports now is 16384, and Art only supports 16kB, so we can save a bit of space. Bug: 332556665 Test: N/A Change-Id: I23df607bcc5cf9e96d7b6a66169413cd1a883f7e --- libc/bionic/pthread_internal.h | 2 +- libc/platform/bionic/page.h | 6 ++++-- libc/private/WriteProtected.h | 10 +++++----- libdl/libdl_cfi.cpp | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h index 091f711eb..c2abdea29 100644 --- a/libc/bionic/pthread_internal.h +++ b/libc/bionic/pthread_internal.h @@ -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. diff --git a/libc/platform/bionic/page.h b/libc/platform/bionic/page.h index 65faba4f0..4dbe4baea 100644 --- a/libc/platform/bionic/page.h +++ b/libc/platform/bionic/page.h @@ -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 } diff --git a/libc/private/WriteProtected.h b/libc/private/WriteProtected.h index bbe35e529..f26912546 100644 --- a/libc/private/WriteProtected.h +++ b/libc/private/WriteProtected.h @@ -30,11 +30,11 @@ template 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 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(addr), max_page_size(), prot) == -1) { + if (mprotect(reinterpret_cast(addr), max_android_page_size(), prot) == -1) { async_safe_fatal("WriteProtected mprotect %x failed: %s", prot, strerror(errno)); } } diff --git a/libdl/libdl_cfi.cpp b/libdl/libdl_cfi.cpp index 23cd7f53a..8adc342ac 100644 --- a/libdl/libdl_cfi.cpp +++ b/libdl/libdl_cfi.cpp @@ -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; }