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.

505 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. init.c
  5. Abstract:
  6. This module provides the main cluster initialization.
  7. Author:
  8. John Vert (jvert) 6/5/1996
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include "clusrtl.h"
  16. #define MEM_LEAKS 1
  17. #define EVENT_LEAKS 1
  18. #define KEY_LEAKS 1
  19. #define HEAP_SIGNATURE 'PAEH'
  20. typedef struct _MEM_HDR {
  21. DWORD Signature;
  22. PVOID CallersAddress;
  23. PVOID CallersCaller;
  24. } MEM_HDR, *PMEM_HDR;
  25. #ifdef MEM_LEAKS
  26. HLOCAL
  27. WINAPI
  28. CheckLocalAlloc(
  29. UINT uFlags,
  30. UINT uBytes
  31. )
  32. {
  33. HLOCAL memory;
  34. PMEM_HDR memHdr;
  35. PVOID callersAddress;
  36. PVOID callersCaller;
  37. RtlGetCallersAddress(
  38. &callersAddress,
  39. &callersCaller );
  40. memHdr = LocalAlloc( uFlags, uBytes + sizeof(MEM_HDR) );
  41. if ( !memHdr ) {
  42. return NULL;
  43. }
  44. memHdr->Signature = HEAP_SIGNATURE;
  45. memHdr->CallersAddress = callersAddress;
  46. memHdr->CallersCaller = callersCaller;
  47. return(memHdr+1);
  48. }
  49. HLOCAL
  50. WINAPI
  51. CheckLocalFree(
  52. HLOCAL hMem
  53. )
  54. {
  55. PMEM_HDR memHdr = hMem;
  56. if ( memHdr ) {
  57. --memHdr;
  58. if ( memHdr->Signature != HEAP_SIGNATURE ) {
  59. memHdr++;
  60. }
  61. }
  62. return( LocalFree(memHdr) );
  63. }
  64. #endif // MEM_LEAKS
  65. #ifdef EVENT_LEAKS
  66. //WINBASEAPI
  67. HANDLE
  68. WINAPI
  69. CheckCreateEventA(
  70. LPSECURITY_ATTRIBUTES lpEventAttributes,
  71. BOOL bManualReset,
  72. BOOL bInitialState,
  73. LPCSTR lpName
  74. )
  75. {
  76. HANDLE handle;
  77. PVOID callersAddress;
  78. PVOID callersCaller;
  79. RtlGetCallersAddress(
  80. &callersAddress,
  81. &callersCaller );
  82. handle = CreateEventA(
  83. lpEventAttributes,
  84. bManualReset,
  85. bInitialState,
  86. lpName
  87. );
  88. ClRtlLogPrint( "[TEST] CreateEvent returns handle %1!lx!, called from %2!lx! and %3!lx!\n",
  89. handle,
  90. callersAddress,
  91. callersCaller );
  92. return(handle);
  93. } // CheckCreateEventA
  94. //WINBASEAPI
  95. HANDLE
  96. WINAPI
  97. CheckCreateEventW(
  98. LPSECURITY_ATTRIBUTES lpEventAttributes,
  99. BOOL bManualReset,
  100. BOOL bInitialState,
  101. LPCWSTR lpName
  102. )
  103. {
  104. HANDLE handle;
  105. PVOID callersAddress;
  106. PVOID callersCaller;
  107. RtlGetCallersAddress(
  108. &callersAddress,
  109. &callersCaller );
  110. handle = CreateEventW(
  111. lpEventAttributes,
  112. bManualReset,
  113. bInitialState,
  114. lpName
  115. );
  116. ClRtlLogPrint( "[TEST] CreateEventW returns handle %1!lx!, called from %2!lx! and %3!lx!\n",
  117. handle,
  118. callersAddress,
  119. callersCaller );
  120. return(handle);
  121. } // CheckCreateEventW
  122. #endif // EVENT_LEAKS
  123. #ifdef KEY_LEAKS
  124. //WINADVAPI
  125. LONG
  126. APIENTRY
  127. CheckRegOpenKeyA(
  128. HKEY hKey,
  129. LPCSTR lpSubKey,
  130. PHKEY phkResult
  131. )
  132. {
  133. LONG status;
  134. PVOID callersAddress;
  135. PVOID callersCaller;
  136. RtlGetCallersAddress(
  137. &callersAddress,
  138. &callersCaller );
  139. status = RegOpenKeyA(
  140. hKey,
  141. lpSubKey,
  142. phkResult
  143. );
  144. if ( status ) {
  145. ClRtlLogPrint( "[TEST] RegOpenKey returns key %1!lx!, called from %2!lx! and %3!lx!\n",
  146. *phkResult,
  147. callersAddress,
  148. callersCaller );
  149. }
  150. return(status);
  151. } // CheckRegOpenKeyA
  152. //WINADVAPI
  153. LONG
  154. APIENTRY
  155. CheckRegOpenKeyW(
  156. HKEY hKey,
  157. LPCWSTR lpSubKey,
  158. PHKEY phkResult
  159. )
  160. {
  161. LONG status;
  162. PVOID callersAddress;
  163. PVOID callersCaller;
  164. RtlGetCallersAddress(
  165. &callersAddress,
  166. &callersCaller );
  167. status = RegOpenKeyW(
  168. hKey,
  169. lpSubKey,
  170. phkResult
  171. );
  172. if ( status ) {
  173. ClRtlLogPrint( "[TEST] RegOpenKeyW returns key %1!lx!, called from %2!lx! and %3!lx!\n",
  174. *phkResult,
  175. callersAddress,
  176. callersCaller );
  177. }
  178. return(status);
  179. } // CheckRegOpenKeyW
  180. //WINADVAPI
  181. LONG
  182. APIENTRY
  183. CheckRegOpenKeyExA(
  184. HKEY hKey,
  185. LPCSTR lpSubKey,
  186. DWORD ulOptions,
  187. REGSAM samDesired,
  188. PHKEY phkResult
  189. )
  190. {
  191. LONG status;
  192. PVOID callersAddress;
  193. PVOID callersCaller;
  194. RtlGetCallersAddress(
  195. &callersAddress,
  196. &callersCaller );
  197. status = RegOpenKeyExA(
  198. hKey,
  199. lpSubKey,
  200. ulOptions,
  201. samDesired,
  202. phkResult
  203. );
  204. if ( status ) {
  205. ClRtlLogPrint( "[TEST] RegOpenKeyEx returns key %1!lx!, called from %2!lx! and %3!lx!\n",
  206. *phkResult,
  207. callersAddress,
  208. callersCaller );
  209. }
  210. return(status);
  211. } // CheckRegOpenKeyExA
  212. //WINADVAPI
  213. LONG
  214. APIENTRY
  215. CheckRegOpenKeyExW(
  216. HKEY hKey,
  217. LPCWSTR lpSubKey,
  218. DWORD ulOptions,
  219. REGSAM samDesired,
  220. PHKEY phkResult
  221. )
  222. {
  223. LONG status;
  224. PVOID callersAddress;
  225. PVOID callersCaller;
  226. RtlGetCallersAddress(
  227. &callersAddress,
  228. &callersCaller );
  229. status = RegOpenKeyExW(
  230. hKey,
  231. lpSubKey,
  232. ulOptions,
  233. samDesired,
  234. phkResult
  235. );
  236. if ( status ) {
  237. ClRtlLogPrint( "[TEST] RegOpenKeyExW returns key %1!lx!, called from %2!lx! and %3!lx!\n",
  238. *phkResult,
  239. callersAddress,
  240. callersCaller );
  241. }
  242. return(status);
  243. } // CheckRegOpenKeyExW
  244. //WINADVAPI
  245. LONG
  246. APIENTRY
  247. CheckRegCreateKeyA(
  248. HKEY hKey,
  249. LPCSTR lpSubKey,
  250. PHKEY phkResult
  251. )
  252. {
  253. LONG status;
  254. PVOID callersAddress;
  255. PVOID callersCaller;
  256. RtlGetCallersAddress(
  257. &callersAddress,
  258. &callersCaller );
  259. status = RegCreateKeyA(
  260. hKey,
  261. lpSubKey,
  262. phkResult
  263. );
  264. if ( status ) {
  265. ClRtlLogPrint( "[TEST] RegCreateKey returns key %1!lx!, called from %2!lx! and %3!lx!\n",
  266. *phkResult,
  267. callersAddress,
  268. callersCaller );
  269. }
  270. return(status);
  271. } // CheckRegCreateKeyA
  272. //WINADVAPI
  273. LONG
  274. APIENTRY
  275. CheckRegCreateKeyW(
  276. HKEY hKey,
  277. LPCWSTR lpSubKey,
  278. PHKEY phkResult
  279. )
  280. {
  281. LONG status;
  282. PVOID callersAddress;
  283. PVOID callersCaller;
  284. RtlGetCallersAddress(
  285. &callersAddress,
  286. &callersCaller );
  287. status = RegCreateKeyW(
  288. hKey,
  289. lpSubKey,
  290. phkResult
  291. );
  292. if ( status ) {
  293. ClRtlLogPrint( "[TEST] RegCreateKeyW returns key %1!lx!, called from %2!lx! and %3!lx!\n",
  294. *phkResult,
  295. callersAddress,
  296. callersCaller );
  297. }
  298. return(status);
  299. } // CheckRegCreateKeyW
  300. //WINADVAPI
  301. LONG
  302. APIENTRY
  303. CheckRegCreateKeyExA(
  304. HKEY hKey,
  305. LPCSTR lpSubKey,
  306. DWORD Reserved,
  307. LPSTR lpClass,
  308. DWORD dwOptions,
  309. REGSAM samDesired,
  310. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  311. PHKEY phkResult,
  312. LPDWORD lpdwDisposition
  313. )
  314. {
  315. LONG status;
  316. PVOID callersAddress;
  317. PVOID callersCaller;
  318. RtlGetCallersAddress(
  319. &callersAddress,
  320. &callersCaller );
  321. status = RegCreateKeyExA(
  322. hKey,
  323. lpSubKey,
  324. Reserved,
  325. lpClass,
  326. dwOptions,
  327. samDesired,
  328. lpSecurityAttributes,
  329. phkResult,
  330. lpdwDisposition
  331. );
  332. if ( status ) {
  333. ClRtlLogPrint( "[TEST] RegCreateKeyEx returns key %1!lx!, called from %2!lx! and %3!lx!\n",
  334. *phkResult,
  335. callersAddress,
  336. callersCaller );
  337. }
  338. return(status);
  339. } // CheckRegCreateKeyExA
  340. //WINADVAPI
  341. LONG
  342. APIENTRY
  343. CheckRegCreateKeyExW(
  344. HKEY hKey,
  345. LPCWSTR lpSubKey,
  346. DWORD Reserved,
  347. LPWSTR lpClass,
  348. DWORD dwOptions,
  349. REGSAM samDesired,
  350. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  351. PHKEY phkResult,
  352. LPDWORD lpdwDisposition
  353. )
  354. {
  355. LONG status;
  356. PVOID callersAddress;
  357. PVOID callersCaller;
  358. RtlGetCallersAddress(
  359. &callersAddress,
  360. &callersCaller );
  361. status = RegCreateKeyExW(
  362. hKey,
  363. lpSubKey,
  364. Reserved,
  365. lpClass,
  366. dwOptions,
  367. samDesired,
  368. lpSecurityAttributes,
  369. phkResult,
  370. lpdwDisposition
  371. );
  372. ClRtlLogPrint( "[TEST] RegCreateKeyExW returns key %1!lx!, called from %2!lx! and %3!lx!\n",
  373. *phkResult,
  374. callersAddress,
  375. callersCaller );
  376. return(status);
  377. } // CheckRegCreateKeyExW
  378. //WINADVAPI
  379. LONG
  380. APIENTRY
  381. CheckRegCloseKey(
  382. HKEY hKey
  383. )
  384. {
  385. LONG status;
  386. PVOID callersAddress;
  387. PVOID callersCaller;
  388. RtlGetCallersAddress(
  389. &callersAddress,
  390. &callersCaller );
  391. ClRtlLogPrint( "[TEST] RegCloseKey for handle %1!lx! called from %2!lx! and %3!lx!\n",
  392. hKey,
  393. callersAddress,
  394. callersCaller );
  395. status = RegCloseKey(
  396. hKey
  397. );
  398. return(status);
  399. } // CheckRegCloseKey
  400. #endif // KEY_LEAKS