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

Side by Side Diff: base/allocator/allocator_shim.cc

Issue 2658723007: Hook up allocator shim on mac. (Closed)
Patch Set: Rebase. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/allocator/allocator_shim.h" 5 #include "base/allocator/allocator_shim.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include <new> 9 #include <new>
10 10
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 size = (size + GetCachedPageSize() - 1) & ~(GetCachedPageSize() - 1); 234 size = (size + GetCachedPageSize() - 1) & ~(GetCachedPageSize() - 1);
235 } 235 }
236 return ShimMemalign(GetCachedPageSize(), size); 236 return ShimMemalign(GetCachedPageSize(), size);
237 } 237 }
238 238
239 void ShimFree(void* address) { 239 void ShimFree(void* address) {
240 const allocator::AllocatorDispatch* const chain_head = GetChainHead(); 240 const allocator::AllocatorDispatch* const chain_head = GetChainHead();
241 return chain_head->free_function(chain_head, address); 241 return chain_head->free_function(chain_head, address);
242 } 242 }
243 243
244 size_t ShimGetSizeEstimate(const void* address) {
245 const allocator::AllocatorDispatch* const chain_head = GetChainHead();
246 return chain_head->get_size_estimate_function(chain_head,
247 const_cast<void*>(address));
248 }
249
250 unsigned ShimBatchMalloc(size_t size, void** results, unsigned num_requested) {
251 const allocator::AllocatorDispatch* const chain_head = GetChainHead();
252 return chain_head->batch_malloc_function(chain_head, size, results,
253 num_requested);
254 }
255
256 void ShimBatchFree(void** to_be_freed, unsigned num_to_be_freed) {
257 const allocator::AllocatorDispatch* const chain_head = GetChainHead();
258 return chain_head->batch_free_function(chain_head, to_be_freed,
259 num_to_be_freed);
260 }
261
244 } // extern "C" 262 } // extern "C"
245 263
246 #if !defined(OS_WIN) 264 #if !defined(OS_WIN)
247 // Cpp symbols (new / delete) should always be routed through the shim layer 265 // Cpp symbols (new / delete) should always be routed through the shim layer
248 // except on Windows where the malloc intercept is deep enough that it also 266 // except on Windows where the malloc intercept is deep enough that it also
249 // catches the cpp calls. 267 // catches the cpp calls.
250 #include "base/allocator/allocator_shim_override_cpp_symbols.h" 268 #include "base/allocator/allocator_shim_override_cpp_symbols.h"
251 #endif 269 #endif
252 270
253 #if defined(OS_ANDROID) 271 #if defined(OS_ANDROID)
254 // Android does not support symbol interposition. The way malloc symbols are 272 // Android does not support symbol interposition. The way malloc symbols are
255 // intercepted on Android is by using link-time -wrap flags. 273 // intercepted on Android is by using link-time -wrap flags.
256 #include "base/allocator/allocator_shim_override_linker_wrapped_symbols.h" 274 #include "base/allocator/allocator_shim_override_linker_wrapped_symbols.h"
257 #elif defined(OS_WIN) 275 #elif defined(OS_WIN)
258 // On Windows we use plain link-time overriding of the CRT symbols. 276 // On Windows we use plain link-time overriding of the CRT symbols.
259 #include "base/allocator/allocator_shim_override_ucrt_symbols_win.h" 277 #include "base/allocator/allocator_shim_override_ucrt_symbols_win.h"
278 #elif defined(OS_MACOSX)
279 #include "base/allocator/allocator_shim_override_mac_symbols.h"
260 #else 280 #else
261 #include "base/allocator/allocator_shim_override_libc_symbols.h" 281 #include "base/allocator/allocator_shim_override_libc_symbols.h"
262 #endif 282 #endif
263 283
264 // In the case of tcmalloc we also want to plumb into the glibc hooks 284 // In the case of tcmalloc we also want to plumb into the glibc hooks
265 // to avoid that allocations made in glibc itself (e.g., strdup()) get 285 // to avoid that allocations made in glibc itself (e.g., strdup()) get
266 // accidentally performed on the glibc heap instead of the tcmalloc one. 286 // accidentally performed on the glibc heap instead of the tcmalloc one.
267 #if defined(USE_TCMALLOC) 287 #if defined(USE_TCMALLOC)
268 #include "base/allocator/allocator_shim_override_glibc_weak_symbols.h" 288 #include "base/allocator/allocator_shim_override_glibc_weak_symbols.h"
269 #endif 289 #endif
270 290
271 // Cross-checks. 291 // Cross-checks.
272 292
273 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 293 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
274 #error The allocator shim should not be compiled when building for memory tools. 294 #error The allocator shim should not be compiled when building for memory tools.
275 #endif 295 #endif
276 296
277 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ 297 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \
278 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) 298 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS)
279 #error This code cannot be used when exceptions are turned on. 299 #error This code cannot be used when exceptions are turned on.
280 #endif 300 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698