Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.5 KiB

  1. /*****************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1988-1991 **/
  4. /*****************************************************************/
  5. #include <stdio.h>
  6. #include <process.h>
  7. #include <setjmp.h>
  8. #include <time.h>
  9. #include <nt.h>
  10. #include <ntrtl.h>
  11. #include <nturtl.h>
  12. #include <windows.h>
  13. // declare a BSS value - see what the assemble looks like
  14. CONTEXT RegContext;
  15. ULONG DefaultValue;
  16. ULONG TestCount;
  17. ULONG ExpectedException;
  18. extern ULONG DivOperand;
  19. extern ULONG DivRegPointer;
  20. extern LONG DivRegScaler;
  21. extern ULONG ExceptEip;
  22. extern ULONG ExceptEsp;
  23. extern ULONG TestTable[];
  24. extern ULONG TestTableCenter[];
  25. #define TESTTABLESIZE (128*sizeof(ULONG))
  26. extern TestDiv();
  27. BOOLEAN vInitialized;
  28. ULONG vZero = 0;
  29. ULONG vTwo = 0;
  30. ULONG vDivOk = 0x7f7f7f7f;
  31. VOID __cdecl
  32. main (argc, argv)
  33. int argc;
  34. char *argv[];
  35. {
  36. /***
  37. * This program tests the kernel's MOD/RM & SIB decoding of
  38. * a processor trap 0. The kernel needs to crack the MOD/RM & SIB
  39. * on a div to determine if the exception is a divide_by_zero
  40. * or an overflow execption.
  41. */
  42. try {
  43. //
  44. // Setup for divide by zero test
  45. //
  46. DivOperand = 0;
  47. DivRegScaler = 0;
  48. DivRegPointer = TestTableCenter;
  49. DefaultValue = 0x01010101;
  50. ExpectedException = STATUS_INTEGER_DIVIDE_BY_ZERO;
  51. printf ("Begin divide by zero test\n");
  52. for (DivRegScaler = -7; DivRegScaler < 7; DivRegScaler++) {
  53. vInitialized = FALSE;
  54. TestDiv ();
  55. }
  56. printf ("End divide by zero test\n\n");
  57. //
  58. // Setup for divide overflow test
  59. //
  60. DivOperand = 2;
  61. DivRegPointer = TestTableCenter;
  62. DefaultValue = 0;
  63. ExpectedException = STATUS_INTEGER_OVERFLOW;
  64. printf ("Begin divide overflow test\n");
  65. for (DivRegScaler = -7; DivRegScaler < 7; DivRegScaler++) {
  66. vInitialized = FALSE;
  67. TestDiv ();
  68. }
  69. printf ("End divide overflow test\n\n");
  70. } except (HandleException(GetExceptionInformation())) {
  71. printf ("FAIL: in divide by zero exception handler");
  72. }
  73. printf ("%ld varations run ", TestCount);
  74. }
  75. HandleException (
  76. IN PEXCEPTION_POINTERS ExceptionPointers
  77. )
  78. {
  79. ULONG i;
  80. PUCHAR p;
  81. PCONTEXT Context;
  82. ULONG def;
  83. switch (i = ExceptionPointers->ExceptionRecord->ExceptionCode) {
  84. case 1:
  85. Context = ExceptionPointers->ContextRecord;
  86. Context->Eip = ExceptEip;
  87. Context->Esp = ExceptEsp;
  88. if (vInitialized) {
  89. printf ("Divide failed - div instruction completed\n");
  90. return EXCEPTION_CONTINUE_SEARCH; // to debugger
  91. }
  92. vInitialized = TRUE;
  93. TestCount--;
  94. // fall through...
  95. case STATUS_INTEGER_OVERFLOW:
  96. case STATUS_INTEGER_DIVIDE_BY_ZERO:
  97. if (i != ExpectedException && i != 1) {
  98. break;
  99. }
  100. TestCount++;
  101. // set context
  102. def = DefaultValue;
  103. Context = ExceptionPointers->ContextRecord;
  104. Context->Eax = def;
  105. Context->Ebx = def;
  106. Context->Ecx = def;
  107. Context->Edx = def;
  108. Context->Esi = def;
  109. Context->Edi = def;
  110. Context->Ebp = def;
  111. // find next test
  112. for (p = (PUCHAR) Context->Eip; ((PULONG) p)[0] != 0xCCCCCCCC; p++) ;
  113. Context->Eip = (ULONG) (p + 4);
  114. // clear global testable
  115. RtlFillMemoryUlong (TestTable, TESTTABLESIZE, def);
  116. return EXCEPTION_CONTINUE_EXECUTION;
  117. }
  118. printf ("\nFailed - unexpected exception code %lx (expected %lx)\n",
  119. ExceptionPointers->ExceptionRecord->ExceptionCode,
  120. ExpectedException
  121. );
  122. return EXCEPTION_CONTINUE_SEARCH;
  123. }
  124. DivMarker()
  125. {
  126. EXCEPTION_RECORD ExceptionRecord;
  127. //
  128. // Construct an exception record.
  129. //
  130. ExceptionRecord.ExceptionCode = 1;
  131. ExceptionRecord.ExceptionRecord = (PEXCEPTION_RECORD)NULL;
  132. ExceptionRecord.NumberParameters = 0;
  133. ExceptionRecord.ExceptionFlags = 0;
  134. RtlRaiseException(&ExceptionRecord);
  135. }