Add BionicAllocator::memalign
Bionic needs this functionality to allocate a TLS segment with greater
than 16-byte alignment. For simplicity, this allocator only supports up
to one page of alignment.
The memory layout changes slightly when allocating an object of exactly
PAGE_SIZE alignment. Instead of allocating the page_info header at the
start of the page containing the pointer, it is allocated at the start
of the preceding page.
Bug: http://b/78026329
Test: linker-unit-tests{32,64}
Change-Id: I1c8d1cd7ca72d113bced5ee15ba8d831426b0081
diff --git a/libc/private/bionic_allocator.h b/libc/private/bionic_allocator.h
index 75cbd9d..c705ce4 100644
--- a/libc/private/bionic_allocator.h
+++ b/libc/private/bionic_allocator.h
@@ -105,13 +105,16 @@
public:
constexpr BionicAllocator() : allocators_(nullptr), allocators_buf_() {}
void* alloc(size_t size);
+ void* memalign(size_t align, size_t size);
// Note that this implementation of realloc never shrinks allocation
void* realloc(void* ptr, size_t size);
void free(void* ptr);
private:
- void* alloc_mmap(size_t size);
- page_info* get_page_info(void* ptr);
+ void* alloc_mmap(size_t align, size_t size);
+ inline void* alloc_impl(size_t align, size_t size);
+ inline page_info* get_page_info_unchecked(void* ptr);
+ inline page_info* get_page_info(void* ptr);
BionicSmallObjectAllocator* get_small_object_allocator(uint32_t type);
void initialize_allocators();