From cae21a9b53a10f0cba79bf6783c4a5af16228fed Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Mon, 5 Feb 2018 18:14:55 -0800 Subject: Add aligned_alloc to libc. Bug: 72969374 Test: Bionic unit tests pass. Test: Malloc debug unit tests pass. Change-Id: I235985bbc638855d94249c97c98f14ab2924bda0 (cherry picked from commit d69ee59594088c0d92ba9273188ef53ea5e6cd6a) --- libc/malloc_debug/malloc_debug.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libc/malloc_debug/malloc_debug.cpp') diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp index a2ada2f2e..ecfbd7112 100644 --- a/libc/malloc_debug/malloc_debug.cpp +++ b/libc/malloc_debug/malloc_debug.cpp @@ -77,6 +77,7 @@ void debug_free_malloc_leak_info(uint8_t* info); size_t debug_malloc_usable_size(void* pointer); void* debug_malloc(size_t size); void debug_free(void* pointer); +void* debug_aligned_alloc(size_t alignment, size_t size); void* debug_memalign(size_t alignment, size_t bytes); void* debug_realloc(void* pointer, size_t bytes); void* debug_calloc(size_t nmemb, size_t bytes); @@ -669,6 +670,17 @@ int debug_mallopt(int param, int value) { return g_dispatch->mallopt(param, value); } +void* debug_aligned_alloc(size_t alignment, size_t size) { + if (DebugCallsDisabled()) { + return g_dispatch->aligned_alloc(alignment, size); + } + if (!powerof2(alignment)) { + errno = EINVAL; + return nullptr; + } + return debug_memalign(alignment, size); +} + int debug_posix_memalign(void** memptr, size_t alignment, size_t size) { if (DebugCallsDisabled()) { return g_dispatch->posix_memalign(memptr, alignment, size); -- cgit v1.2.3