summaryrefslogtreecommitdiffstats
path: root/base/allocator
diff options
context:
space:
mode:
Diffstat (limited to 'base/allocator')
-rw-r--r--base/allocator/allocator_check.cc38
-rw-r--r--base/allocator/allocator_check.h18
-rw-r--r--base/allocator/allocator_shim_win.cc7
3 files changed, 63 insertions, 0 deletions
diff --git a/base/allocator/allocator_check.cc b/base/allocator/allocator_check.cc
new file mode 100644
index 0000000..4220fb7
--- /dev/null
+++ b/base/allocator/allocator_check.cc
@@ -0,0 +1,38 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/allocator/allocator_check.h"
+
+#include "build/build_config.h"
+
+#if defined(OS_LINUX)
+#include <malloc.h>
+#endif
+
+namespace base {
+namespace allocator {
+
+// Defined in allocator_shim_win.cc .
+// TODO(primiano): replace with an include once base can depend on allocator.
+#if defined(OS_WIN) && defined(ALLOCATOR_SHIM)
+extern bool g_is_win_shim_layer_initialized;
+#endif
+
+bool IsAllocatorInitialized() {
+#if defined(OS_WIN) && defined(ALLOCATOR_SHIM)
+ // Set by allocator_shim_win.cc when the shimmed _heap_init() is called.
+ return g_is_win_shim_layer_initialized;
+#elif defined(OS_LINUX) && defined(USE_TCMALLOC)
+// From third_party/tcmalloc/chromium/src/gperftools/tcmalloc.h.
+// TODO(primiano): replace with an include once base can depend on allocator.
+#define TC_MALLOPT_IS_OVERRIDDEN_BY_TCMALLOC 0xbeef42
+ return (mallopt(TC_MALLOPT_IS_OVERRIDDEN_BY_TCMALLOC, 0) ==
+ TC_MALLOPT_IS_OVERRIDDEN_BY_TCMALLOC);
+#else
+ return true;
+#endif
+}
+
+} // namespace allocator
+} // namespace base
diff --git a/base/allocator/allocator_check.h b/base/allocator/allocator_check.h
new file mode 100644
index 0000000..c3aa2cb
--- /dev/null
+++ b/base/allocator/allocator_check.h
@@ -0,0 +1,18 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_ALLOCATOR_ALLOCATOR_ALLOCATOR_CHECK_H_
+#define BASE_ALLOCATOR_ALLOCATOR_ALLOCATOR_CHECK_H_
+
+#include "base/base_export.h"
+
+namespace base {
+namespace allocator {
+
+BASE_EXPORT bool IsAllocatorInitialized();
+
+} // namespace allocator
+} // namespace base
+
+#endif // BASE_ALLOCATOR_ALLOCATOR_ALLOCATOR_CHECK_H_
diff --git a/base/allocator/allocator_shim_win.cc b/base/allocator/allocator_shim_win.cc
index 2c5a40f..b65544f5 100644
--- a/base/allocator/allocator_shim_win.cc
+++ b/base/allocator/allocator_shim_win.cc
@@ -26,6 +26,12 @@ extern "C" {
void* _crtheap = reinterpret_cast<void*>(1);
}
+namespace base {
+namespace allocator {
+bool g_is_win_shim_layer_initialized = false;
+} // namespace allocator
+} // namespace base
+
namespace {
const size_t kWindowsPageSize = 4096;
@@ -211,6 +217,7 @@ intptr_t _get_heap_handle() {
// heapinit.c
int _heap_init() {
+ base::allocator::g_is_win_shim_layer_initialized = true;
return win_heap_init() ? 1 : 0;
}