diff --git a/reactos/apps/tests/pseh/.cvsignore b/reactos/apps/tests/pseh/.cvsignore new file mode 100644 index 00000000000..d63774a7353 --- /dev/null +++ b/reactos/apps/tests/pseh/.cvsignore @@ -0,0 +1,6 @@ +*.o +*.d +*.exe +*.coff +*.sym +*.map diff --git a/reactos/apps/tests/pseh/Makefile b/reactos/apps/tests/pseh/Makefile new file mode 100644 index 00000000000..2d19be7c6a5 --- /dev/null +++ b/reactos/apps/tests/pseh/Makefile @@ -0,0 +1,23 @@ +# $Id: Makefile,v 1.1 2004/06/03 04:15:40 hyperion Exp $ + +PATH_TO_TOP = ../../.. + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = pseh + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror -D__USE_W32API + +TARGET_SDKLIBS = pseh.a + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/reactos/apps/tests/pseh/pseh.c b/reactos/apps/tests/pseh/pseh.c new file mode 100644 index 00000000000..445e7a8efd9 --- /dev/null +++ b/reactos/apps/tests/pseh/pseh.c @@ -0,0 +1,128 @@ +#include +#include + +#define WIN32_LEAN_AND_MEAN +#define STRICT +#include + +#include + +_SEH_FILTER(main_filter0) +{ + fprintf(stderr, "filter 0: exception code %08lX\n", _SEH_GetExceptionCode()); + return EXCEPTION_EXECUTE_HANDLER; +} + +_SEH_FILTER(main_filter1) +{ + static int n; + + fputs("filter 1\n", stderr); + + _SEH_GetExceptionPointers()->ContextRecord->Eax = (DWORD)(UINT_PTR)&n; + + return EXCEPTION_CONTINUE_EXECUTION; +} + +_SEH_FILTER(main_filter2) +{ + fputs("filter 2\n", stderr); + return EXCEPTION_CONTINUE_SEARCH; +} + +_SEH_FINALLY(main_finally0) +{ + fputs("finally 0\n", stderr); +} + +_SEH_FINALLY(main_finally1) +{ + fputs("finally 1\n", stderr); + RaiseException(0xC0000006, 0, 0, NULL); +} + +_SEH_FINALLY(main_finally2) +{ + fputs("finally 2\n", stderr); +} + +int main(void) +{ + _SEH_TRY + { + _SEH_TRY + { + _SEH_TRY_FILTER(main_filter2) + { + _SEH_TRY_FINALLY(main_finally2) + { + _SEH_TRY_FILTER_FINALLY(main_filter0, main_finally0) + { + /* This exception is handled below */ + RaiseException(0xC0000005, 0, 0, NULL); + } + /* The finally is called no problem */ + _SEH_HANDLE + /* The filter returns EXCEPTION_EXECUTE_HANDLER */ + { + /* We handle the exception */ + fprintf(stderr, "caught exception %08lX\n", _SEH_GetExceptionCode()); + } + _SEH_END; + + _SEH_TRY_FILTER_FINALLY(main_filter1, main_finally1) + { + /* This faulting code is corrected by the filter */ +#ifdef __GNUC__ + __asm__("xorl %eax, %eax"); + __asm__("movl 0(%eax), %eax"); +#else + __asm xor eax, eax + __asm mov eax, [eax] +#endif + + /* Execution continues here */ + } + /* The finally misbehaves and throws an exception */ + _SEH_HANDLE + { + /* + This handler is never called, because the filter returns + EXCEPTION_CONTINUE_EXECUTION + */ + assert(0); + } + _SEH_END; + } + /* This finally is called after the next-to-outermost filter */ + _SEH_END_FINALLY; + } + _SEH_HANDLE + { + /* + This handler is never called, because the filter returns + EXCEPTION_CONTINUE_SEARCH + */ + assert(0); + } + _SEH_END; + } + _SEH_HANDLE + { + /* This handler handles the misbehavior of a finally */ + fprintf(stderr, "caught exception %08lX\n", _SEH_GetExceptionCode()); + + /* This handler misbehaves, too */ + RaiseException(0xC0000007, 0, 0, NULL); + } + _SEH_END; + } + _SEH_HANDLE + { + /* This handler catches the exception thrown by the previous handler */ + fprintf(stderr, "caught exception %08lX\n", _SEH_GetExceptionCode()); + } + _SEH_END; + + return 0; +}