blob: 4220fb799835137f61040bdd1c05de4ffc6a022b [file] [log] [blame]
primianobe9d6fc2016-01-12 22:16:111// Copyright (c) 2012 The Chromium Authors. All rights reserved.
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
9#if defined(OS_LINUX)
10#include <malloc.h>
11#endif
12
13namespace base {
14namespace allocator {
15
16// Defined in allocator_shim_win.cc .
17// TODO(primiano): replace with an include once base can depend on allocator.
18#if defined(OS_WIN) && defined(ALLOCATOR_SHIM)
19extern bool g_is_win_shim_layer_initialized;
20#endif
21
22bool IsAllocatorInitialized() {
23#if defined(OS_WIN) && defined(ALLOCATOR_SHIM)
24 // Set by allocator_shim_win.cc when the shimmed _heap_init() is called.
25 return g_is_win_shim_layer_initialized;
26#elif defined(OS_LINUX) && defined(USE_TCMALLOC)
27// From third_party/tcmalloc/chromium/src/gperftools/tcmalloc.h.
28// TODO(primiano): replace with an include once base can depend on allocator.
29#define TC_MALLOPT_IS_OVERRIDDEN_BY_TCMALLOC 0xbeef42
30 return (mallopt(TC_MALLOPT_IS_OVERRIDDEN_BY_TCMALLOC, 0) ==
31 TC_MALLOPT_IS_OVERRIDDEN_BY_TCMALLOC);
32#else
33 return true;
34#endif
35}
36
37} // namespace allocator
38} // namespace base