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.

369 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. objects.cxx
  5. Abstract:
  6. This file contains the routines to list objects.
  7. Author:
  8. Jason Hartman (JasonHa) 2001-05-12
  9. Environment:
  10. User Mode
  11. --*/
  12. #include "precomp.hxx"
  13. PCSTR BaseObjectFields[] = {
  14. "hHmgr",
  15. "ulShareCount",
  16. "cExclusiveLock",
  17. "BaseFlags",
  18. "Tid",
  19. NULL
  20. };
  21. PCSTR SurfaceObjectFields[] = {
  22. "so.hsurf",
  23. "so.hdev",
  24. "so.sizlBitmap",
  25. "so.cjBits",
  26. "so.pvBits",
  27. "so.iBitmapFormat",
  28. "so.iType",
  29. "so.fjBitmap",
  30. NULL
  31. };
  32. PCSTR ExtendedSurfaceObjectFields[] = {
  33. "ulShareCount",
  34. "BaseFlags",
  35. "so.dhsurf",
  36. "SurfFlags",
  37. NULL
  38. };
  39. #if 0
  40. HRESULT
  41. ListObjectFilter(
  42. OutputControl *OutCtl,
  43. ULONG64 PoolAddr,
  44. ULONG TagFilter,
  45. TypeOutputParser *PoolHeadReader,
  46. PDEBUG_VALUE Tag,
  47. ULONG BlockSize,
  48. BOOL bQuotaWithTag,
  49. PVOID Context
  50. )
  51. {
  52. HRESULT hr;
  53. DEBUG_VALUE PoolType;
  54. * = ( *)Context;
  55. PALLOCATION_STATS AllocStatsAccum = (PALLOCATION_STATS)atu;
  56. if ( != S_OK)
  57. {
  58. return S_FALSE;
  59. }
  60. hr = PoolHeadReader->Get(&PoolType, "PoolType", DEBUG_VALUE_INT32);
  61. if (hr == S_OK)
  62. {
  63. if (PoolType.I32 == 0)
  64. {
  65. hr = atu->Add(Tag->I32, FreePool, BlockSize);
  66. AllocStatsAccum->Free++;
  67. AllocStatsAccum->FreeSize += BlockSize;
  68. }
  69. else
  70. {
  71. DEBUG_VALUE PoolIndex;
  72. if (!(PoolType.I32 & POOL_QUOTA_MASK) ||
  73. bQuotaWithTag)
  74. {
  75. Tag->I32 &= ~PROTECTED_POOL;
  76. }
  77. else if (PoolType.I32 & POOL_QUOTA_MASK)
  78. {
  79. Tag->I32 = 'CORP';
  80. }
  81. if (!NewPool)
  82. {
  83. hr = PoolHeadReader->Get(&PoolIndex, "PoolIndex", DEBUG_VALUE_INT32);
  84. }
  85. if (hr == S_OK)
  86. {
  87. if (NewPool ? (PoolType.I32 & 0x04) : (PoolIndex.I32 & 0x80))
  88. {
  89. hr = atu->Add(Tag->I32, AllocatedPool, BlockSize);
  90. AllocStatsAccum->Allocated++;
  91. AllocStatsAccum->AllocatedSize += BlockSize;
  92. if (AllocStatsAccum->Allocated % 100 == 0)
  93. {
  94. OutCtl->Output(".");
  95. if (AllocStatsAccum->Allocated % 8000 == 0)
  96. {
  97. OutCtl->Output("\n");
  98. }
  99. }
  100. }
  101. else
  102. {
  103. hr = atu->Add(Tag->I32, FreePool, BlockSize);
  104. AllocStatsAccum->Free++;
  105. AllocStatsAccum->FreeSize += BlockSize;
  106. }
  107. }
  108. else
  109. {
  110. hr = atu->Add(Tag->I32, IndeterminatePool, BlockSize);
  111. AllocStatsAccum->Indeterminate++;
  112. AllocStatsAccum->IndeterminateSize += BlockSize;
  113. }
  114. }
  115. }
  116. else
  117. {
  118. AllocStatsAccum->Indeterminate++;
  119. AllocStatsAccum->IndeterminateSize += BlockSize;
  120. }
  121. return hr;
  122. }
  123. #endif
  124. DECLARE_API( listobj )
  125. {
  126. HRESULT hr;
  127. BEGIN_API( listobj );
  128. BOOL CheckType = TRUE;
  129. Array<BOOL> MatchType(TOTAL_TYPE);
  130. Array<CHAR> TypeList;
  131. ULONG TagFilter = ' *G';
  132. FLONG SearchFlags = 0;
  133. BOOL CheckHandle = FALSE;
  134. BOOL Summary = FALSE;
  135. BOOL BadArg = FALSE;
  136. OutputControl OutCtl(Client);
  137. ULONG64 EntryAddr;
  138. ULONG64 gcMaxHmgr;
  139. ULONG EntrySize;
  140. ULONG Index = 0;
  141. ULONG LongestType = 0;
  142. int i;
  143. for (i = 0; i <= MAX_TYPE; i++)
  144. {
  145. ULONG Len = strlen(pszTypes2[i]);
  146. if (Len > LongestType)
  147. {
  148. LongestType = Len;
  149. }
  150. }
  151. while (!BadArg)
  152. {
  153. while (isspace(*args)) args++;
  154. if (*args == '-')
  155. {
  156. // Process switches
  157. args++;
  158. BadArg = (*args == '\0' || isspace(*args));
  159. while (*args != '\0' && !isspace(*args))
  160. {
  161. switch (tolower(*args))
  162. {
  163. case 'a':
  164. if (CheckType && !TypeList.IsEmpty())
  165. {
  166. BadArg = TRUE;
  167. OutCtl.OutErr("Error: -a may not be specified with a Type list.\n");
  168. }
  169. else
  170. {
  171. CheckType = FALSE;
  172. }
  173. break;
  174. case 'h':
  175. CheckHandle = TRUE;
  176. break;
  177. case 'n':
  178. SearchFlags |= SEARCH_POOL_NONPAGED;
  179. break;
  180. case 'p':
  181. SearchFlags |= SEARCH_POOL_PAGED;
  182. break;
  183. case 's':
  184. Summary = TRUE;
  185. break;
  186. default:
  187. BadArg = TRUE;
  188. break;
  189. }
  190. if (BadArg) break;
  191. args++;
  192. }
  193. }
  194. else
  195. {
  196. if (*args == '\0') break;
  197. {
  198. // This argument must be a Type specification.
  199. if (!CheckType)
  200. {
  201. OutCtl.OutErr("Error: a Type list may not be specified with -a.\n");
  202. BadArg = TRUE;
  203. break;
  204. }
  205. for (i = 0; i <= MAX_TYPE; i++)
  206. {
  207. SIZE_T CheckLen = strlen(pszTypes2[i]);
  208. if (_strnicmp(args, pszTypes2[i], CheckLen) == 0 &&
  209. (!iscsym(args[CheckLen]) ||
  210. (_strnicmp(&args[CheckLen], "_TYPE", 5) == 0 &&
  211. !iscsym(args[CheckLen+5])
  212. )))
  213. {
  214. if (!MatchType[i])
  215. {
  216. // Add Type to list
  217. SIZE_T CatLoc = TypeList.GetLength();
  218. if (CatLoc > 0)
  219. {
  220. TypeList[CatLoc] = ' ';
  221. TagFilter = '???G';
  222. }
  223. else
  224. {
  225. TagFilter = '0??G' + (i << 24);
  226. }
  227. TypeList.Set(pszTypes2[i], CheckLen+1, CatLoc);
  228. }
  229. MatchType[i] = TRUE;
  230. args += CheckLen;
  231. if (iscsym(*args)) args += 5;
  232. break;
  233. }
  234. }
  235. if (i > MAX_TYPE)
  236. {
  237. OutCtl.OutErr("Error: Unknown Type in '%s'.\n", args);
  238. BadArg = TRUE;
  239. break;
  240. }
  241. }
  242. }
  243. }
  244. if (!BadArg)
  245. {
  246. if (CheckType && TypeList.IsEmpty())
  247. {
  248. OutCtl.OutErr("Error: Missing -a or Type list.\n");
  249. BadArg = TRUE;
  250. }
  251. }
  252. if (BadArg)
  253. {
  254. if (*args == '?')
  255. {
  256. OutCtl.Output("listobj searches session pool for known GDI objects\n"
  257. " and displays basic object properties\n"
  258. "\n");
  259. }
  260. OutCtl.Output("Usage: listobj [-?hnps] <-a | Type(s)>\n"
  261. "\n"
  262. " a - All object types\n"
  263. " h - Validate handle\n"
  264. " n - Search non-paged pool\n"
  265. " p - Seach paged pool\n"
  266. " s - Summary counts only\n"
  267. "\n"
  268. " The -s option combined with the -a option will produce\n"
  269. " a list of the totals for each object type.\n");
  270. OutCtl.Output("\n Valid Type values are:\n");
  271. i = 0;
  272. while (i <= MAX_TYPE)
  273. {
  274. do
  275. {
  276. OutCtl.Output(" %-*s", LongestType, pszTypes2[i++]);
  277. } while (i <= MAX_TYPE && i%4);
  278. OutCtl.Output("\n");
  279. }
  280. hr = S_OK;
  281. }
  282. else
  283. {
  284. ALLOCATION_STATS AllocStats = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  285. if ((SearchFlags & (SEARCH_POOL_PAGED | SEARCH_POOL_NONPAGED)) == 0)
  286. {
  287. SearchFlags |= SEARCH_POOL_PAGED | SEARCH_POOL_NONPAGED;
  288. }
  289. #if 0
  290. hr = SearchSessionPool(Client,
  291. DEFAULT_SESSION, TagFilter, SearchFlags,
  292. 0,
  293. ListObjectsFilter, &AllocStats, &AllocStats);
  294. #else
  295. OutCtl.OutWarn("listobj not implemented.\n");
  296. hr = E_NOTIMPL;
  297. #endif
  298. if (hr == S_OK || hr == E_ABORT)
  299. {
  300. //OutputAllocStats(&OutCtl, &AllocStats, (hr != S_OK));
  301. }
  302. else
  303. {
  304. OutCtl.OutWarn("SearchSessionPool returned %s\n", pszHRESULT(hr));
  305. }
  306. }
  307. return hr;
  308. }