Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: base/allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc

Issue 2409703002: [tracing] Implement RealSizeEstimate for Android. (Closed)
Patch Set: Address comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698