Assembly Language for Beginners

(Jeff_L) #1

6.5. WINDOWS NT


The first two are located in our example. Two? But we made only one? Yes, another one has been
set up in theCRTfunction_mainCRTStartup(), and as it seems that it handles at leastFPUexceptions.
Its source code can be found in the MSVC installation:crt/src/winxfltr.c.


The third is the SEH4 one in ntdll.dll, and the fourth handler is not MSVC-related and is located in nt-
dll.dll, and has a self-describing function name.


As you can see, there are 3 types of handlers in one chain:


one is not related to MSVC at all (the last one) and two MSVC-related: SEH3 and SEH4.


SEH3: two try/except blocks example


#include <stdio.h>
#include <windows.h>
#include <excpt.h>


int filter_user_exceptions (unsigned int code, struct _EXCEPTION_POINTERS ep)
{
printf("in filter. code=0x%08X\n", code);
if (code == 0x112233)
{
printf("yes, that is our exception\n");
return EXCEPTION_EXECUTE_HANDLER;
}
else
{
printf("not our exception\n");
return EXCEPTION_CONTINUE_SEARCH;
};
}
int main()
{
int
p = NULL;
try
{
try
{
printf ("hello!\n");
RaiseException (0x112233, 0, 0, NULL);
printf ("0x112233 raised. now let's crash\n");
*p = 13; // causes an access violation exception;
}
except(GetExceptionCode()==EXCEPTION_ACCESS_VIOLATION?
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
printf("access violation, can't recover\n");
}
}
except(filter_user_exceptions(GetExceptionCode(), GetExceptionInformation()))
{
// the filter_user_exceptions() function answering to the question
// "is this exception belongs to this block?"
// if yes, do the follow:
printf("user exception caught\n");
}
}


Now there are twotryblocks. So thescope tablenow has two entries, one for each block.Previous try
levelchanges as execution flow enters or exits thetryblock.


Listing 6.29: MSVC 2003

$SG74606 DB 'in filter. code=0x%08X', 0aH, 00H
$SG74608 DB 'yes, that is our exception', 0aH, 00H
$SG74610 DB 'not our exception', 0aH, 00H
$SG74617 DB 'hello!', 0aH, 00H
$SG74619 DB '0x112233 raised. now let''s crash', 0aH, 00H

Free download pdf