| Index: base/allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc
|
| diff --git a/base/allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc b/base/allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc
|
| index 9e04f04f7e6d5ce9ea7e9bfe28cac9a0d6fb2559..69953aec0e92fee04acf19f03464a21ab0e7f1fa 100644
|
| --- a/base/allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc
|
| +++ b/base/allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc
|
| @@ -2,7 +2,14 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include <malloc.h>
|
| +
|
| #include "base/allocator/allocator_shim.h"
|
| +#include "build/build_config.h"
|
| +
|
| +#if defined(OS_ANDROID) && __ANDROID_API__ < 17
|
| +#include <dlfcn.h>
|
| +#endif
|
|
|
| // This translation unit defines a default dispatch for the allocator shim which
|
| // routes allocations to the original libc functions when using the link-time
|
| @@ -45,7 +52,32 @@ void RealFree(const AllocatorDispatch*, void* address) {
|
| __real_free(address);
|
| }
|
|
|
| -size_t RealSizeEstimate(const AllocatorDispatch*, void*) {
|
| +#if defined(OS_ANDROID) && __ANDROID_API__ < 17
|
| +size_t DummyMallocUsableSize(const void*) { return 0; }
|
| +#endif
|
| +
|
| +size_t RealSizeEstimate(const AllocatorDispatch*, void* address) {
|
| +#if defined(OS_ANDROID)
|
| +#if __ANDROID_API__ < 17
|
| + // malloc_usable_size() is available only starting from API 17.
|
| + // TODO(dskiba): remove once we start building against 17+.
|
| + using MallocUsableSizeFunction = decltype(malloc_usable_size)*;
|
| + static MallocUsableSizeFunction usable_size_function = nullptr;
|
| + if (!usable_size_function) {
|
| + void* function_ptr = dlsym(RTLD_DEFAULT, "malloc_usable_size");
|
| + if (function_ptr) {
|
| + usable_size_function = reinterpret_cast<MallocUsableSizeFunction>(
|
| + function_ptr);
|
| + } else {
|
| + usable_size_function = &DummyMallocUsableSize;
|
| + }
|
| + }
|
| + return usable_size_function(address);
|
| +#else
|
| + return malloc_usable_size(address);
|
| +#endif
|
| +#endif // OS_ANDROID
|
| +
|
| // TODO(primiano): This should be redirected to malloc_usable_size or
|
| // the like.
|
| return 0;
|
|
|