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.

291 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. WMI dll main file
  7. Author:
  8. 16-Jan-1997 AlanWar
  9. Revision History:
  10. --*/
  11. #define INITGUID
  12. #include "wmiump.h"
  13. #include "evntrace.h"
  14. #include <rpc.h>
  15. #include "trcapi.h"
  16. /*
  17. Added by Digvijay
  18. start
  19. */
  20. #if DBG
  21. BOOLEAN WmipLoggingEnabled = TRUE;
  22. #endif
  23. extern
  24. RTL_CRITICAL_SECTION UMLogCritSect;
  25. BOOLEAN EtwLocksInitialized = FALSE;
  26. /*
  27. Added by Digvijay
  28. end
  29. */
  30. #ifndef MEMPHIS
  31. RTL_CRITICAL_SECTION PMCritSect;
  32. PVOID WmipProcessHeap = NULL;
  33. HANDLE WmipDeviceHandle;
  34. #else
  35. HANDLE PMMutex;
  36. #endif
  37. extern HANDLE WmipWin32Event;
  38. HMODULE WmipDllHandle;
  39. void WmipDeinitializeDll(
  40. void
  41. );
  42. void WmipDeinitializeAccess(
  43. PTCHAR *RpcStringBinding
  44. );
  45. ULONG WmipInitializeDll(
  46. void
  47. );
  48. HINSTANCE DllInstanceHandle;
  49. extern HANDLE WmipKMHandle;
  50. /*
  51. BOOLEAN
  52. WmiDllInitialize(
  53. IN PVOID DllBase,
  54. IN ULONG Reason,
  55. IN PCONTEXT Context OPTIONAL
  56. )
  57. /*++
  58. Routine Description:
  59. This function implements Win32 base dll initialization.
  60. Arguments:
  61. DllHandle -
  62. Reason - attach\detach
  63. Context - Not Used
  64. Return Value:
  65. STATUS_SUCCESS
  66. --*//*
  67. {
  68. ULONG Status = ERROR_SUCCESS;
  69. ULONG Foo;
  70. DllInstanceHandle = (HINSTANCE)DllBase;
  71. if (Reason == DLL_PROCESS_ATTACH)
  72. {
  73. #if DBG
  74. Foo = WmipLoggingEnabled ? 1 : 0;
  75. WmipGetRegistryValue(LoggingEnableValueText,
  76. &Foo);
  77. WmipLoggingEnabled = (Foo == 0) ? FALSE : TRUE;
  78. #endif
  79. Status = WmipInitializeDll();
  80. } else if (Reason == DLL_PROCESS_DETACH) {
  81. #ifndef MEMPHIS
  82. // Flush out UM buffers to logfile
  83. //
  84. #if 0
  85. WmipFlushUmLoggerBuffer();
  86. #endif
  87. #endif
  88. //
  89. // DOn't need to clean up if process is exiting
  90. if (Context == NULL)
  91. {
  92. WmipDeinitializeDll();
  93. }
  94. if (WmipKMHandle != (HANDLE)NULL)
  95. {
  96. WmipCloseHandle(WmipKMHandle);
  97. }
  98. }
  99. return(Status == ERROR_SUCCESS);
  100. }*/
  101. ULONG WmipInitializeDll(
  102. void
  103. )
  104. /*+++
  105. Routine Description:
  106. Arguments:
  107. Return Value:
  108. ---*/
  109. {
  110. #ifdef MEMPHIS
  111. PMMutex = CreateMutex(NULL, FALSE, NULL);
  112. if (PMMutex == NULL)
  113. {
  114. return(WmipGetLastError());
  115. }
  116. #else
  117. ULONG Status;
  118. Status = RtlInitializeCriticalSection(&PMCritSect);
  119. if (! NT_SUCCESS(Status))
  120. {
  121. return(RtlNtStatusToDosError(Status));
  122. }
  123. Status = RtlInitializeCriticalSection(&UMLogCritSect);
  124. if (! NT_SUCCESS(Status))
  125. {
  126. RtlDeleteCriticalSection(&PMCritSect); // Delete PMCritSec.
  127. return(RtlNtStatusToDosError(Status));
  128. }
  129. EtwLocksInitialized = TRUE;
  130. #endif
  131. return(ERROR_SUCCESS);
  132. }
  133. #ifndef MEMPHIS
  134. VOID
  135. WmipCreateHeap(
  136. void
  137. )
  138. {
  139. WmipEnterPMCritSection();
  140. if (WmipProcessHeap == NULL)
  141. {
  142. WmipProcessHeap = RtlCreateHeap(HEAP_GROWABLE,
  143. NULL,
  144. DLLRESERVEDHEAPSIZE,
  145. DLLCOMMITHEAPSIZE,
  146. NULL,
  147. NULL);
  148. if (WmipProcessHeap == NULL)
  149. {
  150. WmipDebugPrint(("WMI: Cannot create WmipProcessHeap, using process default\n"));
  151. WmipProcessHeap = RtlProcessHeap();
  152. }
  153. }
  154. WmipLeavePMCritSection();
  155. }
  156. #endif
  157. void WmipDeinitializeDll(
  158. void
  159. )
  160. /*+++
  161. Routine Description:
  162. Arguments:
  163. Return Value:
  164. ---*/
  165. {
  166. #ifdef MEMPHIS
  167. WmipCloseHandle(PMMutex);
  168. #else
  169. if(EtwLocksInitialized){
  170. RtlDeleteCriticalSection(&PMCritSect);
  171. RtlDeleteCriticalSection(&UMLogCritSect);
  172. }
  173. if ((WmipProcessHeap != NULL) &&
  174. (WmipProcessHeap != RtlProcessHeap()))
  175. {
  176. RtlDestroyHeap(WmipProcessHeap);
  177. }
  178. if (WmipDeviceHandle != NULL)
  179. {
  180. WmipCloseHandle(WmipDeviceHandle);
  181. }
  182. #endif
  183. if (WmipWin32Event != NULL)
  184. {
  185. WmipCloseHandle(WmipWin32Event);
  186. }
  187. }
  188. /*
  189. #if DBG
  190. void WmipGetRegistryValue(
  191. TCHAR *ValueName,
  192. PULONG Value
  193. )
  194. {
  195. HKEY Key;
  196. DWORD Type;
  197. DWORD ValueSize;
  198. ULONG Status;
  199. Status = RegOpenKey(HKEY_LOCAL_MACHINE,
  200. WmiRegKeyText,
  201. &Key);
  202. if (Status == ERROR_SUCCESS)
  203. {
  204. ValueSize = sizeof(ULONG);
  205. Status = RegQueryValueEx(Key,
  206. ValueName,
  207. NULL,
  208. &Type,
  209. (LPBYTE)Value,
  210. &ValueSize);
  211. if ((Status == ERROR_SUCCESS) &&
  212. (Type == REG_DWORD))
  213. {
  214. WmipDebugPrint(("WMI: %ws from registry is %d\n",
  215. ValueName,
  216. *Value));
  217. }
  218. RegCloseKey(Key);
  219. }
  220. }
  221. #endif
  222. */