| Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
| [email protected] | bac98410 | 2013-06-28 17:40:24 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/process/memory.h" |
| 6 | |
| avi | beced7c | 2015-12-24 06:47:59 | [diff] [blame] | 7 | #include <stddef.h> |
| grt | 5fb37b7f | 2015-11-06 21:56:06 | [diff] [blame] | 8 | #include <stdlib.h> |
| 9 | |
| [email protected] | bac98410 | 2013-06-28 17:40:24 | [diff] [blame] | 10 | namespace base { |
| 11 | |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 12 | void EnableTerminationOnOutOfMemory() {} |
| [email protected] | bac98410 | 2013-06-28 17:40:24 | [diff] [blame] | 13 | |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 14 | void EnableTerminationOnHeapCorruption() {} |
| [email protected] | bac98410 | 2013-06-28 17:40:24 | [diff] [blame] | 15 | |
| 16 | bool AdjustOOMScore(ProcessId process, int score) { |
| 17 | return false; |
| 18 | } |
| 19 | |
| grt | 5fb37b7f | 2015-11-06 21:56:06 | [diff] [blame] | 20 | // UncheckedMalloc and Calloc exist so that platforms making use of |
| 21 | // EnableTerminationOnOutOfMemory have a way to allocate memory without |
| 22 | // crashing. This _stubs.cc file is for platforms that do not support |
| 23 | // EnableTerminationOnOutOfMemory (note the empty implementation above). As |
| 24 | // such, these two Unchecked.alloc functions need only trivially pass-through to |
| 25 | // their respective stdlib function since those functions will return null on a |
| 26 | // failure to allocate. |
| 27 | |
| 28 | bool UncheckedMalloc(size_t size, void** result) { |
| 29 | *result = malloc(size); |
| 30 | return *result != nullptr; |
| 31 | } |
| 32 | |
| 33 | bool UncheckedCalloc(size_t num_items, size_t size, void** result) { |
| 34 | *result = calloc(num_items, size); |
| 35 | return *result != nullptr; |
| 36 | } |
| 37 | |
| Dave Tapuska | 1289751 | 2023-01-10 14:52:09 | [diff] [blame] | 38 | void UncheckedFree(void* ptr) { |
| 39 | free(ptr); |
| 40 | } |
| 41 | |
| [email protected] | bac98410 | 2013-06-28 17:40:24 | [diff] [blame] | 42 | } // namespace base |