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

Unified Diff: base/allocator/allocator_shim.cc

Issue 2658723007: Hook up allocator shim on mac. (Closed)
Patch Set: remove a debugging test. Created 3 years, 11 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 | « base/allocator/allocator_shim.h ('k') | base/allocator/allocator_shim_default_dispatch_to_glibc.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/allocator/allocator_shim.cc
diff --git a/base/allocator/allocator_shim.cc b/base/allocator/allocator_shim.cc
index a9fc095b905e620dd8e2df9f060fd28e32629e27..bad8fc6e281e2789841ae9edb6a844f9bc1df946 100644
--- a/base/allocator/allocator_shim.cc
+++ b/base/allocator/allocator_shim.cc
@@ -241,12 +241,35 @@ void ShimFree(void* address) {
return chain_head->free_function(chain_head, address);
}
+size_t ShimGetSizeEstimate(const void* address) {
+ const allocator::AllocatorDispatch* const chain_head = GetChainHead();
+ return chain_head->get_size_estimate_function(chain_head,
+ const_cast<void*>(address));
+}
+
+unsigned ShimBatchMalloc(size_t size, void** results, unsigned num_requested) {
+ const allocator::AllocatorDispatch* const chain_head = GetChainHead();
+ return chain_head->batch_malloc_function(chain_head, size, results,
+ num_requested);
+}
+
+void ShimBatchFree(void** to_be_freed, unsigned num_to_be_freed) {
+ const allocator::AllocatorDispatch* const chain_head = GetChainHead();
+ return chain_head->batch_free_function(chain_head, to_be_freed,
+ num_to_be_freed);
+}
+
+void ShimFreeDefiniteSize(void* ptr, size_t size) {
+ const allocator::AllocatorDispatch* const chain_head = GetChainHead();
+ return chain_head->free_definite_size_function(chain_head, ptr, size);
+}
+
} // extern "C"
-#if !defined(OS_WIN)
+#if !defined(OS_WIN) && !defined(OS_MACOSX)
// Cpp symbols (new / delete) should always be routed through the shim layer
-// except on Windows where the malloc intercept is deep enough that it also
-// catches the cpp calls.
+// except on Windows and macOS where the malloc intercept is deep enough that it
+// also catches the cpp calls.
#include "base/allocator/allocator_shim_override_cpp_symbols.h"
#endif
@@ -257,6 +280,9 @@ void ShimFree(void* address) {
#elif defined(OS_WIN)
// On Windows we use plain link-time overriding of the CRT symbols.
#include "base/allocator/allocator_shim_override_ucrt_symbols_win.h"
+#elif defined(OS_MACOSX)
+#include "base/allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.h"
+#include "base/allocator/allocator_shim_override_mac_symbols.h"
#else
#include "base/allocator/allocator_shim_override_libc_symbols.h"
#endif
@@ -268,6 +294,22 @@ void ShimFree(void* address) {
#include "base/allocator/allocator_shim_override_glibc_weak_symbols.h"
#endif
+#if defined(OS_MACOSX)
+namespace base {
+namespace allocator {
+void InitializeAllocatorShim() {
+ // Prepares the default dispatch. After the intercepted malloc calls have
+ // traversed the shim this will route them to the default malloc zone.
+ InitializeDefaultDispatchToMacAllocator();
+
+ // This replaces the default malloc zone, causing calls to malloc & friends
+ // from the codebase to be routed to ShimMalloc() above.
+ OverrideMacSymbols();
+}
+} // namespace allocator
+} // namespace base
+#endif
+
// Cross-checks.
#if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
« no previous file with comments | « base/allocator/allocator_shim.h ('k') | base/allocator/allocator_shim_default_dispatch_to_glibc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698