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.

257 lines
4.3 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. #ifndef MEMPHIS
  16. RTL_CRITICAL_SECTION PMCritSect;
  17. PVOID WmipProcessHeap;
  18. HANDLE WmipDeviceHandle;
  19. #else
  20. HANDLE PMMutex;
  21. #endif
  22. extern HANDLE WmipWin32Event;
  23. HMODULE WmipDllHandle;
  24. void WmipDeinitializeDll(
  25. void
  26. );
  27. void WmipDeinitializeAccess(
  28. PTCHAR *RpcStringBinding
  29. );
  30. ULONG WmipInitializeDll(
  31. void
  32. );
  33. HINSTANCE DllInstanceHandle;
  34. extern HANDLE WmipKMHandle;
  35. BOOLEAN
  36. WmiDllInitialize(
  37. IN PVOID DllBase,
  38. IN ULONG Reason,
  39. IN PCONTEXT Context OPTIONAL
  40. )
  41. /*++
  42. Routine Description:
  43. This function implements Win32 base dll initialization.
  44. Arguments:
  45. DllHandle -
  46. Reason - attach\detach
  47. Context - Not Used
  48. Return Value:
  49. STATUS_SUCCESS
  50. --*/
  51. {
  52. ULONG Status = ERROR_SUCCESS;
  53. ULONG Foo;
  54. DllInstanceHandle = (HINSTANCE)DllBase;
  55. if (Reason == DLL_PROCESS_ATTACH)
  56. {
  57. #if DBG
  58. Foo = WmipLoggingEnabled ? 1 : 0;
  59. WmipGetRegistryValue(LoggingEnableValueText,
  60. &Foo);
  61. WmipLoggingEnabled = (Foo == 0) ? FALSE : TRUE;
  62. #endif
  63. Status = WmipInitializeDll();
  64. } else if (Reason == DLL_PROCESS_DETACH) {
  65. #ifndef MEMPHIS
  66. // Flush out UM buffers to logfile
  67. //
  68. #if 0
  69. WmipFlushUmLoggerBuffer();
  70. #endif
  71. #endif
  72. //
  73. // DOn't need to clean up if process is exiting
  74. if (Context == NULL)
  75. {
  76. WmipDeinitializeDll();
  77. }
  78. if (WmipKMHandle != (HANDLE)NULL)
  79. {
  80. CloseHandle(WmipKMHandle);
  81. }
  82. }
  83. return(Status == ERROR_SUCCESS);
  84. }
  85. ULONG WmipInitializeDll(
  86. void
  87. )
  88. /*+++
  89. Routine Description:
  90. Arguments:
  91. Return Value:
  92. ---*/
  93. {
  94. #ifdef MEMPHIS
  95. PMMutex = CreateMutex(NULL, FALSE, NULL);
  96. if (PMMutex == NULL)
  97. {
  98. return(GetLastError());
  99. }
  100. #else
  101. ULONG Status;
  102. Status = RtlInitializeCriticalSection(&PMCritSect);
  103. if (! NT_SUCCESS(Status))
  104. {
  105. return(RtlNtStatusToDosError(Status));
  106. }
  107. #endif
  108. return(ERROR_SUCCESS);
  109. }
  110. #ifndef MEMPHIS
  111. VOID
  112. WmipCreateHeap(
  113. void
  114. )
  115. {
  116. WmipEnterPMCritSection();
  117. if (WmipProcessHeap == NULL)
  118. {
  119. WmipProcessHeap = RtlCreateHeap(HEAP_GROWABLE,
  120. NULL,
  121. DLLRESERVEDHEAPSIZE,
  122. DLLCOMMITHEAPSIZE,
  123. NULL,
  124. NULL);
  125. if (WmipProcessHeap == NULL)
  126. {
  127. WmipDebugPrint(("WMI: Cannot create WmipProcessHeap, using process default\n"));
  128. WmipProcessHeap = RtlProcessHeap();
  129. }
  130. }
  131. WmipLeavePMCritSection();
  132. }
  133. #endif
  134. void WmipDeinitializeDll(
  135. void
  136. )
  137. /*+++
  138. Routine Description:
  139. Arguments:
  140. Return Value:
  141. ---*/
  142. {
  143. #ifdef MEMPHIS
  144. CloseHandle(PMMutex);
  145. #else
  146. RtlDeleteCriticalSection(&PMCritSect);
  147. if ((WmipProcessHeap != NULL) &&
  148. (WmipProcessHeap != RtlProcessHeap()))
  149. {
  150. RtlDestroyHeap(WmipProcessHeap);
  151. }
  152. if (WmipDeviceHandle != NULL)
  153. {
  154. CloseHandle(WmipDeviceHandle);
  155. }
  156. #endif
  157. if (WmipWin32Event != NULL)
  158. {
  159. CloseHandle(WmipWin32Event);
  160. }
  161. }
  162. #if DBG
  163. void WmipGetRegistryValue(
  164. TCHAR *ValueName,
  165. PULONG Value
  166. )
  167. {
  168. HKEY Key;
  169. DWORD Type;
  170. DWORD ValueSize;
  171. ULONG Status;
  172. Status = RegOpenKey(HKEY_LOCAL_MACHINE,
  173. WmiRegKeyText,
  174. &Key);
  175. if (Status == ERROR_SUCCESS)
  176. {
  177. ValueSize = sizeof(ULONG);
  178. Status = RegQueryValueEx(Key,
  179. ValueName,
  180. NULL,
  181. &Type,
  182. (LPBYTE)Value,
  183. &ValueSize);
  184. if ((Status == ERROR_SUCCESS) &&
  185. (Type == REG_DWORD))
  186. {
  187. WmipDebugPrint(("WMI: %ws from registry is %d\n",
  188. ValueName,
  189. *Value));
  190. }
  191. RegCloseKey(Key);
  192. }
  193. }
  194. #endif