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.

284 lines
5.0 KiB

  1. #include <ntosp.h>
  2. extern KEVENT CrashEvent;
  3. extern ULONG CrashRequest;
  4. unsigned int fExcept1 = 0;
  5. unsigned int cTry1 = 0;
  6. unsigned int cRaise1pre = 0;
  7. unsigned int cRaise1post = 0;
  8. unsigned int cExcept1 = 0;
  9. unsigned int cFilter1 = 0;
  10. unsigned int fExcept2 = 0;
  11. unsigned int cTry2 = 0;
  12. unsigned int cRaise2pre = 0;
  13. unsigned int cRaise2post = 0;
  14. unsigned int cFinally2 = 0;
  15. unsigned int fExcept3 = 0;
  16. unsigned int cTry3 = 0;
  17. unsigned int cRaise3pre = 0;
  18. unsigned int cRaise3post = 0;
  19. unsigned int cExcept3 = 0;
  20. unsigned int cFilter3 = 0;
  21. unsigned int fExcept4 = 0;
  22. unsigned int cTry4 = 0;
  23. unsigned int cRaise4pre = 0;
  24. unsigned int cRaise4post = 0;
  25. unsigned int cFinally4 = 0;
  26. unsigned int fExcept5 = 0;
  27. unsigned int cTry5 = 0;
  28. unsigned int cRaise5pre = 0;
  29. unsigned int cRaise5post = 0;
  30. unsigned int cExcept5 = 0;
  31. unsigned int cFilter5 = 0;
  32. unsigned long GlobalVar = 0;
  33. int ExceptFilterFn5 (int ExceptCode)
  34. {
  35. DbgPrint( "CrashDrv exception filter\n" );
  36. cFilter5 ++;
  37. return ExceptCode == 0x00003344 ? EXCEPTION_EXECUTE_HANDLER :
  38. EXCEPTION_CONTINUE_EXECUTION ;
  39. }
  40. void function5 ()
  41. {
  42. _try
  43. {
  44. cTry5 ++;
  45. if (fExcept5)
  46. {
  47. cRaise5pre ++;
  48. ExRaiseStatus( fExcept4 );
  49. cRaise5post ++;
  50. }
  51. }
  52. _except (ExceptFilterFn5 (GetExceptionCode ()))
  53. {
  54. cExcept5 ++;
  55. }
  56. }
  57. void function4 ()
  58. {
  59. _try
  60. {
  61. cTry4 ++;
  62. function5 ();
  63. if (fExcept4)
  64. {
  65. cRaise4pre ++;
  66. ExRaiseStatus( fExcept4 );
  67. cRaise4post ++;
  68. }
  69. }
  70. _finally
  71. {
  72. cFinally4 ++;
  73. }
  74. }
  75. int ExceptFilterFn3 (int ExceptCode)
  76. {
  77. cFilter3 ++;
  78. return ExceptCode == 0x00005678 ? EXCEPTION_EXECUTE_HANDLER :
  79. EXCEPTION_CONTINUE_SEARCH ;
  80. }
  81. void function3 ()
  82. {
  83. _try
  84. {
  85. cTry3 ++;
  86. function4 ();
  87. if (fExcept3)
  88. {
  89. cRaise3pre ++;
  90. ExRaiseStatus( fExcept3 );
  91. cRaise3post ++;
  92. }
  93. }
  94. _except (ExceptFilterFn3 (GetExceptionCode ()))
  95. {
  96. cExcept3 ++;
  97. }
  98. }
  99. void function2 ()
  100. {
  101. _try
  102. {
  103. cTry2 ++;
  104. function3 ();
  105. if (fExcept2)
  106. {
  107. cRaise2pre ++;
  108. ExRaiseStatus( fExcept2 );
  109. cRaise2post ++;
  110. }
  111. }
  112. _finally
  113. {
  114. cFinally2 ++;
  115. }
  116. }
  117. int ExceptFilterMain (int ExceptCode)
  118. {
  119. cFilter1 ++;
  120. return ExceptCode == 0x00001010 ? EXCEPTION_EXECUTE_HANDLER :
  121. ExceptCode == 0x00005678 ? EXCEPTION_CONTINUE_EXECUTION :
  122. EXCEPTION_CONTINUE_SEARCH ;
  123. }
  124. VOID
  125. CrashDrvExceptionTest(
  126. PULONG ub
  127. )
  128. {
  129. int i = 0;
  130. while ( i++ < 10 ) {
  131. _try {
  132. cTry1 ++;
  133. function2 ();
  134. if (fExcept1) {
  135. cRaise1pre ++;
  136. ExRaiseStatus( fExcept1 );
  137. cRaise1post ++;
  138. }
  139. }
  140. _except (ExceptFilterMain (GetExceptionCode ())) {
  141. cExcept1 ++;
  142. }
  143. fExcept1 = 0;
  144. fExcept2 = 0;
  145. fExcept3 = 0;
  146. fExcept4 = 0;
  147. fExcept5 = 0;
  148. }
  149. }
  150. VOID
  151. CrashDrvSimpleTest(
  152. PULONG ub
  153. )
  154. {
  155. int i = 0;
  156. int j = 0;
  157. int k = 0;
  158. GlobalVar = 69;
  159. i = 1;
  160. j = 2;
  161. k = 3;
  162. }
  163. #pragma warning(disable:4717) // disable recursion check
  164. VOID
  165. CrashDrvStackOverFlow(
  166. PULONG ub
  167. )
  168. {
  169. struct {
  170. int a;
  171. int b;
  172. int c;
  173. int d;
  174. int e;
  175. int f;
  176. int g;
  177. int h;
  178. int i;
  179. } Foo;
  180. RtlFillMemory (&Foo, 'a', sizeof (Foo));
  181. CrashDrvStackOverFlow ((PVOID) &Foo);
  182. return;
  183. }
  184. VOID
  185. CrashDrvBugCheck(
  186. PULONG ub
  187. )
  188. {
  189. KeBugCheck( 0x69696969 );
  190. }
  191. VOID
  192. CrashDrvHardError(
  193. PULONG ub
  194. )
  195. {
  196. NTSTATUS Status;
  197. NTSTATUS ErrorCode;
  198. ULONG Response;
  199. ErrorCode = STATUS_SYSTEM_PROCESS_TERMINATED;
  200. Status = ExRaiseHardError(
  201. ErrorCode,
  202. 0,
  203. 0,
  204. NULL,
  205. OptionShutdownSystem,
  206. &Response
  207. );
  208. return;
  209. }
  210. ULONG CurrentWatchPoint=0;
  211. VOID
  212. AsyncSetBreakPoint(
  213. ULONG LinearAddress
  214. )
  215. {
  216. #ifdef i386
  217. CurrentWatchPoint = LinearAddress;
  218. _asm {
  219. mov eax, LinearAddress
  220. mov dr0, eax
  221. mov eax, 10303h
  222. mov dr7, eax
  223. }
  224. #endif
  225. }
  226. VOID
  227. AsyncRemoveBreakPoint(
  228. ULONG LinearAddress
  229. )
  230. {
  231. #ifdef i386
  232. CurrentWatchPoint = 0;
  233. _asm {
  234. mov eax, 0
  235. mov dr7, eax
  236. }
  237. #endif
  238. }
  239. #pragma optimize ( "", on )
  240. VOID
  241. CrashSpecial(
  242. PULONG ub
  243. )
  244. {
  245. CrashRequest = ub[0];
  246. KeSetEvent( &CrashEvent, 0, FALSE );
  247. }