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