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 #define faill()
9 #define startest()
10 #define finish()
11 
12 char test[] = "SEH0029.c";
13 int perfect;
14 
15 void AccessViolation(PLONG BlackHole, PLONG BadAddress) {
16   *BlackHole += *BadAddress;
17   return;
18 }
19 
20 int main() {
21   PCHAR BadByte;
22   PLONG BlackHole;
23   LONG Counter;
24   DWORD ExceptionCode;
25 
26   BadByte = (PCHAR)((PVOID)0);
27   BadByte += 1;
28   BlackHole = &Counter;
29 
30   Counter = 0;
31 
32   try {
33     /* set counter = 1 */
34     Counter += 1;
35     /*
36      * create a DATA MISALIGNMENT ERROR by passing
37      * a Byte into a LONG. Passing (PLONG)1.
38      */
39     AccessViolation(BlackHole, (PLONG)BadByte);
40   }
41   except((ExceptionCode = GetExceptionCode()),
42          ((ExceptionCode == STATUS_DATATYPE_MISALIGNMENT)
43               ? 1
44               : ((ExceptionCode == STATUS_ACCESS_VIOLATION) ? 1 : 0))) {
45     Counter += 1;
46   }
47   endtry
48 
49   if (Counter != 2) {
50     printf("TEST 29 FAILED. Counter = %d\n\r", Counter);
51     return -1;
52   } else {
53     /*
54     ISSUE-REVIEW:a-sibyvi-2003/10/20
55             This test was expecting STATUS_DATATYPE_MISALIGNMENT
56             which is no longer true for UTC and Phoenix. So changing the test
57             to expect Acces Violation instead.
58     ISSUE-REVIEW:v-simwal-2011-01-25 Either MISALIGNMENT or ACCESS VIOLATION
59     counts as a pass.
60         */
61     if ((ExceptionCode != STATUS_ACCESS_VIOLATION) &&
62         (ExceptionCode != STATUS_DATATYPE_MISALIGNMENT)) {
63       printf(
64           "TEST 29 FAILED. Expected ACCESS_VIOLATION, got exception = %d\n\r",
65           ExceptionCode);
66       return -1;
67     }
68   }
69   return 0;
70 }
71