Windows NT 4.0 source code leak
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.

443 lines
10 KiB

4 years ago
  1. #define TARGET_ALPHA
  2. #include <platform.h>
  3. #include <imagehlp.h>
  4. #include <crash.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include "dumpexam.h"
  9. #define GetContext(p,c) GetContextALPHA(p,c)
  10. #define MAX_STACK_FRAMES 100
  11. #define SAVE_EBP(f) f.Reserved[0]
  12. #define TRAP_TSS(f) f.Reserved[1]
  13. #define TRAP_EDITED(f) f.Reserved[1]
  14. #define SAVE_TRAP(f) f.Reserved[2]
  15. extern FILE *FileOut;
  16. VOID
  17. PrintRegisters(
  18. ULONG Processor,
  19. PCONTEXT Context
  20. );
  21. static
  22. DWORD
  23. GetStackTrace(
  24. PDUMP_HEADER DmpHeader,
  25. ULONG Processor,
  26. LPSTACKFRAME Frames,
  27. ULONG MaxFrames,
  28. PCONTEXT Context
  29. )
  30. {
  31. BOOL rVal;
  32. STACKFRAME StackFrame;
  33. DWORD FrameCnt;
  34. FrameCnt = 0;
  35. ZeroMemory( &StackFrame, sizeof(STACKFRAME) );
  36. do {
  37. rVal = StackWalk(
  38. IMAGE_FILE_MACHINE_ALPHA,
  39. (HANDLE)DmpHeader,
  40. (HANDLE)Processor,
  41. &StackFrame,
  42. Context,
  43. SwReadMemory,
  44. SwFunctionTableAccess,
  45. SwGetModuleBase,
  46. NULL
  47. );
  48. if (rVal) {
  49. CopyMemory(
  50. &Frames[FrameCnt],
  51. &StackFrame,
  52. sizeof(STACKFRAME)
  53. );
  54. Frames[FrameCnt].Reserved[0] = (DWORD)Context->IntSp;
  55. FrameCnt += 1;
  56. }
  57. } while( rVal && FrameCnt < MaxFrames );
  58. return FrameCnt;
  59. }
  60. static
  61. VOID
  62. PrintStackTrace(
  63. PDUMP_HEADER DmpHeader,
  64. ULONG Processor,
  65. LPSTACKFRAME StackFrames,
  66. ULONG FrameCnt
  67. )
  68. {
  69. PFPO_DATA pFpoData;
  70. PIMAGEHLP_SYMBOL Symbol;
  71. ULONG i;
  72. ULONG Displacement;
  73. CHAR SymBuf[512];
  74. PrintHeading( "Stack Trace" );
  75. fprintf( FileOut, "Callee-SP Arguments to Callee Call Site\n");
  76. for (i=0; i<FrameCnt; i++) {
  77. if (SymGetSymFromAddr( DmpHeader, StackFrames[i].AddrPC.Offset, &Displacement, sym )) {
  78. strcpy( SymBuf, sym->Name );
  79. } else {
  80. sprintf( SymBuf, "0x%08x", StackFrames[i].AddrPC.Offset );
  81. }
  82. fprintf(
  83. FileOut,
  84. "%08lx %08lx : %08lx %08lx %08lx %08lx %s",
  85. StackFrames[i].AddrFrame.Offset,
  86. StackFrames[i].AddrReturn.Offset,
  87. StackFrames[i].Params[0],
  88. StackFrames[i].Params[1],
  89. StackFrames[i].Params[2],
  90. StackFrames[i].Params[3],
  91. SymBuf
  92. );
  93. if (Displacement) {
  94. fprintf( FileOut, "+0x%x", Displacement );
  95. }
  96. fprintf( FileOut, "\n" );
  97. }
  98. fprintf( FileOut, "\n" );
  99. }
  100. VOID
  101. PrintStackTraceALPHA(
  102. PDUMP_HEADER DmpHeader,
  103. ULONG Processor
  104. )
  105. {
  106. PFPO_DATA pFpoData;
  107. CONTEXT Context;
  108. STACKFRAME StackFrames[MAX_STACK_FRAMES];
  109. ULONG FrameCnt;
  110. ULONG i;
  111. CHAR buf[32];
  112. GetContext( Processor, &Context );
  113. FrameCnt = GetStackTrace(
  114. DmpHeader,
  115. Processor,
  116. StackFrames,
  117. MAX_STACK_FRAMES,
  118. &Context
  119. );
  120. PrintStackTrace(
  121. DmpHeader,
  122. Processor,
  123. StackFrames,
  124. FrameCnt
  125. );
  126. }
  127. VOID
  128. BugCheckHeuristicsALPHA(
  129. PDUMP_HEADER DmpHeader,
  130. ULONG Processor
  131. )
  132. {
  133. STACKFRAME StackFrames[MAX_STACK_FRAMES];
  134. ULONG FrameCnt;
  135. PIMAGEHLP_SYMBOL Symbol;
  136. ULONG i;
  137. ULONG cb;
  138. CHAR buf[32];
  139. ULONG Ptrs[4];
  140. CONTEXT Context;
  141. if (DmpHeader->BugCheckCode == KMODE_EXCEPTION_NOT_HANDLED) {
  142. PrintHeading(
  143. "Dump Analysis Heuristics for Bugcode %s",
  144. GetBugText(DmpHeader->BugCheckCode)
  145. );
  146. fprintf(
  147. FileOut,
  148. "Exception Code: 0x%08x\n",
  149. DmpHeader->BugCheckParameter1
  150. );
  151. fprintf(
  152. FileOut,
  153. "Address of Exception: 0x%08x\n",
  154. DmpHeader->BugCheckParameter2
  155. );
  156. fprintf(
  157. FileOut,
  158. "Parameter #0: 0x%08x\n",
  159. DmpHeader->BugCheckParameter3
  160. );
  161. fprintf(
  162. FileOut,
  163. "Parameter #1: 0x%08x\n\n",
  164. DmpHeader->BugCheckParameter4
  165. );
  166. if (!SymGetSymFromName( DmpHeader, "PspUnhandledExceptionInSystemThread", sym )) {
  167. return;
  168. }
  169. GetContext( Processor, &Context );
  170. FrameCnt = GetStackTrace(
  171. DmpHeader,
  172. Processor,
  173. StackFrames,
  174. MAX_STACK_FRAMES,
  175. &Context
  176. );
  177. for (i=0; i<FrameCnt; i++) {
  178. if (StackFrames[i].AddrPC.Offset >= sym->Address &&
  179. StackFrames[i].AddrPC.Offset < sym->Address + sym->Size) {
  180. break;
  181. }
  182. }
  183. if (i == FrameCnt) {
  184. return;
  185. }
  186. GetContext( Processor, &Context );
  187. cb = DmpReadMemory( (PVOID)(StackFrames[i+1].Reserved[0]+16), Ptrs, sizeof(Ptrs) );
  188. if (cb != sizeof(Ptrs)) {
  189. return;
  190. }
  191. sprintf( buf, "%08x", Ptrs[0] );
  192. DoExtension( "exr", buf, Processor, (DWORD)GetRegisterValue( &Context, REG_IP ) );
  193. cb = DmpReadMemory( (PVOID)Ptrs[2], &Context, sizeof(Context) );
  194. if (cb != sizeof(Context)) {
  195. return;
  196. }
  197. PrintRegisters( Processor, &Context );
  198. FrameCnt = GetStackTrace(
  199. DmpHeader,
  200. Processor,
  201. StackFrames,
  202. MAX_STACK_FRAMES,
  203. &Context
  204. );
  205. PrintStackTrace(
  206. DmpHeader,
  207. Processor,
  208. StackFrames,
  209. FrameCnt
  210. );
  211. DoDisassemble( (DWORD)Context.Fir );
  212. }
  213. if (DmpHeader->BugCheckCode == IRQL_NOT_LESS_OR_EQUAL) {
  214. PrintHeading(
  215. "Dump Analysis Heuristics for Bugcode %s",
  216. GetBugText(DmpHeader->BugCheckCode)
  217. );
  218. fprintf(
  219. FileOut,
  220. "Invalid Address Referenced: 0x%08x\n",
  221. DmpHeader->BugCheckParameter1
  222. );
  223. fprintf(
  224. FileOut,
  225. "IRQL: %d\n",
  226. DmpHeader->BugCheckParameter2
  227. );
  228. fprintf(
  229. FileOut,
  230. "Access Type: %s\n",
  231. DmpHeader->BugCheckParameter3 ? "Read" : "Write"
  232. );
  233. fprintf(
  234. FileOut,
  235. "Code Address: 0x%08x\n\n",
  236. DmpHeader->BugCheckParameter4
  237. );
  238. sprintf( buf, "%08x", DmpHeader->BugCheckParameter1 );
  239. GetContext( Processor, &Context );
  240. DoExtension( "pool", buf, Processor, (DWORD)GetRegisterValue( &Context, REG_IP ) );
  241. }
  242. }
  243. ULONGLONG
  244. GetRegisterValueALPHA(
  245. PCONTEXT Context,
  246. ULONG Register
  247. )
  248. {
  249. ULONGLONG Value = 0;
  250. switch( Register ) {
  251. case REG_IP:
  252. Value = Context->Fir;
  253. break;
  254. case REG_FP:
  255. Value = Context->IntSp;
  256. break;
  257. case REG_SP:
  258. Value = Context->IntSp;
  259. break;
  260. }
  261. return Value;
  262. }
  263. #define FLAGMODE 1
  264. #define FLAGIE 2
  265. #define FLAGIRQL 3
  266. static
  267. ULONG
  268. GetFlag(
  269. ULONGLONG FlagsReg,
  270. ULONG Flag
  271. )
  272. {
  273. switch( Flag ) {
  274. case FLAGMODE: return (DWORD)((FlagsReg >> 0) & 1);
  275. case FLAGIE: return (DWORD)((FlagsReg >> 1) & 1);
  276. case FLAGIRQL: return (DWORD)((FlagsReg >> 2) & 7);
  277. }
  278. return 0;
  279. }
  280. static
  281. VOID
  282. PrintRegisters(
  283. ULONG Processor,
  284. PCONTEXT Context
  285. )
  286. {
  287. PrintHeading( "Register Dump For Processor #%d", Processor );
  288. fprintf(
  289. FileOut,
  290. "v0=%016Lx t0=%016Lx t1=%016Lx t2=%016Lx\n",
  291. Context->IntV0,
  292. Context->IntT0,
  293. Context->IntT1,
  294. Context->IntT2
  295. );
  296. fprintf(
  297. FileOut,
  298. "t3=%016x t4=%016x t5=%016x t6=%016x\n",
  299. Context->IntT3,
  300. Context->IntT4,
  301. Context->IntT5,
  302. Context->IntT6
  303. );
  304. fprintf(
  305. FileOut,
  306. "t7=%016x s0=%016x s1=%016x s2=%016x\n",
  307. Context->IntT7,
  308. Context->IntS0,
  309. Context->IntS1,
  310. Context->IntS2
  311. );
  312. fprintf(
  313. FileOut,
  314. "s3=%016x s4=%016x s5=%016x fp=%016x\n",
  315. Context->IntS3,
  316. Context->IntS4,
  317. Context->IntS5,
  318. Context->IntFp
  319. );
  320. fprintf(
  321. FileOut,
  322. "a0=%016x a1=%016x a2=%016x a3=%016x\n",
  323. Context->IntA0,
  324. Context->IntA1,
  325. Context->IntA2,
  326. Context->IntA3
  327. );
  328. fprintf(
  329. FileOut,
  330. "a4=%016x a5=%016x t16=%016x t9=%016x\n",
  331. Context->IntA4,
  332. Context->IntA5,
  333. Context->IntT8,
  334. Context->IntT9
  335. );
  336. fprintf(
  337. FileOut,
  338. "t10=%016x t11=%016x ra=%016x t12=%016x\n",
  339. Context->IntT10,
  340. Context->IntT11,
  341. Context->IntRa,
  342. Context->IntT12
  343. );
  344. fprintf(
  345. FileOut,
  346. "at=%016x gp=%016x sp=%016x zero=%x\n",
  347. Context->IntAt,
  348. Context->IntGp,
  349. Context->IntSp,
  350. Context->IntZero
  351. );
  352. fprintf(
  353. FileOut,
  354. "pcr=%016x softfpcr=%016x fir=%016x\n",
  355. Context->Fpcr,
  356. Context->SoftFpcr,
  357. Context->Fir
  358. );
  359. fprintf(
  360. FileOut,
  361. "psr=%08x\n",
  362. Context->Psr
  363. );
  364. fprintf(
  365. FileOut,
  366. "mode=%1x ie=%1x irql=%1x\n",
  367. GetFlag(Context->Psr,FLAGMODE),
  368. GetFlag(Context->Psr,FLAGIE),
  369. GetFlag(Context->Psr,FLAGIRQL)
  370. );
  371. fprintf( FileOut, "\n" );
  372. }
  373. VOID
  374. GetContextALPHA(
  375. ULONG Processor,
  376. PVOID Context
  377. )
  378. {
  379. DmpGetContext( Processor, Context );
  380. }
  381. VOID
  382. PrintRegistersALPHA(
  383. ULONG Processor
  384. )
  385. {
  386. CONTEXT Context;
  387. GetContext( Processor, &Context );
  388. PrintRegisters( Processor, &Context );
  389. }