xref: /aosp_15_r20/external/libchrome/base/process/memory_stubs.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #include "base/process/memory.h"
6*635a8641SAndroid Build Coastguard Worker 
7*635a8641SAndroid Build Coastguard Worker #include <stddef.h>
8*635a8641SAndroid Build Coastguard Worker #include <stdlib.h>
9*635a8641SAndroid Build Coastguard Worker 
10*635a8641SAndroid Build Coastguard Worker namespace base {
11*635a8641SAndroid Build Coastguard Worker 
EnableTerminationOnOutOfMemory()12*635a8641SAndroid Build Coastguard Worker void EnableTerminationOnOutOfMemory() {
13*635a8641SAndroid Build Coastguard Worker }
14*635a8641SAndroid Build Coastguard Worker 
EnableTerminationOnHeapCorruption()15*635a8641SAndroid Build Coastguard Worker void EnableTerminationOnHeapCorruption() {
16*635a8641SAndroid Build Coastguard Worker }
17*635a8641SAndroid Build Coastguard Worker 
AdjustOOMScore(ProcessId process,int score)18*635a8641SAndroid Build Coastguard Worker bool AdjustOOMScore(ProcessId process, int score) {
19*635a8641SAndroid Build Coastguard Worker   return false;
20*635a8641SAndroid Build Coastguard Worker }
21*635a8641SAndroid Build Coastguard Worker 
TerminateBecauseOutOfMemory(size_t size)22*635a8641SAndroid Build Coastguard Worker void TerminateBecauseOutOfMemory(size_t size) {
23*635a8641SAndroid Build Coastguard Worker   abort();
24*635a8641SAndroid Build Coastguard Worker }
25*635a8641SAndroid Build Coastguard Worker 
26*635a8641SAndroid Build Coastguard Worker // UncheckedMalloc and Calloc exist so that platforms making use of
27*635a8641SAndroid Build Coastguard Worker // EnableTerminationOnOutOfMemory have a way to allocate memory without
28*635a8641SAndroid Build Coastguard Worker // crashing. This _stubs.cc file is for platforms that do not support
29*635a8641SAndroid Build Coastguard Worker // EnableTerminationOnOutOfMemory (note the empty implementation above). As
30*635a8641SAndroid Build Coastguard Worker // such, these two Unchecked.alloc functions need only trivially pass-through to
31*635a8641SAndroid Build Coastguard Worker // their respective stdlib function since those functions will return null on a
32*635a8641SAndroid Build Coastguard Worker // failure to allocate.
33*635a8641SAndroid Build Coastguard Worker 
UncheckedMalloc(size_t size,void ** result)34*635a8641SAndroid Build Coastguard Worker bool UncheckedMalloc(size_t size, void** result) {
35*635a8641SAndroid Build Coastguard Worker   *result = malloc(size);
36*635a8641SAndroid Build Coastguard Worker   return *result != nullptr;
37*635a8641SAndroid Build Coastguard Worker }
38*635a8641SAndroid Build Coastguard Worker 
UncheckedCalloc(size_t num_items,size_t size,void ** result)39*635a8641SAndroid Build Coastguard Worker bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
40*635a8641SAndroid Build Coastguard Worker   *result = calloc(num_items, size);
41*635a8641SAndroid Build Coastguard Worker   return *result != nullptr;
42*635a8641SAndroid Build Coastguard Worker }
43*635a8641SAndroid Build Coastguard Worker 
44*635a8641SAndroid Build Coastguard Worker }  // namespace base
45