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