Add aligned_alloc to libc.
Bug: 72969374
Test: Bionic unit tests pass.
Test: Malloc debug unit tests pass.
Change-Id: I235985bbc638855d94249c97c98f14ab2924bda0
diff --git a/libc/bionic/malloc_common.cpp b/libc/bionic/malloc_common.cpp
index 1f201d1..940c418 100644
--- a/libc/bionic/malloc_common.cpp
+++ b/libc/bionic/malloc_common.cpp
@@ -69,6 +69,7 @@
Malloc(malloc_disable),
Malloc(malloc_enable),
Malloc(mallopt),
+ Malloc(aligned_alloc),
};
// In a VM process, this is set to 1 after fork()ing out of zygote.
@@ -142,6 +143,14 @@
return Malloc(posix_memalign)(memptr, alignment, size);
}
+extern "C" void* aligned_alloc(size_t alignment, size_t size) {
+ auto _aligned_alloc = __libc_globals->malloc_dispatch.aligned_alloc;
+ if (__predict_false(_aligned_alloc != nullptr)) {
+ return _aligned_alloc(alignment, size);
+ }
+ return Malloc(aligned_alloc)(alignment, size);
+}
+
extern "C" void* realloc(void* old_mem, size_t bytes) {
auto _realloc = __libc_globals->malloc_dispatch.realloc;
if (__predict_false(_realloc != nullptr)) {
@@ -276,6 +285,10 @@
prefix, "posix_memalign")) {
return false;
}
+ if (!InitMallocFunction<MallocAlignedAlloc>(malloc_impl_handler, &table->aligned_alloc,
+ prefix, "aligned_alloc")) {
+ return false;
+ }
if (!InitMallocFunction<MallocRealloc>(malloc_impl_handler, &table->realloc,
prefix, "realloc")) {
return false;