Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: base/process/memory_linux.cc

Issue 55333002: Make possible to check memory allocations inside chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes inspired by trybots Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/memory.cc ('k') | base/process/memory_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/memory_linux.cc
diff --git a/base/process/memory_linux.cc b/base/process/memory_linux.cc
index a40c2707edb34dc8ba27937cb5362ca3323022b4..e1d452b67fa8ed769485be714d97e33bc0730d19 100644
--- a/base/process/memory_linux.cc
+++ b/base/process/memory_linux.cc
@@ -12,6 +12,22 @@
#include "base/process/internal_linux.h"
#include "base/strings/string_number_conversions.h"
+#if defined(USE_TCMALLOC)
+// Used by UncheckedMalloc. If tcmalloc is linked to the executable
+// this will be replaced by a strong symbol that actually implement
+// the semantics and don't call new handler in case the allocation fails.
+extern "C" {
+
+__attribute__((weak, visibility("default")))
+void* tc_malloc_skip_new_handler_weak(size_t size);
+
+void* tc_malloc_skip_new_handler_weak(size_t size) {
+ return malloc(size);
+}
+
+}
+#endif
+
namespace base {
size_t g_oom_size = 0U;
@@ -182,4 +198,17 @@ bool AdjustOOMScore(ProcessId process, int score) {
return false;
}
+bool UncheckedMalloc(size_t size, void** result) {
+#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
+ defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \
+ (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC))
+ *result = malloc(size);
+#elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)
+ *result = __libc_malloc(size);
+#elif defined(USE_TCMALLOC)
+ *result = tc_malloc_skip_new_handler_weak(size);
+#endif
+ return *result != NULL;
+}
+
} // namespace base
« no previous file with comments | « base/process/memory.cc ('k') | base/process/memory_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698