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

Unified Diff: base/allocator/allocator_shim_override_mac_symbols.h

Issue 2658723007: Hook up allocator shim on mac. (Closed)
Patch Set: Rebase. 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
Index: base/allocator/allocator_shim_override_mac_symbols.h
diff --git a/base/allocator/allocator_shim_override_mac_symbols.h b/base/allocator/allocator_shim_override_mac_symbols.h
new file mode 100644
index 0000000000000000000000000000000000000000..7c02120e938cc6cdfc967696c8e3b8315d7d4c7d
--- /dev/null
+++ b/base/allocator/allocator_shim_override_mac_symbols.h
@@ -0,0 +1,61 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifdef BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_
+#error This header is meant to be included only once by allocator_shim.cc
+#endif
+#define BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_
+
+#include "base/allocator/allocator_interception_mac.h"
+#include "base/allocator/allocator_shim_default_dispatch_to_zoned_malloc.h"
+#include "third_party/apple_apsl/malloc.h"
+
+namespace base {
+namespace allocator {
+
+void InitializeAllocatorShim() {
Primiano Tucci (use gerrit) 2017/01/28 05:10:02 I'd rename this to OverrideMacSymbols, which will
erikchen 2017/01/31 02:21:22 Done.
+ MallocZoneFunctions functions;
Primiano Tucci (use gerrit) 2017/01/28 05:10:02 As said above, these 3 lines are really unnecessar
erikchen 2017/01/31 02:21:22 Done.
+ base::allocator::StoreDefaultZoneFunctions(&functions);
+ base::allocator::SetDefaultDispatchMallocZoneFunctions(&functions);
+
+ MallocZoneFunctions new_functions;
+ new_functions.size = [](malloc_zone_t* zone, const void* ptr) -> size_t {
+ return ShimGetSizeEstimate(ptr);
+ };
+ new_functions.malloc = [](malloc_zone_t* zone, size_t size) -> void* {
+ return ShimMalloc(size);
+ };
+ new_functions.calloc = [](malloc_zone_t* zone, size_t n,
+ size_t size) -> void* {
+ return ShimCalloc(n, size);
+ };
+ new_functions.valloc = [](malloc_zone_t* zone, size_t size) -> void* {
+ return ShimValloc(size);
+ };
+ new_functions.free = [](malloc_zone_t* zone, void* ptr) { ShimFree(ptr); };
+ new_functions.realloc = [](malloc_zone_t* zone, void* ptr,
+ size_t size) -> void* {
+ return ShimRealloc(ptr, size);
+ };
+ new_functions.batch_malloc = [](struct _malloc_zone_t* zone, size_t size,
+ void** results,
+ unsigned num_requested) -> unsigned {
+ return ShimBatchMalloc(size, results, num_requested);
+ };
+ new_functions.batch_free = [](struct _malloc_zone_t* zone, void** to_be_freed,
+ unsigned num_to_be_freed) -> void {
+ ShimBatchFree(to_be_freed, num_to_be_freed);
+ };
+ new_functions.memalign = [](malloc_zone_t* zone, size_t alignment,
+ size_t size) -> void* {
+ return ShimMemalign(alignment, size);
+ };
+ new_functions.free_definite_size = [](malloc_zone_t* zone, void* ptr,
+ size_t size) { ShimFree(ptr); };
+
+ base::allocator::ReplaceDefaultZoneFunctions(&new_functions);
+}
+
+} // namespace allocator
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698