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

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

Issue 2601573002: mac: Hook up allocator shim. (Closed)
Patch Set: Clean up. Created 3 years, 12 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 // TODO(erikchen): Fix get_size_estimate() to take 'const void*'.
247 // https://crbug.com/665567.
248 return chain_head->get_size_estimate_function(chain_head,
249 const_cast<void*>(address));
250 }
251
252 unsigned ShimBatchMalloc(size_t size, void** results, unsigned num_requested) {
253 const allocator::AllocatorDispatch* const chain_head = GetChainHead();
254 return chain_head->batch_malloc_function(chain_head, size, results,
255 num_requested);
256 }
257
258 void ShimBatchFree(void** to_be_freed, unsigned num_to_be_freed) {
259 const allocator::AllocatorDispatch* const chain_head = GetChainHead();
260 return chain_head->batch_free_function(chain_head, to_be_freed,
261 num_to_be_freed);
262 }
263
244 } // extern "C" 264 } // extern "C"
245 265
246 #if !defined(OS_WIN) 266 #if !defined(OS_WIN)
247 // Cpp symbols (new / delete) should always be routed through the shim layer 267 // 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 268 // except on Windows where the malloc intercept is deep enough that it also
249 // catches the cpp calls. 269 // catches the cpp calls.
250 #include "base/allocator/allocator_shim_override_cpp_symbols.h" 270 #include "base/allocator/allocator_shim_override_cpp_symbols.h"
251 #endif 271 #endif
252 272
253 #if defined(OS_ANDROID) 273 #if defined(OS_ANDROID)
254 // Android does not support symbol interposition. The way malloc symbols are 274 // Android does not support symbol interposition. The way malloc symbols are
255 // intercepted on Android is by using link-time -wrap flags. 275 // intercepted on Android is by using link-time -wrap flags.
256 #include "base/allocator/allocator_shim_override_linker_wrapped_symbols.h" 276 #include "base/allocator/allocator_shim_override_linker_wrapped_symbols.h"
257 #elif defined(OS_WIN) 277 #elif defined(OS_WIN)
258 // On Windows we use plain link-time overriding of the CRT symbols. 278 // On Windows we use plain link-time overriding of the CRT symbols.
259 #include "base/allocator/allocator_shim_override_ucrt_symbols_win.h" 279 #include "base/allocator/allocator_shim_override_ucrt_symbols_win.h"
280 #elif defined(OS_MACOSX)
281 #include "base/allocator/allocator_shim_override_mac_symbols.h"
260 #else 282 #else
261 #include "base/allocator/allocator_shim_override_libc_symbols.h" 283 #include "base/allocator/allocator_shim_override_libc_symbols.h"
262 #endif 284 #endif
263 285
264 // In the case of tcmalloc we also want to plumb into the glibc hooks 286 // 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 287 // to avoid that allocations made in glibc itself (e.g., strdup()) get
266 // accidentally performed on the glibc heap instead of the tcmalloc one. 288 // accidentally performed on the glibc heap instead of the tcmalloc one.
267 #if defined(USE_TCMALLOC) 289 #if defined(USE_TCMALLOC)
268 #include "base/allocator/allocator_shim_override_glibc_weak_symbols.h" 290 #include "base/allocator/allocator_shim_override_glibc_weak_symbols.h"
269 #endif 291 #endif
270 292
271 // Cross-checks. 293 // Cross-checks.
272 294
273 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 295 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
274 #error The allocator shim should not be compiled when building for memory tools. 296 #error The allocator shim should not be compiled when building for memory tools.
275 #endif 297 #endif
276 298
277 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ 299 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \
278 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) 300 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS)
279 #error This code cannot be used when exceptions are turned on. 301 #error This code cannot be used when exceptions are turned on.
280 #endif 302 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698