primiano | df8fa81 | 2016-01-13 13:14:13 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
primiano | be9d6fc | 2016-01-12 22:16:11 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/allocator/allocator_check.h" |
| 6 | |
primiano | 3038b2f | 2017-05-26 15:48:32 | [diff] [blame] | 7 | #include "base/allocator/features.h" |
primiano | be9d6fc | 2016-01-12 22:16:11 | [diff] [blame] | 8 | #include "build/build_config.h" |
| 9 | |
wfh | 08a9665 | 2016-04-01 22:36:30 | [diff] [blame] | 10 | #if defined(OS_WIN) |
primiano | 3038b2f | 2017-05-26 15:48:32 | [diff] [blame] | 11 | #include "base/allocator/winheap_stubs_win.h" |
wfh | 08a9665 | 2016-04-01 22:36:30 | [diff] [blame] | 12 | #endif |
| 13 | |
primiano | be9d6fc | 2016-01-12 22:16:11 | [diff] [blame] | 14 | #if defined(OS_LINUX) |
| 15 | #include <malloc.h> |
| 16 | #endif |
| 17 | |
erikchen | bf11b55a | 2017-02-10 01:34:48 | [diff] [blame] | 18 | #if defined(OS_MACOSX) |
| 19 | #include "base/allocator/allocator_interception_mac.h" |
| 20 | #endif |
| 21 | |
primiano | be9d6fc | 2016-01-12 22:16:11 | [diff] [blame] | 22 | namespace base { |
| 23 | namespace allocator { |
| 24 | |
primiano | be9d6fc | 2016-01-12 22:16:11 | [diff] [blame] | 25 | bool IsAllocatorInitialized() { |
Primiano Tucci | 05f56d4 | 2017-06-01 14:22:03 | [diff] [blame] | 26 | #if defined(OS_WIN) && BUILDFLAG(USE_ALLOCATOR_SHIM) |
primiano | 3038b2f | 2017-05-26 15:48:32 | [diff] [blame] | 27 | // Set by allocator_shim_override_ucrt_symbols_win.h when the |
| 28 | // shimmed _set_new_mode() is called. |
primiano | be9d6fc | 2016-01-12 22:16:11 | [diff] [blame] | 29 | return g_is_win_shim_layer_initialized; |
thestig | 82c7781 | 2016-03-30 20:45:12 | [diff] [blame] | 30 | #elif defined(OS_LINUX) && defined(USE_TCMALLOC) && \ |
| 31 | !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
primiano | be9d6fc | 2016-01-12 22:16:11 | [diff] [blame] | 32 | // From third_party/tcmalloc/chromium/src/gperftools/tcmalloc.h. |
| 33 | // TODO(primiano): replace with an include once base can depend on allocator. |
| 34 | #define TC_MALLOPT_IS_OVERRIDDEN_BY_TCMALLOC 0xbeef42 |
| 35 | return (mallopt(TC_MALLOPT_IS_OVERRIDDEN_BY_TCMALLOC, 0) == |
| 36 | TC_MALLOPT_IS_OVERRIDDEN_BY_TCMALLOC); |
erikchen | bf11b55a | 2017-02-10 01:34:48 | [diff] [blame] | 37 | #elif defined(OS_MACOSX) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| 38 | // From allocator_interception_mac.mm. |
| 39 | return base::allocator::g_replaced_default_zone; |
primiano | be9d6fc | 2016-01-12 22:16:11 | [diff] [blame] | 40 | #else |
| 41 | return true; |
| 42 | #endif |
| 43 | } |
| 44 | |
| 45 | } // namespace allocator |
| 46 | } // namespace base |