From bbc57fd5047349d1b013bb493fe6fca49848ff7e Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Mon, 15 Apr 2019 16:49:26 -0400 Subject: [PATCH] Protect against used wavmIntrensics exceptions hitting a brick wall on unwinding --- .../Source/Runtime/WAVMIntrinsics.cpp | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/libraries/wasm-jit/Source/Runtime/WAVMIntrinsics.cpp b/libraries/wasm-jit/Source/Runtime/WAVMIntrinsics.cpp index a85d0e21fcd..9e38eeebea0 100644 --- a/libraries/wasm-jit/Source/Runtime/WAVMIntrinsics.cpp +++ b/libraries/wasm-jit/Source/Runtime/WAVMIntrinsics.cpp @@ -9,9 +9,14 @@ namespace Runtime { static void causeIntrensicException(Exception::Cause cause) { - Platform::immediately_exit(std::make_exception_ptr(Exception{cause, std::vector()})); + try { + Platform::immediately_exit(std::make_exception_ptr(Exception{cause, std::vector()})); + } + catch (...) { + Platform::immediately_exit(std::current_exception()); + } __builtin_unreachable(); - } + } template Float quietNaN(Float value) @@ -145,19 +150,24 @@ namespace Runtime DEFINE_INTRINSIC_FUNCTION3(wavmIntrinsics,indirectCallSignatureMismatch,indirectCallSignatureMismatch,none,i32,index,i64,expectedSignatureBits,i64,tableBits) { - TableInstance* table = reinterpret_cast(tableBits); - void* elementValue = table->baseAddress[index].value; - const FunctionType* actualSignature = table->baseAddress[index].type; - const FunctionType* expectedSignature = reinterpret_cast((Uptr)expectedSignatureBits); - std::string ipDescription = ""; - LLVMJIT::describeInstructionPointer(reinterpret_cast(elementValue),ipDescription); - Log::printf(Log::Category::debug,"call_indirect signature mismatch: expected %s at index %u but got %s (%s)\n", - asString(expectedSignature).c_str(), - index, - actualSignature ? asString(actualSignature).c_str() : "nullptr", - ipDescription.c_str() - ); - causeIntrensicException(elementValue == nullptr ? Exception::Cause::undefinedTableElement : Exception::Cause::indirectCallSignatureMismatch); + try { + TableInstance* table = reinterpret_cast(tableBits); + void* elementValue = table->baseAddress[index].value; + const FunctionType* actualSignature = table->baseAddress[index].type; + const FunctionType* expectedSignature = reinterpret_cast((Uptr)expectedSignatureBits); + std::string ipDescription = ""; + LLVMJIT::describeInstructionPointer(reinterpret_cast(elementValue),ipDescription); + Log::printf(Log::Category::debug,"call_indirect signature mismatch: expected %s at index %u but got %s (%s)\n", + asString(expectedSignature).c_str(), + index, + actualSignature ? asString(actualSignature).c_str() : "nullptr", + ipDescription.c_str() + ); + causeIntrensicException(elementValue == nullptr ? Exception::Cause::undefinedTableElement : Exception::Cause::indirectCallSignatureMismatch); + } + catch (...) { + Platform::immediately_exit(std::current_exception()); + } } DEFINE_INTRINSIC_FUNCTION0(wavmIntrinsics,indirectCallIndexOutOfBounds,indirectCallIndexOutOfBounds,none)