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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 namespace base { | 10 namespace base { |
11 | 11 |
12 void EnableTerminationOnOutOfMemory() { | 12 void EnableTerminationOnOutOfMemory() { |
13 } | 13 } |
14 | 14 |
15 void EnableTerminationOnHeapCorruption() { | 15 void EnableTerminationOnHeapCorruption() { |
16 } | 16 } |
17 | 17 |
18 bool AdjustOOMScore(ProcessId process, int score) { | 18 bool AdjustOOMScore(ProcessId process, int score) { |
19 return false; | 19 return false; |
20 } | 20 } |
21 | 21 |
| 22 void TerminateBecauseOutOfMemory(size_t size) { |
| 23 abort(); |
| 24 } |
| 25 |
22 // UncheckedMalloc and Calloc exist so that platforms making use of | 26 // UncheckedMalloc and Calloc exist so that platforms making use of |
23 // EnableTerminationOnOutOfMemory have a way to allocate memory without | 27 // EnableTerminationOnOutOfMemory have a way to allocate memory without |
24 // crashing. This _stubs.cc file is for platforms that do not support | 28 // crashing. This _stubs.cc file is for platforms that do not support |
25 // EnableTerminationOnOutOfMemory (note the empty implementation above). As | 29 // EnableTerminationOnOutOfMemory (note the empty implementation above). As |
26 // such, these two Unchecked.alloc functions need only trivially pass-through to | 30 // such, these two Unchecked.alloc functions need only trivially pass-through to |
27 // their respective stdlib function since those functions will return null on a | 31 // their respective stdlib function since those functions will return null on a |
28 // failure to allocate. | 32 // failure to allocate. |
29 | 33 |
30 bool UncheckedMalloc(size_t size, void** result) { | 34 bool UncheckedMalloc(size_t size, void** result) { |
31 *result = malloc(size); | 35 *result = malloc(size); |
32 return *result != nullptr; | 36 return *result != nullptr; |
33 } | 37 } |
34 | 38 |
35 bool UncheckedCalloc(size_t num_items, size_t size, void** result) { | 39 bool UncheckedCalloc(size_t num_items, size_t size, void** result) { |
36 *result = calloc(num_items, size); | 40 *result = calloc(num_items, size); |
37 return *result != nullptr; | 41 return *result != nullptr; |
38 } | 42 } |
39 | 43 |
40 } // namespace base | 44 } // namespace base |
OLD | NEW |