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.

250 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1993-1999 Microsoft Corporation
  3. Module Name:
  4. kdexts.c
  5. Abstract:
  6. This file contains the generic routines and initialization code
  7. for the kernel debugger extensions dll.
  8. Author:
  9. Stephane Plante (splante)
  10. jdunn, adapted to USB2
  11. Environment:
  12. User Mode
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. #include <ntverp.h>
  17. #include <imagehlp.h>
  18. //
  19. // globals
  20. //
  21. EXT_API_VERSION ApiVersion = { (VER_PRODUCTVERSION_W >> 8), (VER_PRODUCTVERSION_W & 0xff), EXT_API_VERSION_NUMBER, 0 };
  22. WINDBG_EXTENSION_APIS ExtensionApis;
  23. USHORT SavedMajorVersion;
  24. USHORT SavedMinorVersion;
  25. #ifdef USB_KD64
  26. DBGKD_GET_VERSION64 KernelVersionPacket;
  27. #else
  28. DBGKD_GET_VERSION32 KernelVersionPacket;
  29. #endif
  30. DllInit(
  31. HANDLE hModule,
  32. DWORD dwReason,
  33. DWORD dwReserved
  34. )
  35. {
  36. switch (dwReason) {
  37. case DLL_THREAD_ATTACH:
  38. break;
  39. case DLL_THREAD_DETACH:
  40. break;
  41. case DLL_PROCESS_DETACH:
  42. break;
  43. case DLL_PROCESS_ATTACH:
  44. break;
  45. }
  46. return TRUE;
  47. }
  48. VOID
  49. WinDbgExtensionDllInit(
  50. PWINDBG_EXTENSION_APIS lpExtensionApis,
  51. USHORT MajorVersion,
  52. USHORT MinorVersion
  53. )
  54. {
  55. ExtensionApis = *lpExtensionApis;
  56. SavedMajorVersion = MajorVersion;
  57. SavedMinorVersion = MinorVersion;
  58. return;
  59. }
  60. VOID
  61. CheckVersion(
  62. VOID
  63. )
  64. {
  65. #if DBG
  66. if ( (SavedMajorVersion != 0x0c) ||
  67. (SavedMinorVersion != VER_PRODUCTBUILD) ) {
  68. dprintf(
  69. "\r\n*** Extension DLL(%d Checked) does not match target "
  70. "system(%d %s)\r\n\r\n",
  71. VER_PRODUCTBUILD,
  72. SavedMinorVersion,
  73. (SavedMajorVersion==0x0f) ? "Free" : "Checked"
  74. );
  75. }
  76. #else
  77. if ( (SavedMajorVersion != 0x0f) ||
  78. (SavedMinorVersion != VER_PRODUCTBUILD) ) {
  79. dprintf(
  80. "\r\n*** Extension DLL(%d Free) does not match target "
  81. "system(%d %s)\r\n\r\n",
  82. VER_PRODUCTBUILD,
  83. SavedMinorVersion,
  84. (SavedMajorVersion==0x0f) ? "Free" : "Checked"
  85. );
  86. }
  87. #endif
  88. }
  89. BOOL
  90. HaveDebuggerData(
  91. VOID
  92. )
  93. {
  94. static int havedata = 0;
  95. if (havedata == 2) {
  96. return FALSE;
  97. }
  98. if (havedata == 0) {
  99. if (!Ioctl(
  100. IG_GET_KERNEL_VERSION,
  101. (PVOID)(&KernelVersionPacket),
  102. sizeof(KernelVersionPacket)
  103. )
  104. ) {
  105. havedata = 2;
  106. } else if (KernelVersionPacket.MajorVersion == 0) {
  107. havedata = 2;
  108. } else {
  109. havedata = 1;
  110. }
  111. }
  112. return (havedata == 1) &&
  113. ((KernelVersionPacket.Flags & DBGKD_VERS_FLAG_DATA) != 0);
  114. }
  115. #if 0
  116. BOOL
  117. GetUlong (
  118. IN PCHAR String,
  119. IN PULONG Value
  120. )
  121. {
  122. BOOL status;
  123. ULONG_PTR Location;
  124. ULONG result;
  125. Location = GetExpression( String );
  126. if (!Location) {
  127. dprintf("unable to get %s\n",String);
  128. return FALSE;
  129. }
  130. status = ReadMemory(
  131. Location,
  132. Value,
  133. sizeof(ULONG),
  134. &result
  135. );
  136. if (status == FALSE || result != sizeof(ULONG)) {
  137. return FALSE;
  138. }
  139. return TRUE;
  140. }
  141. BOOL
  142. GetUlongPtr (
  143. IN PCHAR String,
  144. IN PULONG_PTR Address
  145. )
  146. {
  147. BOOL status;
  148. ULONG_PTR Location;
  149. ULONG result;
  150. Location = GetExpression( String );
  151. if (!Location) {
  152. dprintf("unable to get %s\n",String);
  153. return FALSE;
  154. }
  155. status = ReadMemory(
  156. Location,
  157. Address,
  158. sizeof(ULONG_PTR),
  159. &result
  160. );
  161. if (status == FALSE || result != sizeof(ULONG)) {
  162. return FALSE;
  163. }
  164. return TRUE;
  165. }
  166. #endif //xxx
  167. LPEXT_API_VERSION
  168. ExtensionApiVersion(
  169. VOID
  170. )
  171. {
  172. return &ApiVersion;
  173. }
  174. DECLARE_API( version )
  175. {
  176. #if DBG
  177. PCHAR DebuggerType = "Checked";
  178. #else
  179. PCHAR DebuggerType = "Free";
  180. #endif
  181. dprintf(
  182. "%s Extension dll for Build %d debugging %s kernel for Build %d\n",
  183. DebuggerType,
  184. VER_PRODUCTBUILD,
  185. SavedMajorVersion == 0x0c ? "Checked" : "Free",
  186. SavedMinorVersion
  187. );
  188. return S_OK;
  189. }