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

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

Issue 2499373003: [NOT FOR REVIEW] Basic allocator shim for macOS. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | base/allocator/allocator_shim_override_cpp_symbols.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 size = (size + GetCachedPageSize() - 1) & ~(GetCachedPageSize() - 1); 236 size = (size + GetCachedPageSize() - 1) & ~(GetCachedPageSize() - 1);
237 } 237 }
238 return ShimMemalign(GetCachedPageSize(), size); 238 return ShimMemalign(GetCachedPageSize(), size);
239 } 239 }
240 240
241 void ShimFree(void* address) { 241 void ShimFree(void* address) {
242 const allocator::AllocatorDispatch* const chain_head = GetChainHead(); 242 const allocator::AllocatorDispatch* const chain_head = GetChainHead();
243 return chain_head->free_function(chain_head, address); 243 return chain_head->free_function(chain_head, address);
244 } 244 }
245 245
246 size_t ShimGetSizeEstimate(const void* address) {
247 const allocator::AllocatorDispatch* const chain_head = GetChainHead();
248 // TODO: Fix get_size_estimate() to take 'const void*'.
249 return chain_head->get_size_estimate_function(
250 chain_head, const_cast<void*>(address));
251 }
252
246 } // extern "C" 253 } // extern "C"
247 254
248 #if !defined(OS_WIN) 255 #if !defined(OS_WIN)
249 // Cpp symbols (new / delete) should always be routed through the shim layer 256 // Cpp symbols (new / delete) should always be routed through the shim layer
250 // except on Windows where the malloc intercept is deep enough that it also 257 // except on Windows where the malloc intercept is deep enough that it also
251 // catches the cpp calls. 258 // catches the cpp calls.
252 #include "base/allocator/allocator_shim_override_cpp_symbols.h" 259 #include "base/allocator/allocator_shim_override_cpp_symbols.h"
253 #endif 260 #endif
254 261
255 #if defined(OS_ANDROID) 262 #if defined(OS_ANDROID)
256 // Android does not support symbol interposition. The way malloc symbols are 263 // Android does not support symbol interposition. The way malloc symbols are
257 // intercepted on Android is by using link-time -wrap flags. 264 // intercepted on Android is by using link-time -wrap flags.
258 #include "base/allocator/allocator_shim_override_linker_wrapped_symbols.h" 265 #include "base/allocator/allocator_shim_override_linker_wrapped_symbols.h"
259 #elif defined(OS_WIN) 266 #elif defined(OS_WIN)
260 // On Windows we use plain link-time overriding of the CRT symbols. 267 // On Windows we use plain link-time overriding of the CRT symbols.
261 #include "base/allocator/allocator_shim_override_ucrt_symbols_win.h" 268 #include "base/allocator/allocator_shim_override_ucrt_symbols_win.h"
269 #elif defined(OS_MACOSX)
270 #include "base/allocator/allocator_shim_override_mac_symbols.h"
262 #else 271 #else
263 #include "base/allocator/allocator_shim_override_libc_symbols.h" 272 #include "base/allocator/allocator_shim_override_libc_symbols.h"
264 #endif 273 #endif
265 274
266 // In the case of tcmalloc we also want to plumb into the glibc hooks 275 // In the case of tcmalloc we also want to plumb into the glibc hooks
267 // to avoid that allocations made in glibc itself (e.g., strdup()) get 276 // to avoid that allocations made in glibc itself (e.g., strdup()) get
268 // accidentally performed on the glibc heap instead of the tcmalloc one. 277 // accidentally performed on the glibc heap instead of the tcmalloc one.
269 #if defined(USE_TCMALLOC) 278 #if defined(USE_TCMALLOC)
270 #include "base/allocator/allocator_shim_override_glibc_weak_symbols.h" 279 #include "base/allocator/allocator_shim_override_glibc_weak_symbols.h"
271 #endif 280 #endif
272 281
273 // Cross-checks. 282 // Cross-checks.
274 283
275 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 284 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
276 #error The allocator shim should not be compiled when building for memory tools. 285 #error The allocator shim should not be compiled when building for memory tools.
277 #endif 286 #endif
278 287
279 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ 288 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \
280 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) 289 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS)
281 #error This code cannot be used when exceptions are turned on. 290 #error This code cannot be used when exceptions are turned on.
282 #endif 291 #endif
OLDNEW
« no previous file with comments | « no previous file | base/allocator/allocator_shim_override_cpp_symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698