OLD | NEW |
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" __attribute__((weak)) |
| 20 void* tc_malloc_skip_new_handler_weak(size_t size) { |
| 21 return malloc(size); |
| 22 } |
| 23 #endif |
| 24 |
15 namespace base { | 25 namespace base { |
16 | 26 |
17 size_t g_oom_size = 0U; | 27 size_t g_oom_size = 0U; |
18 | 28 |
19 namespace { | 29 namespace { |
20 | 30 |
21 #if !defined(OS_ANDROID) | 31 #if !defined(OS_ANDROID) |
22 void OnNoMemorySize(size_t size) { | 32 void OnNoMemorySize(size_t size) { |
23 g_oom_size = size; | 33 g_oom_size = size; |
24 | 34 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str; | 185 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str; |
176 int score_len = static_cast<int>(score_str.length()); | 186 int score_len = static_cast<int>(score_str.length()); |
177 return (score_len == file_util::WriteFile(oom_file, | 187 return (score_len == file_util::WriteFile(oom_file, |
178 score_str.c_str(), | 188 score_str.c_str(), |
179 score_len)); | 189 score_len)); |
180 } | 190 } |
181 | 191 |
182 return false; | 192 return false; |
183 } | 193 } |
184 | 194 |
| 195 bool UncheckedMalloc(size_t size, void** result) { |
| 196 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \ |
| 197 defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \ |
| 198 (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)) |
| 199 *result = malloc(size); |
| 200 #elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC) |
| 201 *result = __libc_malloc(size); |
| 202 #elif defined(USE_TCMALLOC) |
| 203 *result = tc_malloc_skip_new_handler_weak(size); |
| 204 #endif |
| 205 return *result; |
| 206 } |
| 207 |
185 } // namespace base | 208 } // namespace base |
OLD | NEW |