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 
rtlRaiseException(DWORD Status)11 void rtlRaiseException(DWORD Status) {
12   RaiseException(Status, 0, /*no flags*/ 0, 0);
13   return;
14 }
15 
AccessViolation(PLONG BlackHole,PLONG BadAddress)16 void AccessViolation(PLONG BlackHole, PLONG BadAddress) {
17   *BlackHole += *BadAddress;
18   return;
19 }
20 
main()21 int main() {
22   PLONG BadAddress;
23   PCHAR BadByte;
24   PLONG BlackHole;
25   ULONG Index2 = 1;
26   LONG Counter;
27 
28   BadAddress = (PLONG)((PVOID)0);
29   BadByte = (PCHAR)((PVOID)0);
30   BadByte += 1;
31   BlackHole = &Counter;
32 
33   Counter = 0;
34 
35   try {
36     AccessViolation(BlackHole, BadAddress);
37   }
38   except((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ? 1 : 0)
39   /*
40    * exception handler should gete executed
41    * setting Counter to 1
42    */
43   {
44     Counter += 1;
45     try {
46       rtlRaiseException(EXCEPTION_CONTINUE_SEARCH);
47     }
48     except((GetExceptionCode() == EXCEPTION_CONTINUE_SEARCH) ? 1 : 0)
49     /* exception handler should get executed */
50     {
51       if (Counter != 1) {
52         printf("TEST 13 FAILED. Counter = %d\n\r", Counter);
53         return -1;
54       }
55       /* set's counter to 2 */
56       Counter += 1;
57     }
58     endtry
59   }
60   endtry
61 
62   if (Counter != 2) {
63     printf("TEST 13 FAILED. Counter= %d\n\r", Counter);
64     return -1;
65   }
66 
67   return 0;
68 }
69