1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for
3 // full license information.
4 
5 #include <setjmp.h>
6 #include <windows.h>
7 #include "seh.h"
8 
9 char test[] = "SEH0013.c";
10 int perfect;
11 
12 void rtlRaiseException(DWORD Status) {
13   RaiseException(Status, 0, /*no flags*/ 0, 0);
14   return;
15 }
16 
17 void AccessViolation(PLONG BlackHole, PLONG BadAddress) {
18   *BlackHole += *BadAddress;
19   return;
20 }
21 
22 int main() {
23   PLONG BadAddress;
24   PCHAR BadByte;
25   PLONG BlackHole;
26   ULONG Index2 = 1;
27   LONG Counter;
28 
29   BadAddress = (PLONG)((PVOID)0);
30   BadByte = (PCHAR)((PVOID)0);
31   BadByte += 1;
32   BlackHole = &Counter;
33 
34   Counter = 0;
35 
36   try {
37     AccessViolation(BlackHole, BadAddress);
38   }
39   except((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ? 1 : 0)
40   /*
41    * exception handler should gete executed
42    * setting Counter to 1
43    */
44   {
45     Counter += 1;
46     try {
47       rtlRaiseException(EXCEPTION_CONTINUE_SEARCH);
48     }
49     except((GetExceptionCode() == EXCEPTION_CONTINUE_SEARCH) ? 1 : 0)
50     /* exception handler should get executed */
51     {
52       if (Counter != 1) {
53         printf("TEST 13 FAILED. Counter = %d\n\r", Counter);
54         return -1;
55       }
56       /* set's counter to 2 */
57       Counter += 1;
58     }
59     endtry
60   }
61   endtry
62 
63   if (Counter != 2) {
64     printf("TEST 13 FAILED. Counter= %d\n\r", Counter);
65     return -1;
66   }
67 
68   return 0;
69 }
70