Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / base / process / memory.cc
blob133a72a0f75a56e2890eb5b9cb7c71aac8597e9e
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.
5 #include "base/debug/alias.h"
6 #include "base/logging.h"
7 #include "base/process/memory.h"
9 namespace base {
11 namespace {
13 // Breakpad server classifies base::`anonymous namespace'::OnNoMemory as
14 // out-of-memory crash.
15 NOINLINE void OnNoMemory(size_t size) {
16 size_t tmp_size = size;
17 base::debug::Alias(&tmp_size);
18 LOG(FATAL) << "Out of memory. size=" << tmp_size;
21 } // namespace
23 void TerminateBecauseOutOfMemory(size_t size) {
24 OnNoMemory(size);
27 // Defined in memory_mac.mm for Mac.
28 #if !defined(OS_MACOSX)
30 bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
31 const size_t alloc_size = num_items * size;
33 // Overflow check
34 if (size && ((alloc_size / size) != num_items)) {
35 *result = NULL;
36 return false;
39 if (!UncheckedMalloc(alloc_size, result))
40 return false;
42 memset(*result, 0, alloc_size);
43 return true;
46 #endif
48 } // namespace base