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 <windows.h>
6 #include "seh.h"
7 
8 char test[] = "SEH0011.c";
9 
10 void AccessViolation(PLONG BlackHole, PLONG BadAddress) {
11   *BlackHole += *BadAddress;
12   return;
13 }
14 
15 void tfAccessViolation(PLONG BlackHole, PLONG BadAddress, PLONG Counter) {
16   try {
17     AccessViolation(BlackHole, BadAddress);
18   }
19   finally {
20     if (abnormal_termination() != 0)
21     /*
22      * not abnormal termination
23      * counter should equal 99
24      */
25     {
26       *Counter = 99;
27     } else {
28       *Counter = 100;
29     }
30   } endtry
31   return;
32 }
33 
34 int main() {
35   PLONG BadAddress;
36   PLONG BlackHole;
37   LONG Counter;
38 
39   BadAddress = (PLONG)((PVOID)0);
40   BlackHole = &Counter;
41 
42   Counter = 0;
43 
44   try {
45     tfAccessViolation(BlackHole, BadAddress, &Counter);
46   }
47   except((GetExceptionCode() == STATUS_ACCESS_VIOLATION) ? 1 : 0)
48   /*
49    * acception raised was 0xC00000005L (ACCESS VIOLATION)
50    * execute handler
51    */
52   {
53     Counter -= 1;
54   }
55   endtry
56 
57   if (Counter != 98) {
58     printf("TEST 11 FAILED. Counter = %d\n\r", Counter);
59     return -1;
60   }
61 
62   return 0;
63 }
64