Home | History | Annotate | Download | only in partition_allocator
      1 // Copyright (c) 2016 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 #ifndef BASE_ALLOCATOR_OOM_H
      6 #define BASE_ALLOCATOR_OOM_H
      7 
      8 #include "third_party/base/logging.h"
      9 
     10 #if defined(OS_WIN)
     11 #include <windows.h>
     12 #endif
     13 
     14 // Do not want trivial entry points just calling OOM_CRASH() to be
     15 // commoned up by linker icf/comdat folding.
     16 #define OOM_CRASH_PREVENT_ICF()                  \
     17   volatile int oom_crash_inhibit_icf = __LINE__; \
     18   ALLOW_UNUSED_LOCAL(oom_crash_inhibit_icf)
     19 
     20 // OOM_CRASH() - Specialization of IMMEDIATE_CRASH which will raise a custom
     21 // exception on Windows to signal this is OOM and not a normal assert.
     22 #if defined(OS_WIN)
     23 #define OOM_CRASH()                                                     \
     24   do {                                                                  \
     25     OOM_CRASH_PREVENT_ICF();                                            \
     26     ::RaiseException(0xE0000008, EXCEPTION_NONCONTINUABLE, 0, nullptr); \
     27     IMMEDIATE_CRASH();                                                  \
     28   } while (0)
     29 #else
     30 #define OOM_CRASH()          \
     31   do {                       \
     32     OOM_CRASH_PREVENT_ICF(); \
     33     IMMEDIATE_CRASH();       \
     34   } while (0)
     35 #endif
     36 
     37 #endif  // BASE_ALLOCATOR_OOM_H
     38