oom.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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. #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_OOM_H_
  5. #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_OOM_H_
  6. #include "base/allocator/partition_allocator/oom_callback.h"
  7. #include "base/process/memory.h"
  8. #include "build/build_config.h"
  9. #if defined(OS_WIN)
  10. #include <windows.h>
  11. #endif
  12. namespace {
  13. // The crash is generated in a NOINLINE function so that we can classify the
  14. // crash as an OOM solely by analyzing the stack trace.
  15. NOINLINE void OnNoMemory(size_t size) {
  16. base::internal::RunPartitionAllocOomCallback();
  17. base::internal::OnNoMemoryInternal(size);
  18. IMMEDIATE_CRASH();
  19. }
  20. } // namespace
  21. // OOM_CRASH(size) - Specialization of IMMEDIATE_CRASH which will raise a custom
  22. // exception on Windows to signal this is OOM and not a normal assert.
  23. // OOM_CRASH(size) is called by users of PageAllocator (including
  24. // PartitionAlloc) to signify an allocation failure from the platform.
  25. #define OOM_CRASH(size) \
  26. do { \
  27. OnNoMemory(size); \
  28. } while (0)
  29. #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_OOM_H_