• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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/debug/alias.h"
6 #include "base/logging.h"
7 #include "base/process/memory.h"
8 #include "build/build_config.h"
9 
10 namespace base {
11 
12 // Defined in memory_win.cc for Windows.
13 #if !defined(OS_WIN)
14 
15 namespace {
16 
17 // Breakpad server classifies base::`anonymous namespace'::OnNoMemory as
18 // out-of-memory crash.
OnNoMemory(size_t size)19 NOINLINE void OnNoMemory(size_t size) {
20   size_t tmp_size = size;
21   base::debug::Alias(&tmp_size);
22   LOG(FATAL) << "Out of memory. size=" << tmp_size;
23 }
24 
25 }  // namespace
26 
TerminateBecauseOutOfMemory(size_t size)27 void TerminateBecauseOutOfMemory(size_t size) {
28   OnNoMemory(size);
29 }
30 
31 #endif
32 
33 // Defined in memory_mac.mm for Mac.
34 #if !defined(OS_MACOSX)
35 
UncheckedCalloc(size_t num_items,size_t size,void ** result)36 bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
37   const size_t alloc_size = num_items * size;
38 
39   // Overflow check
40   if (size && ((alloc_size / size) != num_items)) {
41     *result = nullptr;
42     return false;
43   }
44 
45   if (!UncheckedMalloc(alloc_size, result))
46     return false;
47 
48   memset(*result, 0, alloc_size);
49   return true;
50 }
51 
52 #endif
53 
54 }  // namespace base
55