xref: /aosp_15_r20/external/cronet/base/allocator/allocator_check.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
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 
7 #include "build/build_config.h"
8 #include "partition_alloc/partition_alloc_buildflags.h"
9 
10 #if BUILDFLAG(IS_WIN)
11 #include "partition_alloc/shim/winheap_stubs_win.h"
12 #endif
13 
14 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
15 #include <malloc.h>
16 #endif
17 
18 #if BUILDFLAG(IS_APPLE)
19 #include "partition_alloc/shim/allocator_interception_apple.h"
20 #endif
21 
22 namespace base::allocator {
23 
IsAllocatorInitialized()24 bool IsAllocatorInitialized() {
25 #if BUILDFLAG(IS_WIN) && BUILDFLAG(USE_ALLOCATOR_SHIM)
26   // Set by allocator_shim_override_ucrt_symbols_win.h when the
27   // shimmed _set_new_mode() is called.
28   return allocator_shim::g_is_win_shim_layer_initialized;
29 #elif BUILDFLAG(IS_APPLE) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) && \
30     !BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && BUILDFLAG(USE_ALLOCATOR_SHIM)
31   // From allocator_interception_mac.mm.
32   return allocator_shim::g_replaced_default_zone;
33 #else
34   return true;
35 #endif
36 }
37 
38 }  // namespace base::allocator
39