VOID WINAPI RtlLeaveCriticalSection_ver0(__inout WND::LPCRITICAL_SECTION lpCriticalSection)
{
    if (lpCriticalSection == NULL)
    {
        int* ptr = reinterpret_cast<int*>(0x0);
        __try
        {
            // this will cause an exception
            *ptr = 17;
        }
        __except(EXCEPTION_EXECUTE_HANDLER)
        {
            printf("Exception in RtlLeaveCriticalSection replacement routine\n");
            fflush(stdout);
        }

        __try
        {
            volatile int i  = GenerateStackOverflow();
        }
        __except(EXCEPTION_EXECUTE_HANDLER)
        {
            if(_resetstkoflw())
            {
                printf("Stack-Overflow in RtlLeaveCriticalSection replacement routine\n");
                fflush(stdout);
            }
        }
    }
Example #2
0
/*
=================
idRenderModelManagerLocal::FindSkeletalMeshes
=================
*/
void idRenderModelManagerLocal::FindSkeletalMeshes( idList<idStr> &skeletalMeshes ) {
	const idDecl *decl;

	skeletalMeshes.Clear();

	for(int i = 0; i < declManager->GetNumDecls( DECL_MODELDEF ); i++)
	{
		decl = declManager->DeclByIndex( DECL_MODELDEF, i, false );

		// This probley isn't the best way to do this, just check to see if the decl def has the skeletal model extension.
		char *text = (char *)_alloca( decl->GetTextLength() + 1 );
		decl->GetText( text );
		if(!strstr(text, ".md5mesh"))
		{
			_resetstkoflw();
			continue;
		}

		_resetstkoflw();

		skeletalMeshes.Append( decl->GetName() );
	}
}
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);
	}
Example #4
0
// Restore thread local state to saved state in error handler `eh`.
// This is executed in two circumstances:
// * We leave a try block through normal control flow
// * An exception causes a nonlocal jump to the catch block. In this case
//   there's additional cleanup required, eg pushing the exception stack.
JL_DLLEXPORT void jl_eh_restore_state(jl_handler_t *eh)
{
    jl_ptls_t ptls = jl_get_ptls_states();
#ifdef _OS_WINDOWS_
    if (ptls->needs_resetstkoflw) {
        _resetstkoflw();
        ptls->needs_resetstkoflw = 0;
    }
#endif
    jl_task_t *current_task = ptls->current_task;
    // `eh` may be not equal to `ptls->current_task->eh`. See `jl_pop_handler`
    // This function should **NOT** have any safepoint before the ones at the
    // end.
    sig_atomic_t old_defer_signal = ptls->defer_signal;
    int8_t old_gc_state = ptls->gc_state;
    current_task->eh = eh->prev;
    ptls->pgcstack = eh->gcstack;
#ifdef JULIA_ENABLE_THREADING
    arraylist_t *locks = &current_task->locks;
    if (locks->len > eh->locks_len) {
        for (size_t i = locks->len;i > eh->locks_len;i--)
            jl_mutex_unlock_nogc((jl_mutex_t*)locks->items[i - 1]);
        locks->len = eh->locks_len;
    }
#endif
    ptls->world_age = eh->world_age;
    ptls->defer_signal = eh->defer_signal;
    ptls->gc_state = eh->gc_state;
    ptls->finalizers_inhibited = eh->finalizers_inhibited;
    if (old_gc_state && !eh->gc_state) {
        jl_gc_safepoint_(ptls);
    }
    if (old_defer_signal && !eh->defer_signal) {
        jl_sigint_safepoint(ptls);
    }
}
Example #5
0
/*
 * Return non-zero when we run out of memory on the stack; zero otherwise.
 */
int
PyOS_CheckStack(void)
{
    __try {
        /* alloca throws a stack overflow exception if there's
           not enough space left on the stack */
        alloca(PYOS_STACK_MARGIN * sizeof(void*));
        return 0;
    } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ?
                    EXCEPTION_EXECUTE_HANDLER :
            EXCEPTION_CONTINUE_SEARCH) {
        int errcode = _resetstkoflw();
        if (errcode == 0)
        {
            Py_FatalError("Could not reset the stack!");
        }
    }
    return 1;
}

#endif /* WIN32 && _MSC_VER */

/* Alternate implementations can be added here... */

#endif /* USE_STACKCHECK */

/* Deprecated C API functions still provided for binary compatibility */