source: trunk/testapp/exceptions/seh/crash.c

Last change on this file was 21999, checked in by dmik, 13 years ago

kernel32: Make SEH work in OS/2 context.

See #82 for details.

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1#include <stdio.h>
2#include <windows.h>
3#include <excpt.h>
4#include <setjmp.h>
5
6#ifndef _MSC_VER
7
8#include <odinlx.h>
9
10int _main();
11int _argc;
12char **_argv;
13
14int WIN32API WinMain(HANDLE hInstance,
15 HANDLE hPrevInstance,
16 LPSTR lpCmdLine,
17 int nCmdShow)
18{
19 return _main(_argc, _argv);
20}
21
22int main(int argc, char **argv)
23{
24 _argc = argc;
25 _argv = argv;
26#ifdef ODIN_FORCE_WIN32_TIB
27 ForceWin32TIB();
28#endif
29 RegisterLxExe(WinMain, NULL);
30}
31
32#else
33#define _main main
34#endif
35
36int exc_filter(PEXCEPTION_POINTERS pPtrs)
37{
38 PEXCEPTION_RECORD pRec = pPtrs->ExceptionRecord;
39
40 printf("\nexc_filter():\n");
41 printf("pPtrs %p\n", pPtrs);
42 printf("ExceptionCode %p\n", pRec->ExceptionCode);
43 printf("ExceptionAddress %p\n", pRec->ExceptionAddress);
44 printf("NumberParameters %d\n", pRec->NumberParameters);
45 printf("Returning EXCEPTION_CONTINUE_SEARCH.\n");
46
47 return EXCEPTION_CONTINUE_SEARCH;
48}
49
50void throw_EXCEPTION_INT_DIVIDE_BY_ZERO()
51{
52 printf("Throwing EXCEPTION_INT_DIVIDE_BY_ZERO...\n");
53 int x = 0;
54 volatile int y = 4 / x;
55}
56
57int test_1()
58{
59 printf("The program should now expectedly crash "
60 "(but NO POPUPLOG.OS2 entry!)...\n");
61 __try
62 {
63 printf("In outer try...\n");
64
65 __try
66 {
67 printf("In inner try...\n");
68
69 throw_EXCEPTION_INT_DIVIDE_BY_ZERO();
70
71 printf("FAILED: No inner exception!\n");
72 }
73 __except(exc_filter(exception_info()))
74 {
75 printf("FAILED: Inner exception handled.\n");
76 }
77
78 printf("FAILED: No outer exception!\n");
79 }
80 __except(exc_filter(exception_info()))
81 {
82 printf("FAILED: Inner exception handled.\n");
83 }
84
85 printf("FAILED: No exception at all!\n");
86 return 1;
87}
88
89void foo(int code)
90{
91 __try
92 {
93 printf("In foo(%d)...\n", code);
94
95 if (code == 2)
96 {
97 throw_EXCEPTION_INT_DIVIDE_BY_ZERO();
98 printf("FAILED: No exception!\n");
99 }
100 else
101 {
102 foo(code + 1);
103 }
104 }
105 __except(exc_filter(exception_info()))
106 {
107 printf("FAILED: foo(%d) exception handled.\n", code);
108 }
109}
110
111static
112DWORD WINAPI ThreadProc(LPVOID lpParameter)
113{
114 foo(0);
115 printf("FAILED: No exception at all!\n");
116 return 0;
117}
118
119int test_2()
120{
121 printf("The program should now expectedly crash "
122 "(and may be a NO POPUPLOG.OS2 entry)...\n");
123
124 HANDLE hThread = CreateThread(NULL, 0, ThreadProc, NULL, 0, NULL);
125 if (hThread == NULL)
126 {
127 printf("FAILED: CreateThread().");
128 return 1;
129 }
130
131 WaitForSingleObject(hThread, INFINITE);
132
133 return 1;
134}
135
136int _main(int argc, char **argv)
137{
138 int rc = test_2();
139
140 printf("Return (%d).\n", rc);
141
142 return rc;
143}
Note: See TracBrowser for help on using the repository browser.