From 69061d87fa158aa498fa9a4da722b1292b610ddd Mon Sep 17 00:00:00 2001 From: MerryMage Date: Thu, 23 Apr 2020 20:38:57 +0100 Subject: [PATCH] exception_handler_windows: Ignore irrelevant exceptions --- CMakeLists.txt | 1 + src/backend/x64/exception_handler_windows.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03558265..3a791af6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ if (MSVC) /Zc:inline # Omits inline functions from object-file output. /Zc:throwingNew # Assumes new (without std::nothrow) never returns null. /volatile:iso # Use strict standard-abiding volatile semantics + /bigobj # Increase number of sections in .obj files /DNOMINMAX) if (DYNARMIC_WARNINGS_AS_ERRORS) diff --git a/src/backend/x64/exception_handler_windows.cpp b/src/backend/x64/exception_handler_windows.cpp index 3f65a9cf..12f417cc 100644 --- a/src/backend/x64/exception_handler_windows.cpp +++ b/src/backend/x64/exception_handler_windows.cpp @@ -14,6 +14,7 @@ #include "common/assert.h" #include "common/cast_util.h" #include "common/common_types.h" +#include "common/safe_ops.h" using UBYTE = u8; @@ -175,6 +176,13 @@ struct ExceptionHandler::Impl final { code.align(16); const u8* exception_handler_with_cb = code.getCurr(); // Our 3rd argument is a PCONTEXT. + + // If not within our codeblock, ignore this exception. + code.mov(code.rax, Safe::Negate(Common::BitCast(code.getCode()))); + code.add(code.rax, code.qword[code.ABI_PARAM3 + Xbyak::RegExp(offsetof(CONTEXT, Rip))]); + code.cmp(code.rax, static_cast(code.GetTotalCodeSize())); + code.ja(exception_handler_without_cb); + code.sub(code.rsp, 8); code.mov(code.ABI_PARAM1, Common::BitCast(&cb)); code.mov(code.ABI_PARAM2, code.ABI_PARAM3);