Better classify OOM crashes on Windows.
In FX_OutOfMemoryTerminate(), raise the same exception as Chromium's
base::TerminateBecauseOutOfMemory().
Bug: pdfium:1771
Change-Id: I75b02328995e67e1c5f10634926e7d1f6fd6d346
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/90632
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/fx_memory.cpp b/core/fxcrt/fx_memory.cpp
index 7678cda..c0a9b8f 100644
--- a/core/fxcrt/fx_memory.cpp
+++ b/core/fxcrt/fx_memory.cpp
@@ -16,6 +16,10 @@
#include "third_party/base/debug/alias.h"
#include "third_party/base/no_destructor.h"
+#if BUILDFLAG(IS_WIN)
+#include <windows.h>
+#endif
+
pdfium::base::PartitionAllocatorGeneric& GetArrayBufferPartitionAllocator() {
static pdfium::base::NoDestructor<pdfium::base::PartitionAllocatorGeneric>
s_array_buffer_allocator;
@@ -72,7 +76,15 @@
static int make_this_function_aliased = 0xbd;
pdfium::base::debug::Alias(&make_this_function_aliased);
- // Termimate cleanly.
+#if BUILDFLAG(IS_WIN)
+ // The same custom Windows exception code used in Chromium and Breakpad.
+ constexpr DWORD kOomExceptionCode = 0xe0000008;
+ ULONG_PTR exception_args[] = {size};
+ ::RaiseException(kOomExceptionCode, EXCEPTION_NONCONTINUABLE,
+ pdfium::size(exception_args), exception_args);
+#endif
+
+ // Terminate cleanly.
abort();
}