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.

207 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. atom.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Ramon J San Andres (ramonsa) 5-Nov-1993
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #define MAXINTATOM 0xC000
  16. VOID
  17. AtomExtension(
  18. PCSTR lpArgumentString
  19. );
  20. VOID DumpAtomTable(
  21. ULONG64 ppat,
  22. ULONG a
  23. );
  24. DECLARE_API( atom )
  25. /*++
  26. Routine Description:
  27. This function is called as an NTSD extension to dump a user mode atom table
  28. Called as:
  29. !atom [address]
  30. If an address if not given or an address of 0 is given, then the
  31. process atom table is dumped.
  32. Arguments:
  33. args - [address [detail]]
  34. Return Value:
  35. None
  36. --*/
  37. {
  38. // AtomExtension( args );
  39. // Copied its code here :-
  40. ULONG64 ppat, pat;
  41. ULONG a;
  42. INIT_API();
  43. try {
  44. while (*args == ' ') {
  45. args++;
  46. }
  47. if (*args && *args != 0xa) {
  48. a = (ULONG) GetExpression((LPSTR)args);
  49. } else {
  50. a = 0;
  51. }
  52. ppat = GetExpression("kernel32!BaseLocalAtomTable");
  53. if ((ppat != 0) &&
  54. ReadPointer(ppat, &pat)) {
  55. dprintf("\nLocal atom table ");
  56. DumpAtomTable(ppat, a);
  57. dprintf("Use 'dt _RTL_ATOM_TABLE %p'.\n", ppat);
  58. }
  59. } except (EXCEPTION_EXECUTE_HANDLER) {
  60. ;
  61. }
  62. EXIT_API();
  63. return S_OK;
  64. }
  65. CHAR szBaseLocalAtomTable[] = "kernel32!BaseLocalAtomTable";
  66. VOID DumpAtomTable(
  67. ULONG64 ppat,
  68. ULONG a
  69. )
  70. {
  71. ULONG64 pat;
  72. ULONG64 pate;
  73. ULONG iBucket, NumberOfBuckets, PtrSize, Off, NameOff;
  74. LPWSTR pwsz;
  75. BOOL fFirst;
  76. if (!ReadPointer(ppat, &pat) ||
  77. pat == 0) {
  78. dprintf("is not initialized.\n");
  79. return;
  80. }
  81. if (InitTypeRead(pat, _RTL_ATOM_TABLE)) {
  82. return;
  83. }
  84. if (a) {
  85. dprintf("\n");
  86. } else {
  87. dprintf("at %x\n", pat);
  88. }
  89. NumberOfBuckets = (ULONG) ReadField(NumberOfBuckets);
  90. GetFieldOffset("_RTL_ATOM_TABLE", "Buckets", &Off);
  91. GetFieldOffset("_RTL_ATOM_TABLE", "Name", &NameOff);
  92. PtrSize = IsPtr64() ? 8 : 4;
  93. for (iBucket = 0; iBucket < NumberOfBuckets; iBucket++) {
  94. if (!ReadPointer(pat + iBucket * PtrSize + Off, &pate))
  95. {
  96. pate = 0;
  97. }
  98. if (pate != 0 && !a) {
  99. dprintf("Bucket %2d:", iBucket);
  100. }
  101. fFirst = TRUE;
  102. while (pate != 0) {
  103. ULONG NameLength;
  104. if (!fFirst && !a) {
  105. dprintf(" ");
  106. }
  107. fFirst = FALSE;
  108. if (InitTypeRead(pate, _RTL_ATOM_TABLE_ENTRY)) {
  109. return;
  110. }
  111. NameLength = (ULONG) ReadField(NameLength);
  112. pwsz = (LPWSTR)LocalAlloc(LPTR, ((NameLength) + 1) * sizeof(WCHAR));
  113. ReadMemory(pate + NameOff, pwsz, NameLength * sizeof(WCHAR), NULL);
  114. pwsz[NameLength ] = L'\0';
  115. if (a == 0 || a == ((ULONG)ReadField(HandleIndex) | MAXINTATOM)) {
  116. dprintf("%hx(%2d) = %ls (%d)%s\n",
  117. (ATOM)((ULONG)ReadField(HandleIndex) | MAXINTATOM),
  118. (ULONG)ReadField(ReferenceCount),
  119. pwsz, (NameLength),
  120. (ULONG)ReadField(Flags) & RTL_ATOM_PINNED ? " pinned" : "");
  121. if (a) {
  122. LocalFree(pwsz);
  123. return;
  124. }
  125. }
  126. LocalFree(pwsz);
  127. if (pate == ReadField(HashLink)) {
  128. dprintf("Bogus hash link at %p\n", pate);
  129. break;
  130. }
  131. pate = ReadField(HashLink);
  132. }
  133. }
  134. if (a)
  135. dprintf("\n");
  136. }
  137. VOID
  138. AtomExtension(
  139. PCSTR lpArgumentString
  140. )
  141. {
  142. ULONG64 ppat;
  143. ULONG a;
  144. try {
  145. while (*lpArgumentString == ' ') {
  146. lpArgumentString++;
  147. }
  148. if (*lpArgumentString && *lpArgumentString != 0xa) {
  149. a = (ATOM)GetExpression((LPSTR)lpArgumentString);
  150. } else {
  151. a = 0;
  152. }
  153. ppat = GetExpression(szBaseLocalAtomTable);
  154. if (ppat != 0) {
  155. dprintf("\nLocal atom table ");
  156. DumpAtomTable(ppat, a);
  157. }
  158. } except (EXCEPTION_EXECUTE_HANDLER) {
  159. ;
  160. }
  161. }