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" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str; | 173 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str; |
174 int score_len = static_cast<int>(score_str.length()); | 174 int score_len = static_cast<int>(score_str.length()); |
175 return (score_len == file_util::WriteFile(oom_file, | 175 return (score_len == file_util::WriteFile(oom_file, |
176 score_str.c_str(), | 176 score_str.c_str(), |
177 score_len)); | 177 score_len)); |
178 } | 178 } |
179 | 179 |
180 return false; | 180 return false; |
181 } | 181 } |
182 | 182 |
| 183 #if defined(USE_TCMALLOC) |
| 184 void* tc_try_malloc(size_t size) __THROW; |
| 185 #endif |
| 186 |
| 187 void* UncheckedMalloc(size_t size) { |
| 188 #if defined(USE_TCMALLOC) |
| 189 return tc_try_malloc(size); |
| 190 #elif defined(LIBC_GLIBC) |
| 191 return __libc_malloc(size); |
| 192 #else |
| 193 #error UncheckedMalloc not implemented on this OS/platform |
| 194 #endif |
| 195 } |
| 196 |
| 197 void* UncheckedCalloc(size_t num_items, size_t size) { |
| 198 const size_t alloc_size = num_items * size; |
| 199 |
| 200 // Overflow check |
| 201 if (alloc_size && (alloc_size / size) != num_items) |
| 202 return NULL; |
| 203 |
| 204 void* result = UncheckedMalloc(alloc_size); |
| 205 if (result) |
| 206 memset(result, 0, alloc_size); |
| 207 return result; |
| 208 } |
| 209 |
183 } // namespace base | 210 } // namespace base |
OLD | NEW |