Commit a0199931 authored by dskiba's avatar dskiba Committed by Commit bot

[tracing] Implement RealSizeEstimate for Android.

BUG=none

Review-Url: https://chromiumcodereview.appspot.com/2409703002
Cr-Commit-Position: refs/heads/master@{#426942}
parent 5805da7f
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment