summaryrefslogtreecommitdiffstats
path: root/base/allocator
diff options
context:
space:
mode:
authorprimiano <primiano@chromium.org>2016-01-12 14:16:11 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-12 22:18:10 +0000
commitbe9d6fce01061afde845fd7aa2335e5757d6a421 (patch)
treefb212b5237619f78af41b650fab85965cfbbb67f /base/allocator
parent73b81e992e53c657631c49429ba407fe3a3a6813 (diff)
downloadchromium_src-be9d6fce01061afde845fd7aa2335e5757d6a421.zip
chromium_src-be9d6fce01061afde845fd7aa2335e5757d6a421.tar.gz
chromium_src-be9d6fce01061afde845fd7aa2335e5757d6a421.tar.bz2
Add run-time CHECK to smoke-test allocator overrides
As part of the refactoring work on the allocator, it emerged that it would be nice to have a test that ensures that we don't accidentally break things along the way and not detected that. This CL adds a runtime CHECK() that verifies that: - On Windows (non-component build) the shim layer has been initialized. Concretely this checks that chrome called the shimmed _heap_init() method and not the one from libcmt. - On Linux desktop, the malloc symbols are being overridden by tcmalloc (only when USE_TCMALLOC is defined). The rationale of this test is: if _heap_init was shimmed there are very good chances that malloc (& friends) were shimmed as well. Likewise on Linux for mallopt() <-> malloc(). BUG=564618 Review URL: https://codereview.chromium.org/1577883002 Cr-Commit-Position: refs/heads/master@{#369007}
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;
}