Source code of Windows XP (NT5)
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.

249 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. w95track.c
  5. Abstract:
  6. Routines to track calls to Win95Reg APIs. Used for debugging only.
  7. Author:
  8. Jim Schmidt (jimschm) 30-Jan-1998
  9. Revisions:
  10. --*/
  11. #include "pch.h"
  12. #ifdef DEBUG
  13. #undef Win95RegOpenKeyExA
  14. #undef Win95RegCreateKeyExA
  15. #undef Win95RegOpenKeyExW
  16. #undef Win95RegCreateKeyExW
  17. #define DBG_W95TRACK "W95Track"
  18. #define NO_MATCH 0xffffffff
  19. DWORD g_DontCare95;
  20. typedef struct {
  21. PCSTR File;
  22. DWORD Line;
  23. HKEY Key;
  24. CHAR SubKey[];
  25. } KEYTRACK, *PKEYTRACK;
  26. GROWLIST g_KeyTrackList95 = GROWLIST_INIT;
  27. DWORD
  28. pFindKeyReference95 (
  29. HKEY Key
  30. )
  31. {
  32. INT i;
  33. DWORD Items;
  34. PKEYTRACK KeyTrack;
  35. Items = GrowListGetSize (&g_KeyTrackList95);
  36. for (i = (INT) (Items - 1) ; i >= 0 ; i--) {
  37. KeyTrack = (PKEYTRACK) GrowListGetItem (&g_KeyTrackList95, (DWORD) i);
  38. if (KeyTrack && KeyTrack->Key == Key) {
  39. return (DWORD) i;
  40. }
  41. }
  42. return NO_MATCH;
  43. }
  44. VOID
  45. pAddKeyReference95A (
  46. HKEY Key,
  47. PCSTR SubKey,
  48. PCSTR File,
  49. DWORD Line
  50. )
  51. {
  52. PKEYTRACK KeyTrack;
  53. DWORD Size;
  54. Size = sizeof (KEYTRACK) + SizeOfString (SubKey);
  55. KeyTrack = (PKEYTRACK) MemAlloc (g_hHeap, 0, Size);
  56. KeyTrack->Key = Key;
  57. KeyTrack->File = File;
  58. KeyTrack->Line = Line;
  59. StringCopy (KeyTrack->SubKey, SubKey);
  60. GrowListAppend (&g_KeyTrackList95, (PBYTE) KeyTrack, Size);
  61. MemFree (g_hHeap, 0, KeyTrack);
  62. }
  63. VOID
  64. pAddKeyReference95W (
  65. HKEY Key,
  66. PCWSTR SubKey,
  67. PCSTR File,
  68. DWORD Line
  69. )
  70. {
  71. PCSTR AnsiSubKey;
  72. AnsiSubKey = ConvertWtoA (SubKey);
  73. pAddKeyReference95A (Key, AnsiSubKey, File, Line);
  74. FreeConvertedStr (AnsiSubKey);
  75. }
  76. BOOL
  77. pDelKeyReference95 (
  78. HKEY Key
  79. )
  80. {
  81. DWORD Index;
  82. Index = pFindKeyReference95 (Key);
  83. if (Index != NO_MATCH) {
  84. GrowListDeleteItem (&g_KeyTrackList95, Index);
  85. return TRUE;
  86. }
  87. return FALSE;
  88. }
  89. VOID
  90. DumpOpenKeys95 (
  91. VOID
  92. )
  93. {
  94. DWORD d;
  95. DWORD Items;
  96. PKEYTRACK KeyTrack;
  97. Items = GrowListGetSize (&g_KeyTrackList95);
  98. if (Items) {
  99. DEBUGMSG ((DBG_ERROR, "Unclosed reg keys: %u", Items));
  100. }
  101. for (d = 0 ; d < Items ; d++) {
  102. KeyTrack = (PKEYTRACK) GrowListGetItem (&g_KeyTrackList95, d);
  103. DEBUGMSG ((DBG_W95TRACK, "Open Key: %hs (%hs line %u)", KeyTrack->SubKey, KeyTrack->File, KeyTrack->Line));
  104. }
  105. }
  106. VOID
  107. RegTrackTerminate95 (
  108. VOID
  109. )
  110. {
  111. FreeGrowList (&g_KeyTrackList95);
  112. }
  113. VOID
  114. DebugRegOpenRootKey95A (
  115. HKEY Key,
  116. PCSTR SubKey,
  117. PCSTR File,
  118. DWORD Line
  119. )
  120. {
  121. pAddKeyReference95A (Key, SubKey, File, Line);
  122. }
  123. VOID
  124. DebugRegOpenRootKey95W (
  125. HKEY Key,
  126. PCWSTR SubKey,
  127. PCSTR File,
  128. DWORD Line
  129. )
  130. {
  131. pAddKeyReference95W (Key, SubKey, File, Line);
  132. }
  133. LONG
  134. DebugRegOpenKeyEx95A (
  135. HKEY Key,
  136. PCSTR SubKey,
  137. DWORD Unused,
  138. REGSAM SamMask,
  139. PHKEY ResultPtr,
  140. PCSTR File,
  141. DWORD Line
  142. )
  143. {
  144. LONG rc;
  145. rc = Win95RegOpenKeyExA (Key, SubKey, Unused, SamMask, ResultPtr);
  146. if (rc == ERROR_SUCCESS) {
  147. pAddKeyReference95A (*ResultPtr, SubKey, File, Line);
  148. }
  149. return rc;
  150. }
  151. LONG
  152. DebugRegOpenKeyEx95W (
  153. HKEY Key,
  154. PCWSTR SubKey,
  155. DWORD Unused,
  156. REGSAM SamMask,
  157. PHKEY ResultPtr,
  158. PCSTR File,
  159. DWORD Line
  160. )
  161. {
  162. LONG rc;
  163. rc = Win95RegOpenKeyExW (Key, SubKey, Unused, SamMask, ResultPtr);
  164. if (rc == ERROR_SUCCESS) {
  165. pAddKeyReference95W (*ResultPtr, SubKey, File, Line);
  166. }
  167. return rc;
  168. }
  169. LONG
  170. DebugCloseRegKey95 (
  171. HKEY Key,
  172. PCSTR File,
  173. DWORD Line
  174. )
  175. {
  176. LONG rc;
  177. rc = RealCloseRegKey95 (Key);
  178. if (rc == ERROR_SUCCESS) {
  179. if (!pDelKeyReference95 (Key)) {
  180. DEBUGMSG ((
  181. DBG_ERROR,
  182. "Reg key handle closed via CloseRegKey95, but not opened "
  183. "with a tracked registry API. %s line %u",
  184. File,
  185. Line
  186. ));
  187. }
  188. }
  189. return rc;
  190. }
  191. #endif