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.

211 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1992-2000 Microsoft Corporation
  3. Module Name:
  4. extapis.cpp
  5. Abstract:
  6. Procedures exported by the dll which can be called by
  7. other extension dlls and debugger
  8. Environment:
  9. User Mode.
  10. Revision History:
  11. Kshitiz K. Sharma (kksharma) 2/1/2001
  12. --*/
  13. #include "precomp.h"
  14. #include <time.h>
  15. PCHAR gTargetMode[] = {
  16. "No Target",
  17. "Kernel Mode",
  18. "User Mode",
  19. };
  20. PCHAR gAllOsTypes[] = {
  21. "Windows 95",
  22. "Windows 98",
  23. "Windows ME",
  24. "Windows NT 4",
  25. "Windows 2000",
  26. "Windows XP",
  27. };
  28. HRESULT
  29. GetProcessorInfo(
  30. PCPU_INFO pCpuInfo
  31. )
  32. {
  33. HRESULT Hr;
  34. ULONG Processor;
  35. ULONG i;
  36. DEBUG_PROCESSOR_IDENTIFICATION_ALL ProcId;
  37. pCpuInfo->Type = g_TargetMachine;
  38. if (g_ExtControl->GetNumberProcessors(&pCpuInfo->NumCPUs) != S_OK) {
  39. pCpuInfo->NumCPUs = 0;
  40. }
  41. PDEBUG_SYSTEM_OBJECTS DebugSystem;
  42. ULONG64 hCurrentThread;
  43. if ((Hr = g_ExtClient->QueryInterface(__uuidof(IDebugSystemObjects),
  44. (void **)&DebugSystem)) != S_OK) {
  45. return Hr;
  46. }
  47. DebugSystem->GetCurrentThreadHandle(&hCurrentThread);
  48. DebugSystem->Release();
  49. pCpuInfo->CurrentProc = (ULONG) hCurrentThread - 1;
  50. for (i=0; i<pCpuInfo->NumCPUs; i++) {
  51. // Get Info for all procs
  52. if ((Hr = g_ExtData->ReadProcessorSystemData(i,
  53. DEBUG_DATA_PROCESSOR_IDENTIFICATION,
  54. &pCpuInfo->ProcInfo[i],
  55. sizeof(pCpuInfo->ProcInfo[i]), NULL)) != S_OK) {
  56. continue;
  57. }
  58. }
  59. return Hr;
  60. }
  61. void
  62. GetOsType(ULONG PlatForm, PTARGET_DEBUG_INFO pTargetInfo)
  63. {
  64. if (PlatForm == VER_PLATFORM_WIN32_NT)
  65. // If its nt target
  66. {
  67. if (pTargetInfo->OsInfo.Version.Minor > 2195) {
  68. pTargetInfo->OsInfo.Type = WIN_NT5_1;
  69. } else if (pTargetInfo->OsInfo.Version.Minor > 1381) {
  70. pTargetInfo->OsInfo.Type = WIN_NT5;
  71. } else {
  72. pTargetInfo->OsInfo.Type = WIN_NT4;
  73. }
  74. } else {
  75. if (pTargetInfo->OsInfo.Version.Minor > 2222) {
  76. pTargetInfo->OsInfo.Type = WIN_ME;
  77. } else if (pTargetInfo->OsInfo.Version.Minor > 950) {
  78. pTargetInfo->OsInfo.Type = WIN_98;
  79. } else if (pTargetInfo->OsInfo.Version.Minor > 950) {
  80. pTargetInfo->OsInfo.Type = WIN_95;
  81. }
  82. }
  83. }
  84. HRESULT
  85. FillTargetDebugInfo(
  86. PDEBUG_CLIENT Client,
  87. PTARGET_DEBUG_INFO pTargetInfo
  88. )
  89. {
  90. HRESULT Hr;
  91. ULONG Time;
  92. ULONG PlatForm, Qualifier;
  93. BOOL fUnInitialized = FALSE;
  94. if (pTargetInfo->SizeOfStruct != sizeof(TARGET_DEBUG_INFO)) {
  95. return E_FAIL;
  96. }
  97. if (!g_ExtClient)
  98. {
  99. fUnInitialized = TRUE;
  100. }
  101. ZeroMemory(pTargetInfo, sizeof(TARGET_DEBUG_INFO));
  102. pTargetInfo->SizeOfStruct = sizeof(TARGET_DEBUG_INFO);
  103. if (fUnInitialized)
  104. {
  105. // Do this to prevent multiple INIT_API calls in same extension call
  106. INIT_API();
  107. }
  108. pTargetInfo->Mode = (TARGET_MODE) g_TargetClass;
  109. Hr = GetProcessorInfo(&pTargetInfo->Cpu);
  110. Hr = g_ExtControl->GetCurrentSystemUpTime(&Time);
  111. if (Hr == S_OK) {
  112. pTargetInfo->SysUpTime = Time;
  113. }
  114. PDEBUG_SYSTEM_OBJECTS2 DebugSystem;
  115. ULONG64 hCurrentThread;
  116. if ((Hr = g_ExtClient->QueryInterface(__uuidof(IDebugSystemObjects),
  117. (void **)&DebugSystem)) == S_OK) {
  118. Hr = DebugSystem->GetCurrentProcessUpTime(&Time);
  119. DebugSystem->Release();
  120. if (Hr == S_OK) {
  121. pTargetInfo->AppUpTime = Time;
  122. }
  123. }
  124. Hr = g_ExtControl->GetCurrentTimeDate(&Time);
  125. if (Hr == S_OK) {
  126. pTargetInfo->CrashTime = Time;
  127. }
  128. time_t ltime;
  129. time( &ltime );
  130. pTargetInfo->EntryDate = (ULONG64) ltime;
  131. Hr = g_ExtControl->GetSystemVersion(&PlatForm,
  132. &pTargetInfo->OsInfo.Version.Major,
  133. &pTargetInfo->OsInfo.Version.Minor,
  134. &pTargetInfo->OsInfo.ServicePackString[0],
  135. sizeof(pTargetInfo->OsInfo.ServicePackString),
  136. NULL,
  137. &pTargetInfo->OsInfo.SrvPackNumber,
  138. &pTargetInfo->OsInfo.OsString[0],
  139. sizeof(pTargetInfo->OsInfo.OsString),
  140. NULL);
  141. GetOsType(PlatForm, pTargetInfo);
  142. pTargetInfo->Source = Debugger;
  143. Hr = g_ExtData->ReadDebuggerData(DEBUG_DATA_ProductType,
  144. &pTargetInfo->OsInfo.ProductType,
  145. sizeof(pTargetInfo->OsInfo.ProductType),
  146. NULL);
  147. if (FAILED(Hr))
  148. {
  149. pTargetInfo->OsInfo.ProductType = 0;
  150. }
  151. Hr = g_ExtData->ReadDebuggerData(DEBUG_DATA_SuiteMask,
  152. &pTargetInfo->OsInfo.Suite,
  153. sizeof(pTargetInfo->OsInfo.Suite),
  154. NULL);
  155. if (FAILED(Hr))
  156. {
  157. pTargetInfo->OsInfo.Suite = 0;
  158. }
  159. if (fUnInitialized)
  160. {
  161. EXIT_API();
  162. }
  163. return Hr;
  164. }
  165. HRESULT WINAPI
  166. _EFN_GetTargetInfo
  167. (
  168. PDEBUG_CLIENT Client,
  169. PTARGET_DEBUG_INFO pTargetInfo
  170. )
  171. {
  172. return FillTargetDebugInfo(Client, pTargetInfo);
  173. }