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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/process/memory.cc ('k') | base/process/memory_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/process/memory.h" 5 #include "base/process/memory.h"
6 6
7 #include <new> 7 #include <new>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/process/internal_linux.h" 12 #include "base/process/internal_linux.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 14
15 #if defined(USE_TCMALLOC)
16 // Used by UncheckedMalloc. If tcmalloc is linked to the executable
17 // this will be replaced by a strong symbol that actually implement
18 // the semantics and don't call new handler in case the allocation fails.
19 extern "C" {
20
21 __attribute__((weak, visibility("default")))
22 void* tc_malloc_skip_new_handler_weak(size_t size);
23
24 void* tc_malloc_skip_new_handler_weak(size_t size) {
25 return malloc(size);
26 }
27
28 }
29 #endif
30
15 namespace base { 31 namespace base {
16 32
17 size_t g_oom_size = 0U; 33 size_t g_oom_size = 0U;
18 34
19 namespace { 35 namespace {
20 36
21 #if !defined(OS_ANDROID) 37 #if !defined(OS_ANDROID)
22 void OnNoMemorySize(size_t size) { 38 void OnNoMemorySize(size_t size) {
23 g_oom_size = size; 39 g_oom_size = size;
24 40
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 int converted_score = score * kMaxOldOomScore / kMaxOomScore; 191 int converted_score = score * kMaxOldOomScore / kMaxOomScore;
176 std::string score_str = IntToString(converted_score); 192 std::string score_str = IntToString(converted_score);
177 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str; 193 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str;
178 int score_len = static_cast<int>(score_str.length()); 194 int score_len = static_cast<int>(score_str.length());
179 return (score_len == WriteFile(oom_file, score_str.c_str(), score_len)); 195 return (score_len == WriteFile(oom_file, score_str.c_str(), score_len));
180 } 196 }
181 197
182 return false; 198 return false;
183 } 199 }
184 200
201 bool UncheckedMalloc(size_t size, void** result) {
202 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
203 defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \
204 (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC))
205 *result = malloc(size);
206 #elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)
207 *result = __libc_malloc(size);
208 #elif defined(USE_TCMALLOC)
209 *result = tc_malloc_skip_new_handler_weak(size);
210 #endif
211 return *result != NULL;
212 }
213
185 } // namespace base 214 } // namespace base
OLDNEW
« 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