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