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