void FatalConditionHandler::reset() {
     if (isSet) {
         // Unregister handler and restore the old guarantee
         RemoveVectoredExceptionHandler(exceptionHandlerHandle);
         SetThreadStackGuarantee(&guaranteeSize);
         exceptionHandlerHandle = nullptr;
         isSet = false;
     }
 }
 FatalConditionHandler::FatalConditionHandler() {
     isSet = true;
     // 32k seems enough for Catch to handle stack overflow,
     // but the value was found experimentally, so there is no strong guarantee
     guaranteeSize = 32 * 1024;
     exceptionHandlerHandle = nullptr;
     // Register as first handler in current chain
     exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
     // Pass in guarantee size to be filled
     SetThreadStackGuarantee(&guaranteeSize);
 }
Example #3
0
	Value catchRuntimeExceptions(const std::function<Value()>& thunk)
	{
		// Ensure that there's enough space left on the stack in the case of a stack overflow to prepare the stack trace.
		ULONG stackOverflowReserveBytes = 32768;
		SetThreadStackGuarantee(&stackOverflowReserveBytes);

		Exception* runtimeException = nullptr;
		__try
		{
			return thunk();
		}
		__except(sehFilterFunction(GetExceptionInformation(),runtimeException))
		{}

		if(runtimeException->cause == Exception::Cause::StackOverflow)
		{
			// After a stack overflow, the stack will be left in a damaged state. Let the CRT repair it.
			_resetstkoflw();
		}

		return Value(runtimeException);
	}