Source code of Windows XP (NT5)
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.

340 lines
10 KiB

  1. /*
  2. * excptn.c - Exception functions of DBG DLL.
  3. *
  4. */
  5. #include <precomp.h>
  6. #pragma hdrstop
  7. BOOL DbgGPFault2(
  8. PFFRAME16 pFFrame
  9. )
  10. /*
  11. 2nd chance GPFault handler (called via BOP)
  12. */
  13. {
  14. BOOL fResult;
  15. fResult = FALSE; // Default to Event not handled
  16. DbgGetContext();
  17. vcContext.SegEs = (ULONG)pFFrame->wES;
  18. vcContext.SegDs = (ULONG)pFFrame->wDS;
  19. vcContext.SegCs = (ULONG)pFFrame->wCS;
  20. vcContext.SegSs = (ULONG)pFFrame->wSS;
  21. #ifdef i386
  22. //
  23. // On x86 systems, we really might have some data in the high words
  24. // of these registers. Hopefully DOSX.EXE and KRNL286.EXE don't
  25. // blow them away. Here is where we attempt to recover them.
  26. //
  27. vcContext.Edi = MAKELONG(pFFrame->wDI, HIWORD(px86->Edi ));
  28. vcContext.Esi = MAKELONG(pFFrame->wSI, HIWORD(px86->Esi ));
  29. vcContext.Ebx = MAKELONG(pFFrame->wBX, HIWORD(px86->Ebx ));
  30. vcContext.Edx = MAKELONG(pFFrame->wDX, HIWORD(px86->Edx ));
  31. vcContext.Ecx = MAKELONG(pFFrame->wCX, HIWORD(px86->Ecx ));
  32. vcContext.Eax = MAKELONG(pFFrame->wAX, HIWORD(px86->Eax ));
  33. vcContext.Ebp = MAKELONG(pFFrame->wBP, HIWORD(px86->Ebp ));
  34. vcContext.Eip = MAKELONG(pFFrame->wIP, HIWORD(px86->Eip ));
  35. vcContext.Esp = MAKELONG(pFFrame->wSP, HIWORD(px86->Esp ));
  36. vcContext.EFlags = MAKELONG(pFFrame->wFlags,HIWORD(px86->EFlags));
  37. #else
  38. vcContext.Edi = (ULONG)pFFrame->wDI;
  39. vcContext.Esi = (ULONG)pFFrame->wSI;
  40. vcContext.Ebx = (ULONG)pFFrame->wBX;
  41. vcContext.Edx = (ULONG)pFFrame->wDX;
  42. vcContext.Ecx = (ULONG)pFFrame->wCX;
  43. vcContext.Eax = (ULONG)pFFrame->wAX;
  44. vcContext.Ebp = (ULONG)pFFrame->wBP;
  45. vcContext.Eip = (ULONG)pFFrame->wIP;
  46. vcContext.Esp = (ULONG)pFFrame->wSP;
  47. vcContext.EFlags = (ULONG)pFFrame->wFlags;
  48. #endif
  49. if ( fDebugged ) {
  50. fResult = SendVDMEvent(DBG_GPFAULT2);
  51. if ( !fResult ) {
  52. DWORD dw;
  53. dw = SetErrorMode(0);
  54. try {
  55. RaiseException((DWORD)DBG_CONTROL_BREAK, 0, 0, (LPDWORD)0);
  56. fResult = TRUE;
  57. } except (EXCEPTION_EXECUTE_HANDLER) {
  58. fResult = FALSE;
  59. }
  60. SetErrorMode(dw);
  61. }
  62. } else {
  63. char text[100];
  64. // Dump a simulated context
  65. OutputDebugString("NTVDM:GP Fault detected, register dump follows:\n");
  66. wsprintf(text,"eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx esi=%08lx edi=%08lx\n",
  67. vcContext.Eax,
  68. vcContext.Ebx,
  69. vcContext.Ecx,
  70. vcContext.Edx,
  71. vcContext.Esi,
  72. vcContext.Edi );
  73. OutputDebugString(text);
  74. wsprintf(text,"eip=%08lx esp=%08lx ebp=%08lx iopl=%d %s %s %s %s %s %s %s %s\n",
  75. vcContext.Eip,
  76. vcContext.Esp,
  77. vcContext.Ebp,
  78. (vcContext.EFlags & V86FLAGS_IOPL) >> V86FLAGS_IOPL_BITS,
  79. (vcContext.EFlags & V86FLAGS_OVERFLOW ) ? "ov" : "nv",
  80. (vcContext.EFlags & V86FLAGS_DIRECTION) ? "dn" : "up",
  81. (vcContext.EFlags & V86FLAGS_INTERRUPT) ? "ei" : "di",
  82. (vcContext.EFlags & V86FLAGS_SIGN ) ? "ng" : "pl",
  83. (vcContext.EFlags & V86FLAGS_ZERO ) ? "zr" : "nz",
  84. (vcContext.EFlags & V86FLAGS_AUXCARRY ) ? "ac" : "na",
  85. (vcContext.EFlags & V86FLAGS_PARITY ) ? "po" : "pe",
  86. (vcContext.EFlags & V86FLAGS_CARRY ) ? "cy" : "nc" );
  87. OutputDebugString(text);
  88. wsprintf(text,"cs=%04x ss=%04x ds=%04x es=%04x fs=%04x gs=%04x efl=%08lx\n",
  89. (WORD)vcContext.SegCs,
  90. (WORD)vcContext.SegSs,
  91. (WORD)vcContext.SegDs,
  92. (WORD)vcContext.SegEs,
  93. (WORD)vcContext.SegFs,
  94. (WORD)vcContext.SegGs,
  95. vcContext.EFlags );
  96. OutputDebugString(text);
  97. }
  98. #ifdef i386
  99. //
  100. // On x86 systems, we really might have some data in the FS and GS
  101. // registers. Hopefully DOSX.EXE and KRNL286.EXE don't
  102. // blow them away. Here is where we attempt to restore them.
  103. //
  104. px86->SegGs = (WORD)vcContext.SegGs;
  105. px86->SegFs = (WORD)vcContext.SegFs;
  106. #else
  107. // No need to set FS,GS, they don't exist
  108. #endif
  109. pFFrame->wES = (WORD)vcContext.SegEs;
  110. pFFrame->wDS = (WORD)vcContext.SegDs;
  111. pFFrame->wCS = (WORD)vcContext.SegCs;
  112. pFFrame->wSS = (WORD)vcContext.SegSs;
  113. #ifdef i386
  114. //
  115. // On x86 systems, we really might have some data in the high words
  116. // of these registers. Hopefully DOSX.EXE and KRNL286.EXE don't
  117. // blow them away. Here is where we attempt to restore them.
  118. //
  119. pFFrame->wDI = LOWORD(vcContext.Edi);
  120. px86->Edi = MAKELONG(LOWORD(px86->Edi),HIWORD(vcContext.Edi));
  121. pFFrame->wSI = LOWORD(vcContext.Esi);
  122. px86->Esi = MAKELONG(LOWORD(px86->Esi),HIWORD(vcContext.Esi));
  123. pFFrame->wBX = LOWORD(vcContext.Ebx);
  124. px86->Ebx = MAKELONG(LOWORD(px86->Ebx),HIWORD(vcContext.Ebx));
  125. pFFrame->wDX = LOWORD(vcContext.Edx);
  126. px86->Edx = MAKELONG(LOWORD(px86->Edx),HIWORD(vcContext.Edx));
  127. pFFrame->wCX = LOWORD(vcContext.Ecx);
  128. px86->Ecx = MAKELONG(LOWORD(px86->Ecx),HIWORD(vcContext.Ecx));
  129. pFFrame->wAX = LOWORD(vcContext.Eax);
  130. px86->Eax = MAKELONG(LOWORD(px86->Eax),HIWORD(vcContext.Eax));
  131. pFFrame->wBP = LOWORD(vcContext.Ebp);
  132. px86->Ebp = MAKELONG(LOWORD(px86->Ebp),HIWORD(vcContext.Ebp));
  133. pFFrame->wIP = LOWORD(vcContext.Eip);
  134. px86->Eip = MAKELONG(LOWORD(px86->Eip),HIWORD(vcContext.Eip));
  135. pFFrame->wFlags = LOWORD(vcContext.EFlags);
  136. px86->EFlags = MAKELONG(LOWORD(px86->EFlags),HIWORD(vcContext.EFlags));
  137. pFFrame->wSP = LOWORD(vcContext.Esp);
  138. px86->Esp = MAKELONG(LOWORD(px86->Esp),HIWORD(vcContext.Esp));
  139. #else
  140. pFFrame->wDI = (WORD)vcContext.Edi;
  141. pFFrame->wSI = (WORD)vcContext.Esi;
  142. pFFrame->wBX = (WORD)vcContext.Ebx;
  143. pFFrame->wDX = (WORD)vcContext.Edx;
  144. pFFrame->wCX = (WORD)vcContext.Ecx;
  145. pFFrame->wAX = (WORD)vcContext.Eax;
  146. pFFrame->wBP = (WORD)vcContext.Ebp;
  147. pFFrame->wIP = (WORD)vcContext.Eip;
  148. pFFrame->wFlags = (WORD)vcContext.EFlags;
  149. pFFrame->wSP = (WORD)vcContext.Esp;
  150. #endif
  151. return( fResult );
  152. }
  153. BOOL DbgDivOverflow2(
  154. PTFRAME16 pTFrame
  155. )
  156. /*
  157. 2nd chance divide exception handler
  158. */
  159. {
  160. BOOL fResult;
  161. fResult = FALSE; // Default to Event not handled
  162. if ( fDebugged ) {
  163. DbgGetContext();
  164. vcContext.SegDs = (ULONG)pTFrame->wDS;
  165. vcContext.SegCs = (ULONG)pTFrame->wCS;
  166. vcContext.SegSs = (ULONG)pTFrame->wSS;
  167. #ifdef i386
  168. //
  169. // On x86 systems, we really might have some data in the high words
  170. // of these registers. Hopefully DOSX.EXE and KRNL286.EXE don't
  171. // blow them away. Here is where we attempt to recover them.
  172. //
  173. vcContext.Eax = MAKELONG(pTFrame->wAX, HIWORD(px86->Eax ));
  174. vcContext.Eip = MAKELONG(pTFrame->wIP, HIWORD(px86->Eip ));
  175. vcContext.Esp = MAKELONG(pTFrame->wSP, HIWORD(px86->Esp ));
  176. vcContext.EFlags = MAKELONG(pTFrame->wFlags,HIWORD(px86->EFlags));
  177. #else
  178. vcContext.Eax = (ULONG)pTFrame->wAX;
  179. vcContext.Eip = (ULONG)pTFrame->wIP;
  180. vcContext.Esp = (ULONG)pTFrame->wSP;
  181. vcContext.EFlags = (ULONG)pTFrame->wFlags;
  182. #endif
  183. fResult = SendVDMEvent(DBG_DIVOVERFLOW);
  184. #ifdef i386
  185. //
  186. // On x86 systems, we really might have some data in the FS and GS
  187. // registers. Hopefully DOSX.EXE and KRNL286.EXE don't
  188. // blow them away. Here is where we attempt to restore them.
  189. //
  190. px86->SegGs = vcContext.SegGs;
  191. px86->SegFs = vcContext.SegFs;
  192. #else
  193. // No need to set FS,GS, they don't exist
  194. #endif
  195. setES( (WORD)vcContext.SegEs );
  196. pTFrame->wDS = (WORD)vcContext.SegDs;
  197. pTFrame->wCS = (WORD)vcContext.SegCs;
  198. pTFrame->wSS = (WORD)vcContext.SegSs;
  199. #ifdef i386
  200. //
  201. // On x86 systems, we really might have some data in the high words
  202. // of these registers. Hopefully DOSX.EXE and KRNL286.EXE don't
  203. // blow them away. Here is where we attempt to restore them.
  204. //
  205. setEDI( vcContext.Edi );
  206. setESI( vcContext.Esi );
  207. setEBX( vcContext.Ebx );
  208. setEDX( vcContext.Edx );
  209. setECX( vcContext.Ecx );
  210. pTFrame->wAX = LOWORD(vcContext.Eax);
  211. px86->Eax = MAKELONG(LOWORD(px86->Eax),HIWORD(vcContext.Eax));
  212. setEBP( vcContext.Ebp );
  213. pTFrame->wIP = LOWORD(vcContext.Eip);
  214. px86->Eip = MAKELONG(LOWORD(px86->Eip),HIWORD(vcContext.Eip));
  215. pTFrame->wFlags = LOWORD(vcContext.EFlags);
  216. px86->EFlags = MAKELONG(LOWORD(px86->EFlags),HIWORD(vcContext.EFlags));
  217. pTFrame->wSP = LOWORD(vcContext.Esp);
  218. px86->Esp = MAKELONG(LOWORD(px86->Esp),HIWORD(vcContext.Esp));
  219. #else
  220. setDI( (WORD)vcContext.Edi );
  221. setSI( (WORD)vcContext.Esi );
  222. setBX( (WORD)vcContext.Ebx );
  223. setDX( (WORD)vcContext.Edx );
  224. setCX( (WORD)vcContext.Ecx );
  225. pTFrame->wAX = (WORD)vcContext.Eax;
  226. setBP( (WORD)vcContext.Ebp );
  227. pTFrame->wIP = (WORD)vcContext.Eip;
  228. pTFrame->wFlags = (WORD)vcContext.EFlags;
  229. pTFrame->wSP = (WORD)vcContext.Esp;
  230. #endif
  231. }
  232. return( fResult );
  233. }
  234. BOOL
  235. xxxDbgFault(
  236. ULONG IntNumber
  237. )
  238. /*
  239. This is the first chance exception handler. It is called by dpmi32
  240. */
  241. {
  242. ULONG vdmEip;
  243. int i;
  244. PBYTE lpInst;
  245. BOOL fResult = FALSE;
  246. if ( fDebugged ) {
  247. switch(IntNumber) {
  248. case 6:
  249. //BUGBUG: We *could* handle these, but people might be confused by
  250. // the fact that krnl386 does an intentional opcode exception.
  251. // GetNormalContext( &vcContext, &viInfo, EventParams, DBG_INSTRFAULT, PX86 );
  252. break;
  253. case 12:
  254. if (*(ULONG *)(IntelMemoryBase+FIXED_NTVDMSTATE_LINEAR) & VDM_BREAK_EXCEPTIONS) {
  255. DbgGetContext();
  256. fResult = SendVDMEvent(DBG_STACKFAULT);
  257. }
  258. break;
  259. case 13:
  260. if (*(ULONG *)(IntelMemoryBase+FIXED_NTVDMSTATE_LINEAR) & VDM_BREAK_EXCEPTIONS) {
  261. DbgGetContext();
  262. fResult = SendVDMEvent(DBG_GPFAULT);
  263. }
  264. break;
  265. default:
  266. return FALSE;
  267. }
  268. }
  269. return fResult;
  270. }