blob: fba38d151d3caab28b025785d677d88cbc23d5d6 [file] [log] [blame]
primianodf8fa812016-01-13 13:14:131// Copyright 2016 The Chromium Authors. All rights reserved.
primianobe9d6fc2016-01-12 22:16:112// 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
primiano3038b2f2017-05-26 15:48:327#include "base/allocator/features.h"
primianobe9d6fc2016-01-12 22:16:118#include "build/build_config.h"
9
wfh08a96652016-04-01 22:36:3010#if defined(OS_WIN)
primiano3038b2f2017-05-26 15:48:3211#include "base/allocator/winheap_stubs_win.h"
wfh08a96652016-04-01 22:36:3012#endif
13
primianobe9d6fc2016-01-12 22:16:1114#if defined(OS_LINUX)
15#include <malloc.h>
16#endif
17
erikchenbf11b55a2017-02-10 01:34:4818#if defined(OS_MACOSX)
19#include "base/allocator/allocator_interception_mac.h"
20#endif
21
primianobe9d6fc2016-01-12 22:16:1122namespace base {
23namespace allocator {
24
primianobe9d6fc2016-01-12 22:16:1125bool IsAllocatorInitialized() {
Primiano Tucci05f56d42017-06-01 14:22:0326#if defined(OS_WIN) && BUILDFLAG(USE_ALLOCATOR_SHIM)
primiano3038b2f2017-05-26 15:48:3227 // Set by allocator_shim_override_ucrt_symbols_win.h when the
28 // shimmed _set_new_mode() is called.
primianobe9d6fc2016-01-12 22:16:1129 return g_is_win_shim_layer_initialized;
thestig82c77812016-03-30 20:45:1230#elif defined(OS_LINUX) && defined(USE_TCMALLOC) && \
31 !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
primianobe9d6fc2016-01-12 22:16:1132// 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);
erikchenbf11b55a2017-02-10 01:34:4837#elif defined(OS_MACOSX) && !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
38 // From allocator_interception_mac.mm.
39 return base::allocator::g_replaced_default_zone;
primianobe9d6fc2016-01-12 22:16:1140#else
41 return true;
42#endif
43}
44
45} // namespace allocator
46} // namespace base