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

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

Issue 2727463002: mac: Several minor fixes to allocator shim. (Closed)
Patch Set: Treat MallocZoneFunctions as POD. Created 3 years, 9 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
11 #include "base/atomicops.h" 11 #include "base/atomicops.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/process/process_metrics.h" 14 #include "base/process/process_metrics.h"
15 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 17
18 #if !defined(OS_WIN) 18 #if !defined(OS_WIN)
19 #include <unistd.h> 19 #include <unistd.h>
20 #else 20 #else
21 #include "base/allocator/winheap_stubs_win.h" 21 #include "base/allocator/winheap_stubs_win.h"
22 #endif 22 #endif
23 23
24 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
25 #include <malloc/malloc.h> 25 #include <malloc/malloc.h>
26
27 #include "base/allocator/allocator_interception_mac.h"
26 #endif 28 #endif
27 29
28 // No calls to malloc / new in this file. They would would cause re-entrancy of 30 // No calls to malloc / new in this file. They would would cause re-entrancy of
29 // the shim, which is hard to deal with. Keep this code as simple as possible 31 // the shim, which is hard to deal with. Keep this code as simple as possible
30 // and don't use any external C++ object here, not even //base ones. Even if 32 // and don't use any external C++ object here, not even //base ones. Even if
31 // they are safe to use today, in future they might be refactored. 33 // they are safe to use today, in future they might be refactored.
32 34
33 namespace { 35 namespace {
34 36
35 using namespace base; 37 using namespace base;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 #endif 319 #endif
318 320
319 #if defined(OS_MACOSX) 321 #if defined(OS_MACOSX)
320 namespace base { 322 namespace base {
321 namespace allocator { 323 namespace allocator {
322 void InitializeAllocatorShim() { 324 void InitializeAllocatorShim() {
323 // Prepares the default dispatch. After the intercepted malloc calls have 325 // Prepares the default dispatch. After the intercepted malloc calls have
324 // traversed the shim this will route them to the default malloc zone. 326 // traversed the shim this will route them to the default malloc zone.
325 InitializeDefaultDispatchToMacAllocator(); 327 InitializeDefaultDispatchToMacAllocator();
326 328
329 MallocZoneFunctions functions = MallocZoneFunctionsToReplaceDefault();
Primiano Tucci (use gerrit) 2017/03/21 19:39:23 out of curiosity why this doesn't happen in alloca
erikchen 2017/03/24 21:59:03 allocator_shim depends on allocator_shim_default_d
330
327 // This replaces the default malloc zone, causing calls to malloc & friends 331 // This replaces the default malloc zone, causing calls to malloc & friends
328 // from the codebase to be routed to ShimMalloc() above. 332 // from the codebase to be routed to ShimMalloc() above.
329 OverrideMacSymbols(); 333 base::allocator::ReplaceFunctionsForStoredZones(&functions);
330 } 334 }
331 } // namespace allocator 335 } // namespace allocator
332 } // namespace base 336 } // namespace base
333 #endif 337 #endif
334 338
335 // Cross-checks. 339 // Cross-checks.
336 340
337 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 341 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
338 #error The allocator shim should not be compiled when building for memory tools. 342 #error The allocator shim should not be compiled when building for memory tools.
339 #endif 343 #endif
340 344
341 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ 345 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \
342 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) 346 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS)
343 #error This code cannot be used when exceptions are turned on. 347 #error This code cannot be used when exceptions are turned on.
344 #endif 348 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698