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.

305 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. wrp.c
  5. Abstract:
  6. This file contains the generic routines and initialization code
  7. for the kernel debugger extensions dll.
  8. Author:
  9. AmritanR
  10. Environment:
  11. User Mode
  12. Revision History:
  13. --*/
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <ntverp.h>
  18. #include <windef.h>
  19. #include <winbase.h>
  20. #include <ntosp.h>
  21. #include <stdio.h>
  22. #include <wdbgexts.h>
  23. #include <winsock.h>
  24. #include <cxport.h>
  25. #include <ndis.h>
  26. #define __FILE_SIG__ KDEXT_SIG
  27. #include "inc.h"
  28. typedef struct _SYM_TAB_ENTRY
  29. {
  30. PCHAR pwszSymbol;
  31. ULONG_PTR ulpAddress;
  32. } SYM_TAB_ENTRY, *PSYM_TAB_ENTRY;
  33. SYM_TAB_ENTRY g_rgSymbolTable [] = {
  34. { "wanarp!g_leIfList", (ULONG_PTR)0 },
  35. { "wanarp!g_leFreeAdapterList", (ULONG_PTR)0 },
  36. { "wanarp!g_ulNumFreeAdapters", (ULONG_PTR)0 },
  37. { "wanarp!g_leAddedAdapterList", (ULONG_PTR)0 },
  38. { "wanarp!g_ulNumAddedAdapters", (ULONG_PTR)0 },
  39. { "wanarp!g_leChangeAdapterList", (ULONG_PTR)0 },
  40. { "wanarp!g_ulNumAdapters", (ULONG_PTR)0 },
  41. { "wanarp!g_puipConnTable", (ULONG_PTR)0 },
  42. { "wanarp!g_ulConnTableSize", (ULONG_PTR)0 },
  43. { "wanarp!g_pServerInterface", (ULONG_PTR)0 },
  44. { "wanarp!g_pServerAdapter", (ULONG_PTR)0 },
  45. { "wanarp!g_dwDriverState", (ULONG_PTR)0 },
  46. { "wanarp!g_ulNumCreates", (ULONG_PTR)0 },
  47. { "wanarp!g_ulNumThreads", (ULONG_PTR)0 },
  48. { "wanarp!g_lePendingNotificationList", (ULONG_PTR)0 },
  49. { "wanarp!g_lePendingIrpList", (ULONG_PTR)0 },
  50. };
  51. //
  52. // Symbols
  53. //
  54. #define IF_LIST 0
  55. #define FREE_ADPT_LIST 1
  56. #define NUM_FREE_ADPT 2
  57. #define ADDED_ADPT_LIST 3
  58. #define NUM_ADDED_ADPT 4
  59. #define CHANGE_ADPT_LIST 5
  60. #define NUM_ADPT 6
  61. #define CONN_TABLE 7
  62. #define CONN_TABLE_SIZE 8
  63. #define SRVR_IF 9
  64. #define SRVR_ADPT 10
  65. #define DRIVER_STATE 11
  66. #define NUM_CREATES 12
  67. #define NUM_THREADS 13
  68. #define NOTIFICATION_LIST 14
  69. #define IRP_LIST 15
  70. EXT_API_VERSION ApiVersion = { 5, 0, EXT_API_VERSION_NUMBER, 0 };
  71. BOOLEAN ChkTarget;
  72. WINDBG_EXTENSION_APIS ExtensionApis;
  73. BOOL g_bInit;
  74. INT Item;
  75. USHORT SavedMajorVersion;
  76. USHORT SavedMinorVersion;
  77. #define CHECK_SIZE(dwRead,dwReq,bRes) \
  78. { \
  79. if((dwRead) < (dwReq)) \
  80. { \
  81. dprintf("Requested %s (%d) read %d \n",#dwReq,dwReq,dwRead);\
  82. dprintf("Error in %s at %d\n",__FILE__,__LINE__); \
  83. bRes = FALSE; \
  84. } \
  85. else \
  86. { \
  87. bRes = TRUE; \
  88. } \
  89. }
  90. #define READ_MEMORY_ERROR(s, p) \
  91. dprintf("Error %d bytes at %x\n",(s), (p))
  92. #define GET_ADDRESS_ERROR(s) \
  93. dprintf("Error getting the offset for %s\n",(s))
  94. #define INET_NTOA(a) \
  95. inet_ntoa(*(struct in_addr*)&(a))
  96. DllInit(
  97. HANDLE hModule,
  98. DWORD dwReason,
  99. DWORD dwReserved
  100. )
  101. {
  102. switch (dwReason) {
  103. case DLL_THREAD_ATTACH: {
  104. break;
  105. }
  106. case DLL_THREAD_DETACH: {
  107. break;
  108. }
  109. case DLL_PROCESS_DETACH: {
  110. g_bInit = FALSE;
  111. DisableThreadLibraryCalls(hModule);
  112. break;
  113. }
  114. case DLL_PROCESS_ATTACH: {
  115. break;
  116. }
  117. }
  118. return TRUE;
  119. }
  120. VOID
  121. WinDbgExtensionDllInit(
  122. PWINDBG_EXTENSION_APIS lpExtensionApis,
  123. USHORT MajorVersion,
  124. USHORT MinorVersion
  125. )
  126. {
  127. ExtensionApis = *lpExtensionApis;
  128. SavedMajorVersion = MajorVersion;
  129. SavedMinorVersion = MinorVersion;
  130. ChkTarget = ((SavedMajorVersion == 0x0c) ? TRUE : FALSE);
  131. return;
  132. }
  133. DECLARE_API( version )
  134. {
  135. #if DBG
  136. PCHAR DebuggerType = "Checked";
  137. #else
  138. PCHAR DebuggerType = "Free";
  139. #endif
  140. dprintf("%s Extension dll for Build %d debugging %s kernel for Build %d\n",
  141. DebuggerType,
  142. VER_PRODUCTBUILD,
  143. SavedMajorVersion == 0x0c ? "Checked" : "Free",
  144. SavedMinorVersion);
  145. }
  146. VOID
  147. CheckVersion(
  148. VOID
  149. )
  150. {
  151. #if DBG
  152. if((SavedMajorVersion isnot 0x0c) or
  153. (SavedMinorVersion isnot VER_PRODUCTBUILD))
  154. {
  155. dprintf("\n*** Extension DLL(%d Checked) does not match target system(%d %s)\n",
  156. VER_PRODUCTBUILD,
  157. SavedMinorVersion,
  158. (SavedMajorVersion==0x0f) ? "Free" : "Checked");
  159. }
  160. #else
  161. if((SavedMajorVersion isnot 0x0f) or
  162. (SavedMinorVersion isnot VER_PRODUCTBUILD))
  163. {
  164. dprintf("\n*** Extension DLL(%d Free) does not match target (%d %s)\n",
  165. VER_PRODUCTBUILD,
  166. SavedMinorVersion,
  167. (SavedMajorVersion==0x0f) ? "Free" : "Checked");
  168. }
  169. #endif
  170. }
  171. LPEXT_API_VERSION
  172. ExtensionApiVersion(
  173. VOID
  174. )
  175. {
  176. return &ApiVersion;
  177. }
  178. //
  179. // Exported functions
  180. //
  181. DECLARE_API( help )
  182. /*++
  183. Routine Description:
  184. Command help for debugger extension.
  185. Arguments:
  186. None
  187. Return Value:
  188. None
  189. --*/
  190. {
  191. dprintf("\n\tWanArp debugger extension commands:\n\n");
  192. dprintf(
  193. "\tifpool <if> - Show the address-pool of the interface at <if>\n"
  194. );
  195. dprintf("\n\tCompiled on " __DATE__ " at " __TIME__ "\n");
  196. return;
  197. }
  198. BOOL
  199. InitDebugger(
  200. VOID
  201. )
  202. {
  203. int i;
  204. if(g_bInit)
  205. {
  206. return TRUE;
  207. }
  208. for(i = 0;
  209. i < sizeof(g_rgSymbolTable)/sizeof(SYM_TAB_ENTRY);
  210. i++)
  211. {
  212. g_rgSymbolTable[i].ulpAddress =
  213. GetExpression(g_rgSymbolTable[i].pwszSymbol);
  214. if(g_rgSymbolTable[i].ulpAddress == 0)
  215. {
  216. GET_ADDRESS_ERROR(g_rgSymbolTable[i].pwszSymbol);
  217. return FALSE;
  218. }
  219. }
  220. g_bInit = TRUE;
  221. return TRUE;
  222. }
  223. DECLARE_API( init )
  224. {
  225. InitDebugger();
  226. }
  227. DECLARE_API( numif )
  228. {
  229. }