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.

764 lines
24 KiB

  1. /*++
  2. Copyright (c) 1993 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. Wesley Witt (wesw) 26-Aug-1993
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "afdkdp.h"
  14. #pragma hdrstop
  15. /*
  16. #include <nt.h>
  17. #include <ntrtl.h>
  18. #include <nturtl.h>
  19. #include <ntverp.h>
  20. #include <windows.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <stdio.h>
  24. // This is a 64 bit aware debugger extension
  25. #define KDEXT_64BIT
  26. #include <wdbgexts.h>
  27. #include <dbgeng.h>
  28. */
  29. //
  30. // globals
  31. //
  32. WINDBG_EXTENSION_APIS ExtensionApis;
  33. ULONG64 STeip;
  34. ULONG64 STebp;
  35. ULONG64 STesp;
  36. ULONG SavedDebugClass, SavedDebugType;
  37. ULONG SavedMachineType, SavedMajorVersion, SavedMinorVersion;
  38. ULONG SavedSrvPack;
  39. CHAR SavedBuildString[128];
  40. LIST_ENTRY TransportInfoList;
  41. BOOL IsCheckedAfd;
  42. BOOL IsReferenceDebug;
  43. ULONG64 UserProbeAddress;
  44. ULONG TicksToMs, TickCount;
  45. ULONG AfdBufferOverhead;
  46. ULONG AfdStandardAddressLength;
  47. ULONG AfdBufferTagSize;
  48. LARGE_INTEGER SystemTime, InterruptTime;
  49. ULONG DatagramBufferListOffset,
  50. DatagramRecvListOffset,
  51. DatagramPeekListOffset,
  52. RoutingNotifyListOffset,
  53. RequestListOffset,
  54. EventStatusOffset,
  55. ConnectionBufferListOffset,
  56. ConnectionSendListOffset,
  57. ConnectionRecvListOffset,
  58. UnacceptedConnListOffset,
  59. ReturnedConnListOffset,
  60. ListenConnListOffset,
  61. FreeConnListOffset,
  62. PreaccConnListOffset,
  63. SanIrpListOffset,
  64. ListenIrpListOffset,
  65. PollEndpointInfoOffset,
  66. DriverContextOffset,
  67. SendIrpArrayOffset,
  68. FsContextOffset;
  69. ULONG EndpointLinkOffset,
  70. ConnectionLinkOffset,
  71. BufferLinkOffset,
  72. AddressEntryLinkOffset,
  73. TransportInfoLinkOffset,
  74. AddressEntryAddressOffset;
  75. ULONG ConnRefOffset,
  76. EndpRefOffset,
  77. TPackRefOffset;
  78. ULONG RefDebugSize;
  79. ULONG AfdResult, NtResult;
  80. BOOLEAN KmGlobalsRead;
  81. ULONG KmActivationSeqN;
  82. BOOLEAN StateInitialized;
  83. ULONG DebuggerActivationSeqN;
  84. KDDEBUGGER_DATA64 DebuggerData;
  85. PDEBUG_CLIENT gClient;
  86. HRESULT
  87. InitializeState (
  88. PDEBUG_CLIENT Client OPTIONAL
  89. );
  90. VOID
  91. FreeTransportList (
  92. VOID
  93. );
  94. ULONG
  95. ReadTimeInfo (
  96. );
  97. BOOLEAN
  98. ReadKmGlobals (
  99. );
  100. extern "C"
  101. BOOL
  102. WINAPI
  103. DllMain (
  104. HANDLE hModule,
  105. DWORD dwReason,
  106. DWORD dwReserved
  107. )
  108. {
  109. switch (dwReason) {
  110. case DLL_THREAD_ATTACH:
  111. break;
  112. case DLL_THREAD_DETACH:
  113. break;
  114. case DLL_PROCESS_DETACH:
  115. FreeTransportList ();
  116. break;
  117. case DLL_PROCESS_ATTACH:
  118. StateInitialized = FALSE;
  119. InitializeListHead (&TransportInfoList);
  120. KmGlobalsRead = FALSE;
  121. NtResult = 0;
  122. AfdResult = 0;
  123. break;
  124. }
  125. return TRUE;
  126. }
  127. extern "C"
  128. HRESULT
  129. CALLBACK
  130. DebugExtensionInitialize(PULONG Version, PULONG Flags)
  131. {
  132. IDebugClient *DebugClient;
  133. PDEBUG_CONTROL DebugControl;
  134. HRESULT Hr;
  135. *Version = DEBUG_EXTENSION_VERSION(1, 0);
  136. *Flags = 0;
  137. if ((Hr = DebugCreate(__uuidof(IDebugClient),
  138. (void **)&DebugClient)) == S_OK) {
  139. if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
  140. (void **)&DebugControl)) == S_OK) {
  141. ExtensionApis.nSize = sizeof (ExtensionApis);
  142. Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis);
  143. DebugControl->Release();
  144. }
  145. DebugClient->Release();
  146. }
  147. StateInitialized = FALSE;
  148. KmGlobalsRead = FALSE;
  149. NtResult = 0;
  150. AfdResult = 0;
  151. return S_OK;
  152. }
  153. extern "C"
  154. void
  155. CALLBACK
  156. DebugExtensionUninitialize(void)
  157. {
  158. FreeTransportList ();
  159. return;
  160. }
  161. extern "C"
  162. void
  163. CALLBACK
  164. DebugExtensionNotify(ULONG Notify, ULONG64 Argument) {
  165. switch (Notify) {
  166. case DEBUG_NOTIFY_SESSION_ACTIVE:
  167. StateInitialized = FALSE;
  168. break;
  169. case DEBUG_NOTIFY_SESSION_ACCESSIBLE:
  170. if (!StateInitialized) {
  171. InitializeState (NULL);
  172. }
  173. DebuggerActivationSeqN += 1;
  174. break;
  175. case DEBUG_NOTIFY_SESSION_INACCESSIBLE:
  176. DebuggerActivationSeqN += 1;
  177. break;
  178. case DEBUG_NOTIFY_SESSION_INACTIVE:
  179. FreeTransportList ();
  180. break;
  181. default:
  182. break;
  183. }
  184. return;
  185. }
  186. DECLARE_API( version ) {
  187. PCHAR argp;
  188. CHAR srvpackstr[128];
  189. #if DBG
  190. PCHAR ExtensionType = "Checked";
  191. #else
  192. PCHAR ExtensionType = "Free";
  193. #endif
  194. gClient = pClient;
  195. argp = ProcessOptions ((PCHAR)args);
  196. if (argp==NULL) {
  197. return E_INVALIDARG;
  198. }
  199. if (!StateInitialized) {
  200. InitializeState (pClient);
  201. }
  202. if (argp[0]!=0) {
  203. SavedMinorVersion = (USHORT)GetExpression (argp);
  204. }
  205. if (SavedSrvPack != 0) {
  206. _snprintf (srvpackstr, sizeof (srvpackstr)-1, " (service pack: %d)", SavedSrvPack);
  207. srvpackstr[sizeof(srvpackstr)-1] = 0;
  208. }
  209. else {
  210. srvpackstr[0] = 0;
  211. }
  212. dprintf( "%s extension dll for build %d debugging %s build %d%s. %s\n",
  213. ExtensionType,
  214. VER_PRODUCTBUILD,
  215. SavedMajorVersion == 0x0c ? "checked" :
  216. SavedMajorVersion == 0x0f ? "free" : "unknown",
  217. SavedMinorVersion,
  218. srvpackstr,
  219. SavedBuildString
  220. );
  221. if (SavedDebugClass==DEBUG_CLASS_KERNEL) {
  222. if (CheckKmGlobals ()) {
  223. dprintf( "Running %s AFD.SYS\n",
  224. IsCheckedAfd ? "Checked" : (IsReferenceDebug ? "Free with reference debug" : "Free")
  225. );
  226. }
  227. }
  228. return S_OK;
  229. }
  230. BOOLEAN
  231. CheckKmGlobals (
  232. )
  233. {
  234. if (!StateInitialized) {
  235. KmGlobalsRead = FALSE;
  236. if (InitializeState (gClient)!=S_OK) {
  237. return FALSE;
  238. }
  239. }
  240. if (SavedDebugClass==DEBUG_CLASS_KERNEL) {
  241. if (KmGlobalsRead) {
  242. if (KmActivationSeqN!=DebuggerActivationSeqN) {
  243. if (ReadTimeInfo ()==0) {
  244. KmActivationSeqN = DebuggerActivationSeqN;
  245. }
  246. }
  247. }
  248. else {
  249. KmGlobalsRead = ReadKmGlobals ();
  250. }
  251. return TRUE;
  252. }
  253. else {
  254. dprintf ("\nThis command is only available in kernel mode debugging sessions\n");
  255. return FALSE;
  256. }
  257. }
  258. HRESULT
  259. GetExpressionFromType (
  260. IN ULONG64 Address,
  261. IN PCHAR Type,
  262. IN PCHAR Expression,
  263. IN ULONG OutType,
  264. OUT PDEBUG_VALUE Value
  265. )
  266. {
  267. CHAR expr[MAX_ADDRESS_EXPRESSION];
  268. PDEBUG_CONTROL3 DebugControl;
  269. HRESULT Hr;
  270. DEBUG_VALUE ignore;
  271. ULONG flags;
  272. BOOLEAN cpp = FALSE;
  273. if ((Hr = gClient->QueryInterface(__uuidof(IDebugControl3),
  274. (void **)&DebugControl)) == S_OK) {
  275. if (strncmp (Expression, AFDKD_CPP_PREFIX, AFDKD_CPP_PREFSZ)==0) {
  276. if (DebugControl->GetExpressionSyntax (&flags)!=S_OK) {
  277. dprintf ("\nGetExpressionFromType: GetExpressionSyntax failed, hr: %x\n",
  278. Hr);
  279. }
  280. if (DebugControl->SetExpressionSyntax (DEBUG_EXPR_CPLUSPLUS)!=S_OK) {
  281. dprintf ("\nGetExpressionFromType: SetExpressionSyntax(CPP) failed, hr: %x\n",
  282. Hr);
  283. goto FailedCpp;
  284. }
  285. cpp = TRUE;
  286. _snprintf (expr, sizeof (expr)-1, "((%s*)0x%I64X)",
  287. Type, Address);
  288. }
  289. else {
  290. _snprintf (expr, sizeof (expr), "0x%I64X", Address);
  291. }
  292. expr[sizeof(expr)-1] = 0;
  293. Hr = DebugControl->Evaluate(expr,
  294. DEBUG_VALUE_INVALID,
  295. &ignore,
  296. NULL);
  297. if (Hr==S_OK) {
  298. Hr = DebugControl->Evaluate(&Expression[AFDKD_CPP_PREFSZ],
  299. OutType,
  300. Value,
  301. NULL);
  302. if (Hr==S_OK) {
  303. }
  304. else {
  305. dprintf ("\nGetExpressionFromType: Evaluate(%s) for @$exp=0x%p failed, hr: %x\n",
  306. Expression,
  307. Address,
  308. Hr);
  309. }
  310. }
  311. else {
  312. dprintf ("\nGetExpressionFromType: Evaluate(%s) failed, hr: %x\n", expr, Hr);
  313. }
  314. if (cpp) {
  315. if (DebugControl->SetExpressionSyntax (flags)!=S_OK) {
  316. dprintf ("\nGetExpressionFromType: SetExpressionSyntax failed, hr: %x\n", Hr);
  317. }
  318. }
  319. FailedCpp:
  320. DebugControl->Release();
  321. }
  322. else {
  323. dprintf ("\nGetCppExpression: Failed to obtain debug control interface, hr: %x\n", Hr);
  324. }
  325. return Hr;
  326. }
  327. VOID
  328. FreeTransportList (
  329. VOID
  330. )
  331. {
  332. while (!IsListEmpty (&TransportInfoList)) {
  333. PLIST_ENTRY listEntry;
  334. PAFDKD_TRANSPORT_INFO transportInfo;
  335. listEntry = RemoveHeadList (&TransportInfoList);
  336. transportInfo = CONTAINING_RECORD (listEntry,
  337. AFDKD_TRANSPORT_INFO,
  338. Link);
  339. RtlFreeHeap (RtlProcessHeap (), 0, transportInfo);
  340. }
  341. }
  342. ULONG
  343. ReadTimeInfo (
  344. )
  345. {
  346. ULONG result;
  347. ULONG64 address;
  348. PDEBUG_DATA_SPACES pDebugDataSpaces;
  349. HRESULT hr;
  350. TickCount = 0;
  351. TicksToMs = 0;
  352. InterruptTime.QuadPart = 0;
  353. SystemTime.QuadPart = 0;
  354. address = MM_SHARED_USER_DATA_VA;
  355. if ((hr = gClient->QueryInterface(__uuidof(IDebugDataSpaces),
  356. (void **)&pDebugDataSpaces)) == S_OK) {
  357. if ((hr = pDebugDataSpaces->ReadDebuggerData(
  358. DEBUG_DATA_SharedUserData, &address,
  359. sizeof(address), NULL)) == S_OK) {
  360. }
  361. else {
  362. dprintf ("\nReadTimeInfo: Cannot get SharedUserData address, hr:%lx\n", hr);
  363. }
  364. pDebugDataSpaces->Release ();
  365. }
  366. else {
  367. dprintf ("\nReadTimeInfo:Cannot obtain debug data spaces interface, hr:%lx\n", hr);
  368. }
  369. if (
  370. #if defined(_AMD64_)
  371. (result=GetFieldValue(address,
  372. "NT!_KUSER_SHARED_DATA",
  373. "TickCount",
  374. TickCount))!=0 ||
  375. #else
  376. (result=GetFieldValue(address,
  377. "NT!_KUSER_SHARED_DATA",
  378. "TickCountLow",
  379. TickCount))!=0 ||
  380. #endif
  381. (result=GetFieldValue(address,
  382. "NT!_KUSER_SHARED_DATA",
  383. "TickCountMultiplier",
  384. TicksToMs))!=0 ||
  385. (result=GetFieldValue(address,
  386. "NT!_KUSER_SHARED_DATA",
  387. "InterruptTime.High1Time",
  388. InterruptTime.HighPart))!=0 ||
  389. (result=GetFieldValue(address,
  390. "NT!_KUSER_SHARED_DATA",
  391. "InterruptTime.LowPart",
  392. InterruptTime.LowPart))!=0 ||
  393. (result=GetFieldValue(address,
  394. "NT!_KUSER_SHARED_DATA",
  395. "SystemTime.High1Time",
  396. SystemTime.HighPart))!=0 ||
  397. (result=GetFieldValue(MM_SHARED_USER_DATA_VA,
  398. "NT!_KUSER_SHARED_DATA",
  399. "SystemTime.LowPart",
  400. SystemTime.LowPart))!=0 ) {
  401. KUSER_SHARED_DATA sharedData;
  402. ULONG length;
  403. if (ReadMemory (address,
  404. &sharedData,
  405. sizeof (sharedData),
  406. &length)) {
  407. #if defined(_AMD64_)
  408. TickCount = sharedData.TickCount.LowPart;
  409. #else
  410. if (sharedData.TickCountLowDeprecated) {
  411. TickCount = sharedData.TickCountLowDeprecated;
  412. } else {
  413. TickCount = sharedData.TickCount.LowPart;
  414. }
  415. #endif
  416. TicksToMs = sharedData.TickCountMultiplier;
  417. InterruptTime.HighPart = sharedData.InterruptTime.High1Time;
  418. InterruptTime.LowPart = sharedData.InterruptTime.LowPart;
  419. SystemTime.HighPart = sharedData.SystemTime.High1Time;
  420. SystemTime.LowPart = sharedData.SystemTime.LowPart;
  421. result = 0;
  422. }
  423. else {
  424. dprintf ("\nReadTimeInfo: Could not read SHARED_USER_DATA @ %p\n",
  425. address);
  426. }
  427. }
  428. return result;
  429. }
  430. BOOLEAN
  431. ReadKmGlobals (
  432. )
  433. {
  434. ULONG result;
  435. ULONG64 val;
  436. INT i;
  437. struct {
  438. LPSTR Type;
  439. LPSTR Field;
  440. PULONG pOffset;
  441. } MainOffsets[] = {
  442. {"AFD!AFD_ENDPOINT", "Common.Datagram.ReceiveBufferListHead",&DatagramBufferListOffset },
  443. {"AFD!AFD_ENDPOINT", "Common.Datagram.ReceiveIrpListHead", &DatagramRecvListOffset },
  444. {"AFD!AFD_ENDPOINT", "Common.Datagram.PeekIrpListHead", &DatagramPeekListOffset },
  445. {"AFD!AFD_ENDPOINT", "RoutingNotifications", &RoutingNotifyListOffset },
  446. {"AFD!AFD_ENDPOINT", "RequestList", &RequestListOffset },
  447. {"AFD!AFD_ENDPOINT", "EventStatus", &EventStatusOffset },
  448. {"AFD!AFD_ENDPOINT", "Common.VirtualCircuit.Listening.UnacceptedConnectionListHead",
  449. &UnacceptedConnListOffset },
  450. {"AFD!AFD_ENDPOINT", "Common.VirtualCircuit.Listening.ReturnedConnectionListHead",
  451. &ReturnedConnListOffset },
  452. {"AFD!AFD_ENDPOINT", "Common.VirtualCircuit.Listening.ListenConnectionListHead",
  453. &ListenConnListOffset },
  454. {"AFD!AFD_ENDPOINT", "Common.VirtualCircuit.Listening.FreeConnectionListHead",
  455. &FreeConnListOffset },
  456. {"AFD!AFD_ENDPOINT", "Common.VirtualCircuit.Listening.PreacceptedConnectionsListHead",
  457. &PreaccConnListOffset },
  458. {"AFD!AFD_ENDPOINT", "Common.SanEndp.IrpList", &SanIrpListOffset },
  459. {"AFD!AFD_ENDPOINT", "Common.VirtualCircuit.Listening.ListeningIrpListHead",
  460. &ListenIrpListOffset },
  461. {"AFD!AFD_ENDPOINT", "GlobalEndpointListEntry", &EndpointLinkOffset },
  462. {"AFD!AFD_CONNECTION", "Common.NonBufferring.ReceiveBufferListHead",
  463. &ConnectionBufferListOffset },
  464. {"AFD!AFD_CONNECTION", "Common.NonBufferring.SendIrpListHead", &ConnectionSendListOffset },
  465. {"AFD!AFD_CONNECTION", "Common.NonBufferring.ReceiveIrpListHead",
  466. &ConnectionRecvListOffset },
  467. {"AFD!AFD_CONNECTION", "ListEntry", &ConnectionLinkOffset },
  468. {"AFD!AFD_POLL_INFO_INTERNAL","EndpointInfo", &PollEndpointInfoOffset },
  469. {"AFD!AFD_ADDRESS_ENTRY","Address", &AddressEntryAddressOffset },
  470. {"AFD!AFD_ADDRESS_ENTRY","AddressListLink", &AddressEntryLinkOffset },
  471. {"AFD!AFD_BUFFER_HEADER","BufferListEntry", &BufferLinkOffset },
  472. {"AFD!AFD_TRANSPORT_INFO","TransportInfoListEntry", &TransportInfoLinkOffset },
  473. {"AFD!FILE_OBJECT", "FsContext", &FsContextOffset },
  474. {"AFD!IRP", "Tail.Overlay.DriverContext", &DriverContextOffset }
  475. };
  476. struct {
  477. LPSTR Type;
  478. LPSTR Field;
  479. PULONG pOffset;
  480. } RefOffsets[] = {
  481. {"AFD!AFD_ENDPOINT", "ReferenceDebug", &EndpRefOffset },
  482. {"AFD!AFD_CONNECTION", "ReferenceDebug", &ConnRefOffset },
  483. {SavedMinorVersion>=2219
  484. ? "AFD!AFD_TPACKETS_INFO_INTERNAL"
  485. : "AFD!AFD_TRANSMIT_FILE_INFO_INTERNAL","ReferenceDebug", &TPackRefOffset }
  486. };
  487. if (!GetDebuggerData (KDBG_TAG, &DebuggerData, sizeof (DebuggerData))) {
  488. dprintf ("\nReadKmGlobals: could not get debugger data\n");
  489. NtResult = 1;
  490. }
  491. if (NtResult==0) {
  492. UserProbeAddress = 0;
  493. result = ReadPtr (DebuggerData.MmUserProbeAddress, &UserProbeAddress);
  494. if (result==0) {
  495. NtResult = 0;
  496. }
  497. else {
  498. if (result!=NtResult) {
  499. dprintf ("\nReadKmGlobals: could not read nt!MmUserProbeAddress, err: %ld\n");
  500. NtResult = result;
  501. }
  502. }
  503. }
  504. if (NtResult==0) {
  505. result = ReadTimeInfo ();
  506. if (result!=0) {
  507. if (result!=NtResult) {
  508. dprintf("\nReadKmGlobals: Could not read time info from USER_SHARED_DATA, err: %ld\n", result);
  509. NtResult = result;
  510. }
  511. }
  512. }
  513. result = GetFieldValue (0,
  514. "AFD!AfdBufferOverhead",
  515. NULL,
  516. val);
  517. if (result==0) {
  518. AfdResult = 0;
  519. }
  520. else {
  521. if (result!=AfdResult) {
  522. dprintf("\nReadKmGlobals: Could not read afd!AfdBufferOverhead, err: %ld\n", result);
  523. AfdResult = result;
  524. }
  525. }
  526. AfdBufferOverhead = (ULONG)val;
  527. if (AfdResult==0) {
  528. //
  529. // Try to get a pointer to afd!AfdDebug. If we can, then we know
  530. // the target machine is running a checked AFD.SYS.
  531. //
  532. IsCheckedAfd = ( GetExpression( "AFD!AfdDebug" ) != 0 );
  533. IsReferenceDebug = ( GetExpression( "AFD!AfdReferenceEndpoint" ) != 0 );
  534. result = GetFieldValue (0,
  535. "AFD!AfdStandardAddressLength",
  536. NULL,
  537. val);
  538. if (result!=0) {
  539. if (result!=AfdResult) {
  540. dprintf("\nReadKmGlobals: Could not read AFD!AfdStandardAddressLength, err: %ld\n", result);
  541. AfdResult = result;
  542. }
  543. }
  544. AfdStandardAddressLength = (ULONG)val;
  545. AfdBufferTagSize = GetTypeSize ("AFD!AFD_BUFFER_TAG");
  546. if (AfdBufferTagSize==0) {
  547. if (result!=AfdResult) {
  548. dprintf ("\nReadKmGlobals: Could not get sizeof (AFD_BUFFER_TAG)\n");
  549. AfdResult = result;
  550. }
  551. }
  552. for (i=0; i<sizeof (MainOffsets)/sizeof (MainOffsets[0]); i++ ) {
  553. result = GetFieldOffset (MainOffsets[i].Type, MainOffsets[i].Field, MainOffsets[i].pOffset);
  554. if (result!=0) {
  555. if (result!=AfdResult) {
  556. dprintf ("\nReadKmGlobals: Could not get offset of %s in %s, err: %ld\n",
  557. MainOffsets[i].Field, MainOffsets[i].Type, result);
  558. AfdResult = result;
  559. }
  560. }
  561. }
  562. if (IsReferenceDebug ) {
  563. for (i=0; i<sizeof (RefOffsets)/sizeof (RefOffsets[0]); i++ ) {
  564. result = GetFieldOffset (RefOffsets[i].Type, RefOffsets[i].Field, RefOffsets[i].pOffset);
  565. if (result!=0) {
  566. if (result!=AfdResult) {
  567. dprintf ("\nReadKmGlobals: Could not get offset of %s in %s, err: %ld\n",
  568. RefOffsets[i].Field, RefOffsets[i].Type, result);
  569. AfdResult = result;
  570. }
  571. }
  572. }
  573. RefDebugSize = GetTypeSize ("AFD!AFD_REFERENCE_LOCATION");
  574. if (RefDebugSize==0) {
  575. dprintf ("\nReadKmGlobals: sizeof (AFD!AFD_REFERENCE_LOCATION) is 0!!!!!\n");
  576. }
  577. }
  578. if (SavedMinorVersion>=2219) {
  579. result = GetFieldOffset ("AFD!AFD_TPACKETS_INFO_INTERNAL", "SendIrp", &SendIrpArrayOffset);
  580. if (result!=0) {
  581. dprintf ("\nReadKmGlobals: Could not get offset of %s in %s, err: %ld\n",
  582. "SendIrp", "AFD!AFD_TPACKETS_INFO_INTERNAL", result);
  583. if (result!=AfdResult) {
  584. AfdResult = result;
  585. }
  586. }
  587. }
  588. }
  589. if (NtResult==0 && AfdResult==0) {
  590. return TRUE;
  591. }
  592. else
  593. return FALSE;
  594. }
  595. HRESULT
  596. InitializeState (
  597. PDEBUG_CLIENT pClient
  598. )
  599. {
  600. PDEBUG_CONTROL DebugControl;
  601. HRESULT hr;
  602. BOOLEAN releaseClient = FALSE;
  603. SavedMachineType = IMAGE_FILE_MACHINE_UNKNOWN;
  604. SavedDebugClass = DEBUG_CLASS_UNINITIALIZED;
  605. SavedDebugType = 0;
  606. SavedMajorVersion = 0;
  607. SavedMinorVersion = 0;
  608. SavedSrvPack = 0;
  609. SavedBuildString[0] = 0;
  610. if (pClient==NULL) {
  611. if ((hr = DebugCreate(__uuidof(IDebugClient),
  612. (void **)&pClient)) != S_OK) {
  613. dprintf ("\nInitializeState: Cannot create debug client, hr:%lx\n", hr);
  614. return hr;
  615. }
  616. releaseClient = TRUE;
  617. }
  618. //
  619. // Get the architecture type.
  620. //
  621. if ((hr = pClient->QueryInterface(__uuidof(IDebugControl),
  622. (void **)&DebugControl)) == S_OK) {
  623. if ((hr = DebugControl->GetActualProcessorType(&SavedMachineType)) == S_OK) {
  624. ULONG stringUsed, platform;
  625. StateInitialized = TRUE;
  626. if ((hr = DebugControl->GetDebuggeeType(&SavedDebugClass, &SavedDebugType)) != S_OK) {
  627. dprintf ("\nInitializeState: Cannot get debug class and type, hr:%lx\n", hr);
  628. }
  629. if ((hr = DebugControl->GetSystemVersion(
  630. &platform,
  631. &SavedMajorVersion, &SavedMinorVersion,
  632. NULL, 0, NULL,
  633. &SavedSrvPack,
  634. &SavedBuildString[0], sizeof(SavedBuildString),
  635. &stringUsed)) != S_OK) {
  636. dprintf ("\nInitializeState: Cannot get system version, hr:%lx\n", hr);
  637. }
  638. }
  639. else {
  640. dprintf ("\nInitializeState: Cannot get processor type, hr:%lx\n", hr);
  641. }
  642. DebugControl->Release();
  643. }
  644. else {
  645. dprintf ("\nInitializeState: Cannot obtain debug control interface, hr:%lx\n", hr);
  646. }
  647. if (releaseClient)
  648. pClient->Release();
  649. return hr;
  650. }