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

Unified Diff: base/allocator/allocator_shim.cc

Issue 2697123007: base: Add support for malloc zones to the allocator shim (Closed)
Patch Set: Windows compile error. Created 3 years, 10 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 bad8fc6e281e2789841ae9edb6a844f9bc1df946..4de1a8b3b9e368730337a8a1378772ebae38d33a 100644
--- a/base/allocator/allocator_shim.cc
+++ b/base/allocator/allocator_shim.cc
@@ -21,6 +21,10 @@
#include "base/allocator/winheap_stubs_win.h"
#endif
+#if defined(OS_MACOSX)
+#include <malloc/malloc.h>
+#endif
+
// No calls to malloc / new in this file. They would would cause re-entrancy of
// the shim, which is hard to deal with. Keep this code as simple as possible
// and don't use any external C++ object here, not even //base ones. Even if
@@ -96,7 +100,7 @@ void SetCallNewHandlerOnMallocFailure(bool value) {
void* UncheckedAlloc(size_t size) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
- return chain_head->alloc_function(chain_head, size);
+ return chain_head->alloc_function(chain_head, size, nullptr);
}
void InsertAllocatorDispatch(AllocatorDispatch* dispatch) {
@@ -158,53 +162,63 @@ void* ShimCppNew(size_t size) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
- ptr = chain_head->alloc_function(chain_head, size);
+ void* context = nullptr;
+#if defined(OS_MACOSX)
+ context = malloc_default_zone();
+#endif
+ ptr = chain_head->alloc_function(chain_head, size, context);
} while (!ptr && CallNewHandler(size));
return ptr;
}
void ShimCppDelete(void* address) {
+ void* context = nullptr;
+#if defined(OS_MACOSX)
+ context = malloc_default_zone();
+#endif
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
- return chain_head->free_function(chain_head, address);
+ return chain_head->free_function(chain_head, address, context);
}
-void* ShimMalloc(size_t size) {
+void* ShimMalloc(size_t size, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
- ptr = chain_head->alloc_function(chain_head, size);
+ ptr = chain_head->alloc_function(chain_head, size, context);
} while (!ptr && g_call_new_handler_on_malloc_failure &&
CallNewHandler(size));
return ptr;
}
-void* ShimCalloc(size_t n, size_t size) {
+void* ShimCalloc(size_t n, size_t size, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
- ptr = chain_head->alloc_zero_initialized_function(chain_head, n, size);
+ ptr = chain_head->alloc_zero_initialized_function(chain_head, n, size,
+ context);
} while (!ptr && g_call_new_handler_on_malloc_failure &&
CallNewHandler(size));
return ptr;
}
-void* ShimRealloc(void* address, size_t size) {
+void* ShimRealloc(void* address, size_t size, void* context) {
// realloc(size == 0) means free() and might return a nullptr. We should
// not call the std::new_handler in that case, though.
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
- ptr = chain_head->realloc_function(chain_head, address, size);
+ ptr = chain_head->realloc_function(chain_head, address, size, context);
} while (!ptr && size && g_call_new_handler_on_malloc_failure &&
CallNewHandler(size));
return ptr;
}
-void* ShimMemalign(size_t alignment, size_t size) {
+void* ShimMemalign(size_t alignment, size_t size, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
void* ptr;
do {
- ptr = chain_head->alloc_aligned_function(chain_head, alignment, size);
+ ptr = chain_head->alloc_aligned_function(chain_head, alignment, size,
+ context);
} while (!ptr && g_call_new_handler_on_malloc_failure &&
CallNewHandler(size));
return ptr;
@@ -217,13 +231,13 @@ int ShimPosixMemalign(void** res, size_t alignment, size_t size) {
((alignment & (alignment - 1)) != 0) || (alignment == 0)) {
return EINVAL;
}
- void* ptr = ShimMemalign(alignment, size);
+ void* ptr = ShimMemalign(alignment, size, nullptr);
*res = ptr;
return ptr ? 0 : ENOMEM;
}
-void* ShimValloc(size_t size) {
- return ShimMemalign(GetCachedPageSize(), size);
+void* ShimValloc(size_t size, void* context) {
+ return ShimMemalign(GetCachedPageSize(), size, context);
}
void* ShimPvalloc(size_t size) {
@@ -233,35 +247,41 @@ void* ShimPvalloc(size_t size) {
} else {
size = (size + GetCachedPageSize() - 1) & ~(GetCachedPageSize() - 1);
}
- return ShimMemalign(GetCachedPageSize(), size);
+ return ShimMemalign(GetCachedPageSize(), size, nullptr);
Primiano Tucci (use gerrit) 2017/02/20 10:33:05 add a comment saying that this is nullptr because
}
-void ShimFree(void* address) {
+void ShimFree(void* address, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
- return chain_head->free_function(chain_head, address);
+ return chain_head->free_function(chain_head, address, context);
}
-size_t ShimGetSizeEstimate(const void* address) {
+size_t ShimGetSizeEstimate(const void* address, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
- return chain_head->get_size_estimate_function(chain_head,
- const_cast<void*>(address));
+ return chain_head->get_size_estimate_function(
+ chain_head, const_cast<void*>(address), context);
}
-unsigned ShimBatchMalloc(size_t size, void** results, unsigned num_requested) {
+unsigned ShimBatchMalloc(size_t size,
+ void** results,
+ unsigned num_requested,
+ void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
return chain_head->batch_malloc_function(chain_head, size, results,
- num_requested);
+ num_requested, context);
}
-void ShimBatchFree(void** to_be_freed, unsigned num_to_be_freed) {
+void ShimBatchFree(void** to_be_freed,
+ unsigned num_to_be_freed,
+ void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
return chain_head->batch_free_function(chain_head, to_be_freed,
- num_to_be_freed);
+ num_to_be_freed, context);
}
-void ShimFreeDefiniteSize(void* ptr, size_t size) {
+void ShimFreeDefiniteSize(void* ptr, size_t size, void* context) {
const allocator::AllocatorDispatch* const chain_head = GetChainHead();
- return chain_head->free_definite_size_function(chain_head, ptr, size);
+ return chain_head->free_definite_size_function(chain_head, ptr, size,
+ context);
}
} // extern "C"
« 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