Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

test.c File Reference

#include <stdio.h>
#include <process.h>
#include <setjmp.h>
#include <time.h>
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>

Go to the source code of this file.

Defines

#define TESTTABLESIZE   (128*sizeof(ULONG))

Functions

 TestDiv ()
VOID __cdecl main (int argc, argv)
 HandleException (IN PEXCEPTION_POINTERS ExceptionPointers)
 DivMarker ()

Variables

CONTEXT RegContext
ULONG DefaultValue
ULONG TestCount
ULONG ExpectedException
ULONG DivOperand
ULONG DivRegPointer
LONG DivRegScaler
ULONG ExceptEip
ULONG ExceptEsp
ULONG TestTable []
ULONG TestTableCenter []
BOOLEAN vInitialized
ULONG vZero = 0
ULONG vTwo = 0
ULONG vDivOk = 0x7f7f7f7f


Define Documentation

#define TESTTABLESIZE   (128*sizeof(ULONG))
 

Definition at line 31 of file test.c.

Referenced by HandleException().


Function Documentation

DivMarker  ) 
 

Definition at line 160 of file test.c.

References NULL, and RtlRaiseException().

00161 { 00162 EXCEPTION_RECORD ExceptionRecord; 00163 00164 // 00165 // Construct an exception record. 00166 // 00167 00168 ExceptionRecord.ExceptionCode = 1; 00169 ExceptionRecord.ExceptionRecord = (PEXCEPTION_RECORD)NULL; 00170 ExceptionRecord.NumberParameters = 0; 00171 ExceptionRecord.ExceptionFlags = 0; 00172 RtlRaiseException(&ExceptionRecord); 00173 }

HandleException IN PEXCEPTION_POINTERS  ExceptionPointers  ) 
 

Definition at line 98 of file test.c.

References DefaultValue, ExceptEip, ExceptEsp, EXCEPTION_CONTINUE_EXECUTION, EXCEPTION_CONTINUE_SEARCH, ExpectedException, TestCount, TestTable, TESTTABLESIZE, TRUE, and vInitialized.

Referenced by main().

00101 { 00102 ULONG i; 00103 PUCHAR p; 00104 PCONTEXT Context; 00105 ULONG def; 00106 00107 switch (i = ExceptionPointers->ExceptionRecord->ExceptionCode) { 00108 case 1: 00109 Context = ExceptionPointers->ContextRecord; 00110 Context->Eip = ExceptEip; 00111 Context->Esp = ExceptEsp; 00112 00113 if (vInitialized) { 00114 printf ("Divide failed - div instruction completed\n"); 00115 return EXCEPTION_CONTINUE_SEARCH; // to debugger 00116 } 00117 vInitialized = TRUE; 00118 TestCount--; 00119 // fall through... 00120 00121 case STATUS_INTEGER_OVERFLOW: 00122 case STATUS_INTEGER_DIVIDE_BY_ZERO: 00123 if (i != ExpectedException && i != 1) { 00124 break; 00125 } 00126 00127 TestCount++; 00128 00129 // set context 00130 def = DefaultValue; 00131 Context = ExceptionPointers->ContextRecord; 00132 Context->Eax = def; 00133 Context->Ebx = def; 00134 Context->Ecx = def; 00135 Context->Edx = def; 00136 Context->Esi = def; 00137 Context->Edi = def; 00138 Context->Ebp = def; 00139 00140 // find next test 00141 for (p = (PUCHAR) Context->Eip; ((PULONG) p)[0] != 0xCCCCCCCC; p++) ; 00142 Context->Eip = (ULONG) (p + 4); 00143 00144 // clear global testable 00145 RtlFillMemoryUlong (TestTable, TESTTABLESIZE, def); 00146 return EXCEPTION_CONTINUE_EXECUTION; 00147 } 00148 00149 printf ("\nFailed - unexpected exception code %lx (expected %lx)\n", 00150 ExceptionPointers->ExceptionRecord->ExceptionCode, 00151 ExpectedException 00152 ); 00153 00154 return EXCEPTION_CONTINUE_SEARCH; 00155 }

VOID __cdecl main int  argc,
argv 
 

Definition at line 42 of file test.c.

References DefaultValue, DivOperand, DivRegPointer, DivRegScaler, ExpectedException, FALSE, HandleException(), TestCount, TestDiv(), TestTableCenter, and vInitialized.

00045 { 00046 00047 /*** 00048 * This program tests the kernel's MOD/RM & SIB decoding of 00049 * a processor trap 0. The kernel needs to crack the MOD/RM & SIB 00050 * on a div to determine if the exception is a divide_by_zero 00051 * or an overflow execption. 00052 */ 00053 00054 try { 00055 // 00056 // Setup for divide by zero test 00057 // 00058 00059 DivOperand = 0; 00060 DivRegScaler = 0; 00061 DivRegPointer = TestTableCenter; 00062 DefaultValue = 0x01010101; 00063 ExpectedException = STATUS_INTEGER_DIVIDE_BY_ZERO; 00064 00065 printf ("Begin divide by zero test\n"); 00066 00067 for (DivRegScaler = -7; DivRegScaler < 7; DivRegScaler++) { 00068 vInitialized = FALSE; 00069 TestDiv (); 00070 } 00071 00072 printf ("End divide by zero test\n\n"); 00073 00074 // 00075 // Setup for divide overflow test 00076 // 00077 00078 DivOperand = 2; 00079 DivRegPointer = TestTableCenter; 00080 DefaultValue = 0; 00081 ExpectedException = STATUS_INTEGER_OVERFLOW; 00082 00083 printf ("Begin divide overflow test\n"); 00084 00085 for (DivRegScaler = -7; DivRegScaler < 7; DivRegScaler++) { 00086 vInitialized = FALSE; 00087 TestDiv (); 00088 } 00089 printf ("End divide overflow test\n\n"); 00090 00091 } except (HandleException(GetExceptionInformation())) { 00092 printf ("FAIL: in divide by zero exception handler"); 00093 } 00094 00095 printf ("%ld varations run ", TestCount); 00096 }

TestDiv  ) 
 

Referenced by main().


Variable Documentation

ULONG DefaultValue
 

Definition at line 20 of file test.c.

Referenced by HandleException(), and main().

ULONG DivOperand
 

Definition at line 24 of file test.c.

Referenced by main().

ULONG DivRegPointer
 

Definition at line 25 of file test.c.

Referenced by main().

LONG DivRegScaler
 

Definition at line 26 of file test.c.

Referenced by main().

ULONG ExceptEip
 

Definition at line 27 of file test.c.

Referenced by HandleException().

ULONG ExceptEsp
 

Definition at line 28 of file test.c.

Referenced by HandleException().

ULONG ExpectedException
 

Definition at line 22 of file test.c.

Referenced by HandleException(), and main().

CONTEXT RegContext
 

Copyright(c) Microsoft Corp., 1988-1991 *

Definition at line 19 of file test.c.

ULONG TestCount
 

Definition at line 21 of file test.c.

Referenced by HandleException(), and main().

ULONG TestTable[]
 

Definition at line 29 of file test.c.

Referenced by HandleException().

ULONG TestTableCenter[]
 

Definition at line 30 of file test.c.

Referenced by main().

ULONG vDivOk = 0x7f7f7f7f
 

Definition at line 38 of file test.c.

BOOLEAN vInitialized
 

Definition at line 35 of file test.c.

Referenced by HandleException(), and main().

ULONG vTwo = 0
 

Definition at line 37 of file test.c.

ULONG vZero = 0
 

Definition at line 36 of file test.c.


Generated on Sat May 15 19:45:44 2004 for test by doxygen 1.3.7