Why SetUnhandledExceptionFilter cannot capture some exception but AddVectoredExceptionHandler can do

后端 未结 2 1682
夕颜
夕颜 2020-12-13 09:54

I have experienced a problem that the function I passed to the SetUnhandledExceptionFilter didn\'t get called when the exception code c0000374 raising. But it works fine wit

相关标签:
2条回答
  • 2020-12-13 10:29

    The exception is actually caught directly at its source, in RtlReportCriticalFailure, called by the heap manager once heap corruption is detected. The SEH handler registered in this function calls RtlReportException, quickly followed by NtTerminateProcess.

    I can only conclude that SEH handlers are avoided on purpose -- with the heap corrupted, the stack contents (and therefore SEH registrations) are suspect too; and the application can't reasonably recover from heap corruption anyway.

    0 讨论(0)
  • 2020-12-13 10:32

    It happens because of this code in MSVC CRT startup:

        /*
         * Enable app termination when heap corruption is detected on
         * Windows Vista and above. This is a no-op on down-level OS's
         * and enabled by default for 64-bit processes.
         */
    
        if (!_NoHeapEnableTerminationOnCorruption)
        {
            HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
        }
    

    If you want to disable it (not recommended), link nohetoc.obj to your program.

    0 讨论(0)
提交回复
热议问题