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.

296 lines
5.4 KiB

  1. /*++
  2. Copyright 1997 - 98, Microsoft Corporation
  3. Module Name:
  4. qosmmain.c
  5. Abstract:
  6. Contains routines that are invoked when
  7. the QosMgr DLL is loaded or unloaded.
  8. Revision History:
  9. --*/
  10. #include "pchqosm.h"
  11. #pragma hdrstop
  12. // All Global variables
  13. QOSMGR_GLOBALS Globals;
  14. BOOL
  15. WINAPI
  16. DllMain(
  17. IN HINSTANCE Instance,
  18. IN DWORD Reason,
  19. IN PVOID Unused
  20. )
  21. /*++
  22. Routine Description:
  23. This is the DLL's main entrypoint handler which
  24. initializes the Qos Mgr component.
  25. Arguments:
  26. None
  27. Return Value:
  28. TRUE if successful, FALSE if not
  29. --*/
  30. {
  31. static BOOL QosmInitialized = FALSE;
  32. UNREFERENCED_PARAMETER(Unused);
  33. switch(Reason)
  34. {
  35. case DLL_PROCESS_ATTACH:
  36. DisableThreadLibraryCalls(Instance);
  37. //
  38. // Initialize the Qos Mgr Component
  39. //
  40. QosmInitialized = QosmDllStartup();
  41. return QosmInitialized;
  42. case DLL_PROCESS_DETACH:
  43. //
  44. // Cleanup the Qos Mgr Component
  45. //
  46. if (QosmInitialized)
  47. {
  48. QosmDllCleanup();
  49. }
  50. }
  51. return TRUE;
  52. }
  53. BOOL
  54. QosmDllStartup(
  55. VOID
  56. )
  57. /*++
  58. Routine Description:
  59. Initializes all global data structures in Qos Mgr.
  60. Called by DLL Main when the process is attached.
  61. Arguments:
  62. None
  63. Return Value:
  64. TRUE if successful, FALSE if not
  65. --*/
  66. {
  67. TCI_CLIENT_FUNC_LIST TcHandlers;
  68. BOOL ListLockInited;
  69. DWORD Status;
  70. UINT i;
  71. ListLockInited = FALSE;
  72. do
  73. {
  74. ZeroMemory(&Globals, sizeof(QOSMGR_GLOBALS));
  75. // Globals.State = IPQOSMRG_STATE_STOPPED;
  76. //
  77. // Enable logging and tracing for debugging purposes
  78. //
  79. START_TRACING();
  80. START_LOGGING();
  81. #if DBG_TRACE
  82. Globals.TracingFlags = QOSM_TRACE_ANY;
  83. #endif
  84. //
  85. // Create a private heap for Qos Mgr's use
  86. //
  87. Globals.GlobalHeap = HeapCreate(0, 0, 0);
  88. if (Globals.GlobalHeap == NULL)
  89. {
  90. Status = GetLastError();
  91. Trace1(ANY,
  92. "QosmDllStartup: Failed to create a global private heap %x",
  93. Status);
  94. LOGERR0(HEAP_CREATE_FAILED, Status);
  95. break;
  96. }
  97. //
  98. // Initialize lock to guard global list of interfaces
  99. //
  100. try
  101. {
  102. CREATE_READ_WRITE_LOCK(&Globals.GlobalsLock);
  103. ListLockInited = TRUE;
  104. }
  105. except(EXCEPTION_EXECUTE_HANDLER)
  106. {
  107. Status = GetLastError();
  108. Trace1(ANY,
  109. "QosmDllStartup : Failed to create read/write lock %x",
  110. Status);
  111. LOGERR0(CREATE_RWL_FAILED, Status);
  112. break;
  113. }
  114. //
  115. // Initialize global list and table of active interfaces
  116. //
  117. Globals.NumIfs = 0;
  118. InitializeListHead(&Globals.IfList);
  119. //
  120. // Register with the traffic control API to control QOS
  121. //
  122. ZeroMemory(&TcHandlers, sizeof(TCI_CLIENT_FUNC_LIST));
  123. TcHandlers.ClNotifyHandler = TcNotifyHandler;
  124. Status = TcRegisterClient(CURRENT_TCI_VERSION,
  125. NULL,
  126. &TcHandlers,
  127. &Globals.TciHandle);
  128. if (Status != NO_ERROR)
  129. {
  130. Trace1(ANY,
  131. "QosmDllStartup: Failed to register with the TC API %x",
  132. Status);
  133. LOGERR0(TC_REGISTER_FAILED, Status);
  134. break;
  135. }
  136. Globals.State = IPQOSMGR_STATE_STARTING;
  137. return TRUE;
  138. }
  139. while (FALSE);
  140. //
  141. // Some error occured - clean up and return the error code
  142. //
  143. if (ListLockInited)
  144. {
  145. DELETE_READ_WRITE_LOCK(&Globals.GlobalsLock);
  146. }
  147. if (Globals.GlobalHeap != NULL)
  148. {
  149. HeapDestroy(Globals.GlobalHeap);
  150. }
  151. STOP_LOGGING();
  152. STOP_TRACING();
  153. return FALSE;
  154. }
  155. BOOL
  156. QosmDllCleanup(
  157. VOID
  158. )
  159. /*++
  160. Routine Description:
  161. Cleans up all global data structures at unload time.
  162. Arguments:
  163. None
  164. Return Value:
  165. TRUE if successful, FALSE if not
  166. --*/
  167. {
  168. DWORD Status;
  169. // We should have freed all ifs to avoid any leaks
  170. ASSERT(Globals.NumIfs == 0);
  171. //
  172. // Cleanup and deregister with traffic control API
  173. //
  174. Status = TcDeregisterClient(Globals.TciHandle);
  175. if (Status != NO_ERROR)
  176. {
  177. Trace1(ANY,
  178. "QosmDllCleanup: Failed to deregister with the TC API %x",
  179. Status);
  180. LOGERR0(TC_DEREGISTER_FAILED, Status);
  181. }
  182. //
  183. // Free resources allocated like locks and memory
  184. //
  185. DELETE_READ_WRITE_LOCK(&Globals.GlobalsLock);
  186. //
  187. // Cleanup the heap and memory allocated in it
  188. //
  189. HeapDestroy(Globals.GlobalHeap);
  190. //
  191. // Stop debugging aids like tracing and logging
  192. //
  193. STOP_LOGGING();
  194. STOP_TRACING();
  195. return TRUE;
  196. }