Manually installed SEH does not work in indoor units

After reading The Crash Course and a few posts here, I have implemented a very basic version. My only requirement is to be able to "catch" any exception (only "Win32" as I don't throw / raise) and exit the thread that raised it. I have a properly prototyped function that simply calls "ExitThread" and an "EXCEPTION_REGISTRATION" structure that has a handler property in it, and the actual previous descriptor of the previous property. What I am doing to set this handler calls:

BOOL set_my_handler(){
EXCEPTION_REGISTRATION* p_excep = &excep // excep is a global static EXCEPTION_REGISTRATION
__asm{
      mov EAX, p_excep
      mov FS:[0],EAX
 }
 ...
 }

      

Problem: when I throw an exception (say:

* (dword*) 0 = 0;) 

      

in the same area I named set_my_handler, my handler is called expected. But, if I throw the same exception in the inner block by calling the function that does it, it just doesn't work. I am getting Unhandled Exception. while debugging, I noticed that FS: [0] remains unchanged (pointing to my handler) in the inner function. BTW, I am not using any (try / catch or try / _except in my code)

I appreciate your help, thanks.

The answer to my problem (thanks to Raymond Chen): It turns out that the exception registration objects need to be allocated on the stack, as there is a security mechanism that checks its location against the stack segment registers.

+3


source to share





All Articles