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

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: Make possible to check memory allocations inside chromium Created 7 years, 1 month 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
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"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 __attribute__ ((visibility("default"))); 108 __attribute__ ((visibility("default")));
109 109
110 int posix_memalign(void** ptr, size_t alignment, size_t size) { 110 int posix_memalign(void** ptr, size_t alignment, size_t size) {
111 // This will use the safe version of memalign, above. 111 // This will use the safe version of memalign, above.
112 *ptr = memalign(alignment, size); 112 *ptr = memalign(alignment, size);
113 return 0; 113 return 0;
114 } 114 }
115 115
116 } // extern C 116 } // extern C
117 117
118 void* UncheckedMalloc(size_t size) {
119 return __libc_malloc(size);
120 }
121
118 #else 122 #else
119 123
120 // TODO(mostynb@opera.com): dlsym dance 124 // TODO(mostynb@opera.com): dlsym dance
121 125
122 #endif // LIBC_GLIBC && !USE_TCMALLOC 126 #endif // LIBC_GLIBC && !USE_TCMALLOC
123 127
124 #endif // !*_SANITIZER 128 #endif // !*_SANITIZER
125 129
130 #if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
131 defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER) || \
132 (!defined(LIBC_GLIBC) && !defined(USE_TCMALLOC))
133
134 void* UncheckedMalloc(size_t size) {
135 return malloc(size);
136 }
137
138 #endif
139
140 void* UncheckedCalloc(size_t num_items, size_t size) {
141 const size_t alloc_size = num_items * size;
142
143 // Overflow check
144 if (alloc_size && (alloc_size / size) != num_items)
145 return NULL;
146
147 void* result = UncheckedMalloc(alloc_size);
148 if (result)
149 memset(result, 0, alloc_size);
150 return result;
151 }
152
126 void EnableTerminationOnHeapCorruption() { 153 void EnableTerminationOnHeapCorruption() {
127 // On Linux, there nothing to do AFAIK. 154 // On Linux, there nothing to do AFAIK.
128 } 155 }
129 156
130 void EnableTerminationOnOutOfMemory() { 157 void EnableTerminationOnOutOfMemory() {
131 #if defined(OS_ANDROID) 158 #if defined(OS_ANDROID)
132 // Android doesn't support setting a new handler. 159 // Android doesn't support setting a new handler.
133 DLOG(WARNING) << "Not feasible."; 160 DLOG(WARNING) << "Not feasible.";
134 #else 161 #else
135 // Set the new-out of memory handler. 162 // Set the new-out of memory handler.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 int score_len = static_cast<int>(score_str.length()); 201 int score_len = static_cast<int>(score_str.length());
175 return (score_len == file_util::WriteFile(oom_file, 202 return (score_len == file_util::WriteFile(oom_file,
176 score_str.c_str(), 203 score_str.c_str(),
177 score_len)); 204 score_len));
178 } 205 }
179 206
180 return false; 207 return false;
181 } 208 }
182 209
183 } // namespace base 210 } // namespace base
OLDNEW
« no previous file with comments | « base/process/memory.h ('k') | base/process/memory_win.cc » ('j') | base/process/memory_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698