source: trunk/src/win32k/test/Zombie.c@ 10367

Last change on this file since 10367 was 7843, checked in by bird, 24 years ago

Testcase 3 is now 'working'.

File size: 5.4 KB
Line 
1/* $Id: Zombie.c,v 1.2 2002-02-08 14:27:19 bird Exp $
2 *
3 * Zombie Process creator
4 *
5 * Copyright (c) 2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10
11/*******************************************************************************
12* Defined Constants And Macros *
13*******************************************************************************/
14#define INCL_BASE
15
16
17/*******************************************************************************
18* Header Files *
19*******************************************************************************/
20#include <os2.h>
21#include <stdio.h>
22#include <stdlib.h>
23
24
25/*******************************************************************************
26* Internal Functions *
27*******************************************************************************/
28static void syntax(void);
29
30void Zombie1(void);
31VOID _System Zombie1Thread(ULONG ulIgnored);
32
33void Zombie2(void);
34ULONG _System Zombie2XcptHandler(
35 PEXCEPTIONREPORTRECORD pReport,
36 struct _EXCEPTIONREGISTRATIONRECORD * pERegRec,
37 PCONTEXTRECORD pContext,
38 PVOID pv);
39
40void Zombie3(void);
41VOID _System Zombie3ExitList(ULONG ul);
42
43
44/** @design Zombie Processes
45 * <ul>
46 * <li> 1. Suspend a thread & exit program.
47 * <li> 2. Block in exception handler.
48 * <li> 3. Block in exitlist.
49 * <li>
50 * </ul>
51 */
52
53
54int main(int argc, char **argv)
55{
56 int iZombie; /* Zombie number specified at the commandline. */
57
58
59 /*
60 * Syntax.
61 */
62 if (argc != 2)
63 {
64 syntax();
65 return -42;
66 }
67
68
69 /*
70 * Invoke the requested zombie creator.
71 */
72 switch (atoi(argv[1]))
73 {
74 case 1:
75 Zombie1();
76 break;
77
78 case 2:
79 Zombie2();
80 break;
81
82 case 3:
83 Zombie3();
84 break;
85
86 default:
87 fprintf(stderr, "error: invalid zombie type number, %s.\n", argv[1]);
88 syntax();
89 return -42;
90 }
91
92
93 /*
94 * Exit with return code 42 just to distiguish from
95 * any returncode set by OS/2 when killed.
96 */
97 return 42;
98}
99
100
101/**
102 * Display program commandline syntax.
103 */
104static void syntax(void)
105{
106 printf(
107 "Zombie.exe <zombie type no.>\n"
108 " Zombie types: \n"
109 " 1 Suspend a thread & exit program.\n"
110 " 2 Block in exception handler.\n"
111 " 3 Block in exitlist.\n"
112 );
113}
114
115
116/**
117 * Creates zombie situation 1.
118 */
119void Zombie1(void)
120{
121 TID tid;
122 APIRET rc;
123
124 printf("1 - Suspend a thread & exit program.\n");
125 flushall();
126 rc = DosCreateThread(&tid, Zombie1Thread, 0, 0, 16384);
127 if (rc == NO_ERROR)
128 {
129 #if 1
130 DosSleep(128); /* let the new thread start first */
131 rc = DosSuspendThread(tid);
132 if (rc == NO_ERROR)
133 {
134 DosExit(EXIT_PROCESS, 43);
135 printf("!!!internal error!!!\n");
136 }
137 else
138 fprintf(stderr, "DosSuspendThread failed with rc=%d\n", rc);
139 #else
140 for (;;)
141 DosSleep(0);
142 #endif
143 }
144 else
145 fprintf(stderr, "DosCreateThread failed with rc=%d\n ", rc);
146}
147
148/**
149 * Zombie 1 thread the one we'll supend.
150 */
151VOID _System Zombie1Thread(ULONG ulIgnored)
152{
153 #if 1
154 printf("Zombie1 Second thread is started.\n");
155 for (;;)
156 DosSleep(0);
157 #else
158 APIRET rc;
159 printf("Zombie1 Second thread is started.\n");
160 rc = DosSuspendThread(1);
161 if (rc == NO_ERROR)
162 {
163 DosExit(EXIT_PROCESS, 43);
164 printf("!!!internal error!!!\n");
165 }
166 else
167 fprintf(stderr, "DosSuspendThread failed with rc=%d\n", rc);
168 #endif
169}
170
171
172/**
173 * Creates zombie situation 2.
174 */
175void Zombie2(void)
176{
177 APIRET rc;
178 EXCEPTIONREGISTRATIONRECORD ERegRec;
179
180 printf("2 - Block in exception handler.\n");
181 flushall();
182
183 ERegRec.prev_structure = NULL;
184 ERegRec.ExceptionHandler = Zombie2XcptHandler;
185 rc = DosSetExceptionHandler(&ERegRec);
186 if (rc == NO_ERROR)
187 {
188 /* make exception - termination exception for example. */
189 DosExit(EXIT_PROCESS, 43);
190 printf("!!!internal error!!!\n");
191 }
192}
193
194/**
195 * Zombie 2 exceptionhandler - we'll block here.
196 */
197ULONG _System Zombie2XcptHandler(
198 PEXCEPTIONREPORTRECORD pReport,
199 struct _EXCEPTIONREGISTRATIONRECORD * pERegRec,
200 PCONTEXTRECORD pContext,
201 PVOID pv)
202{
203 /* block */
204 DosSleep(-1);
205}
206
207
208/**
209 * Creates zombie situation 3.
210 */
211void Zombie3(void)
212{
213 APIRET rc;
214
215 printf("3 - Block in exitlist.\n");
216 flushall();
217
218 rc = DosExitList(EXLST_ADD, Zombie3ExitList);
219 if (rc == NO_ERROR)
220 {
221 DosExit(EXIT_PROCESS, 43);
222 printf("!!!internal error!!!\n");
223 }
224 else
225 fprintf(stderr, "DosExistList failed with rc=%d\n");
226}
227
228
229/**
230 * Zombie 3 exit list handler - we'l block here.
231 */
232VOID _System Zombie3ExitList(ULONG ul)
233{
234 while (1)
235 {
236 ULONG ul;
237 DosSleep(-1);
238 DosWrite((HFILE)1, "zombie3: iterated\r\n", sizeof("zombie3: iterated\r\n") - 1, &ul);
239 }
240}
Note: See TracBrowser for help on using the repository browser.