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

Side by Side Diff: base/process/memory_linux.cc

Issue 2902043007: allocator: rename use_experimental_allocator_shim to use_allocator_shim (Closed)
Patch Set: Created 3 years, 7 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/debug/thread_heap_usage_tracker_unittest.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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <new> 9 #include <new>
10 10
(...skipping 28 matching lines...) Expand all
39 OnNoMemorySize(0); 39 OnNoMemorySize(0);
40 } 40 }
41 41
42 } // namespace 42 } // namespace
43 43
44 // TODO(primiano): Once the unified shim is on by default (crbug.com/550886) 44 // TODO(primiano): Once the unified shim is on by default (crbug.com/550886)
45 // get rid of the code in this entire #if section. The whole termination-on-OOM 45 // get rid of the code in this entire #if section. The whole termination-on-OOM
46 // logic is implemented in the shim. 46 // logic is implemented in the shim.
47 #if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) && \ 47 #if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) && \
48 !defined(THREAD_SANITIZER) && !defined(LEAK_SANITIZER) && \ 48 !defined(THREAD_SANITIZER) && !defined(LEAK_SANITIZER) && \
49 !BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 49 !BUILDFLAG(USE_ALLOCATOR_SHIM)
50 50
51 #if defined(LIBC_GLIBC) && !defined(USE_TCMALLOC) 51 #if defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)
52 52
53 extern "C" { 53 extern "C" {
54 void* __libc_malloc(size_t size); 54 void* __libc_malloc(size_t size);
55 void* __libc_realloc(void* ptr, size_t size); 55 void* __libc_realloc(void* ptr, size_t size);
56 void* __libc_calloc(size_t nmemb, size_t size); 56 void* __libc_calloc(size_t nmemb, size_t size);
57 void* __libc_valloc(size_t size); 57 void* __libc_valloc(size_t size);
58 #if PVALLOC_AVAILABLE == 1 58 #if PVALLOC_AVAILABLE == 1
59 void* __libc_pvalloc(size_t size); 59 void* __libc_pvalloc(size_t size);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 void EnableTerminationOnHeapCorruption() { 143 void EnableTerminationOnHeapCorruption() {
144 // On Linux, there nothing to do AFAIK. 144 // On Linux, there nothing to do AFAIK.
145 } 145 }
146 146
147 void EnableTerminationOnOutOfMemory() { 147 void EnableTerminationOnOutOfMemory() {
148 // Set the new-out of memory handler. 148 // Set the new-out of memory handler.
149 std::set_new_handler(&OnNoMemory); 149 std::set_new_handler(&OnNoMemory);
150 // If we're using glibc's allocator, the above functions will override 150 // If we're using glibc's allocator, the above functions will override
151 // malloc and friends and make them die on out of memory. 151 // malloc and friends and make them die on out of memory.
152 152
153 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 153 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
154 allocator::SetCallNewHandlerOnMallocFailure(true); 154 allocator::SetCallNewHandlerOnMallocFailure(true);
155 #elif defined(USE_TCMALLOC) 155 #elif defined(USE_TCMALLOC)
156 // For tcmalloc, we need to tell it to behave like new. 156 // For tcmalloc, we need to tell it to behave like new.
157 tc_set_new_mode(1); 157 tc_set_new_mode(1);
158 #endif 158 #endif
159 } 159 }
160 160
161 // NOTE: This is not the only version of this function in the source: 161 // NOTE: This is not the only version of this function in the source:
162 // the setuid sandbox (in process_util_linux.c, in the sandbox source) 162 // the setuid sandbox (in process_util_linux.c, in the sandbox source)
163 // also has its own C version. 163 // also has its own C version.
(...skipping 25 matching lines...) Expand all
189 std::string score_str = IntToString(converted_score); 189 std::string score_str = IntToString(converted_score);
190 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str; 190 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str;
191 int score_len = static_cast<int>(score_str.length()); 191 int score_len = static_cast<int>(score_str.length());
192 return (score_len == WriteFile(oom_file, score_str.c_str(), score_len)); 192 return (score_len == WriteFile(oom_file, score_str.c_str(), score_len));
193 } 193 }
194 194
195 return false; 195 return false;
196 } 196 }
197 197
198 bool UncheckedMalloc(size_t size, void** result) { 198 bool UncheckedMalloc(size_t size, void** result) {
199 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) 199 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
200 *result = allocator::UncheckedAlloc(size); 200 *result = allocator::UncheckedAlloc(size);
201 #elif defined(MEMORY_TOOL_REPLACES_ALLOCATOR) || \ 201 #elif defined(MEMORY_TOOL_REPLACES_ALLOCATOR) || \
202 (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)) 202 (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC))
203 *result = malloc(size); 203 *result = malloc(size);
204 #elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC) 204 #elif defined(LIBC_GLIBC) && !defined(USE_TCMALLOC)
205 *result = __libc_malloc(size); 205 *result = __libc_malloc(size);
206 #elif defined(USE_TCMALLOC) 206 #elif defined(USE_TCMALLOC)
207 *result = tc_malloc_skip_new_handler(size); 207 *result = tc_malloc_skip_new_handler(size);
208 #endif 208 #endif
209 return *result != NULL; 209 return *result != NULL;
210 } 210 }
211 211
212 } // namespace base 212 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/thread_heap_usage_tracker_unittest.cc ('k') | base/process/memory_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698