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.

273 lines
5.4 KiB

  1. /*
  2. * dllinit.c - Initialization and termination routines.
  3. */
  4. /*
  5. Implementation Notes
  6. --------------------
  7. Here are a few conventions I have attempted to follow in the object
  8. synchronization engine:
  9. 1) Functions have only one exit point.
  10. 2) When calling a function that takes one or more pointers to variables to be
  11. filled in with a result, the caller may only depend upon the variables being
  12. filled in correctly if the function returns success.
  13. 3) AllocateMemory() and FreeMemory() are called instead of _fmalloc() and
  14. _ffree() to allow debug manipulation of the heap.
  15. 4) Two layers of parameter validation have been implemented - validation of
  16. parameters passed in from external callers and validation of parameters passed
  17. in from internal callers. #defining EXPV enables the external parameter
  18. validation layer. The internal parameter validation layer is only included in
  19. the debug build. The external parameter validation layer fails any call with
  20. an invalid parameter, returning TR_INVALID_PARAMETER. The internal parameter
  21. validation layer displays a debug message when a call is made with an invalid
  22. parameter, but allows the call to proceed. External parameter validation is
  23. available in all builds. Internal parameter validation is only available in
  24. the DEBUG build.
  25. 5) In addition to the two layers of parameter validation, validation of fields
  26. of structures passed as arguments may be enabled by #defining VSTF. Full
  27. parent and child structure field validation can be quite time-consuming. Field
  28. validation for external structure parameters is available in all builds. Field
  29. validation for internal structure parameters is only available in the DEBUG
  30. build. (Full parameter and structure field validation has proven very valuable
  31. in debugging.)
  32. 6) Some debug bounds check ASSERT()s use floating point math. These floating
  33. point bounds checks are only enabled if DBLCHECK is #defined. Defining
  34. DBLCHECK requires linking with the CRT library for floating point support.
  35. */
  36. /* Headers
  37. **********/
  38. #include "project.h"
  39. #pragma hdrstop
  40. #include "init.h"
  41. /* Module Prototypes
  42. ********************/
  43. PRIVATE_CODE BOOL MyAttachProcess(HMODULE);
  44. PRIVATE_CODE BOOL MyDetachProcess(HMODULE);
  45. /* Global Variables
  46. *******************/
  47. /* serialization control structure */
  48. PUBLIC_DATA CSERIALCONTROL g_cserctrl =
  49. {
  50. MyAttachProcess,
  51. MyDetachProcess,
  52. NULL,
  53. NULL
  54. };
  55. #ifdef DEBUG
  56. /* .ini file name and section used by inifile.c!SetIniSwitches() */
  57. PUBLIC_DATA LPCTSTR GpcszIniFile = TEXT("rover.ini");
  58. PUBLIC_DATA LPCTSTR GpcszIniSection = TEXT("SyncEngineDebugOptions");
  59. /* module name used by debug.c!SpewOut() */
  60. PUBLIC_DATA LPCTSTR GpcszSpewModule = TEXT("SyncEng");
  61. #endif
  62. /***************************** Private Functions *****************************/
  63. #pragma warning(disable:4100) /* "unreferenced formal parameter" warning */
  64. /*
  65. ** MyAttachProcess()
  66. **
  67. **
  68. **
  69. ** Arguments:
  70. **
  71. ** Returns:
  72. **
  73. ** Side Effects: none
  74. */
  75. PRIVATE_CODE BOOL MyAttachProcess(HMODULE hmod)
  76. {
  77. BOOL bResult;
  78. ASSERT(IS_VALID_HANDLE(hmod, MODULE));
  79. DebugEntry(MyAttachProcess);
  80. bResult = (ProcessInitOLEPigModule() &&
  81. ProcessInitStorageModule());
  82. DebugExitBOOL(MyAttachProcess, bResult);
  83. return(bResult);
  84. }
  85. /*
  86. ** MyDetachProcess()
  87. **
  88. **
  89. **
  90. ** Arguments:
  91. **
  92. ** Returns:
  93. **
  94. ** Side Effects: none
  95. */
  96. PRIVATE_CODE BOOL MyDetachProcess(HMODULE hmod)
  97. {
  98. BOOL bResult = TRUE;
  99. ASSERT(IS_VALID_HANDLE(hmod, MODULE));
  100. DebugEntry(MyDetachProcess);
  101. ProcessExitStorageModule();
  102. ProcessExitOLEPigModule();
  103. DebugExitBOOL(MyDetachProcess, bResult);
  104. return(bResult);
  105. }
  106. #pragma warning(default:4100) /* "unreferenced formal parameter" warning */
  107. /****************************** Public Functions *****************************/
  108. #ifdef DEBUG
  109. /*
  110. ** SetAllIniSwitches()
  111. **
  112. **
  113. **
  114. ** Arguments:
  115. **
  116. ** Returns:
  117. **
  118. ** Side Effects: none
  119. */
  120. PUBLIC_CODE BOOL SetAllIniSwitches(void)
  121. {
  122. BOOL bResult;
  123. bResult = SetDebugModuleIniSwitches();
  124. bResult = SetSerialModuleIniSwitches() && bResult;
  125. bResult = SetMemoryManagerModuleIniSwitches() && bResult;
  126. bResult = SetBriefcaseModuleIniSwitches() && bResult;
  127. return(bResult);
  128. }
  129. #endif
  130. /*
  131. ** InitializeDLL()
  132. **
  133. **
  134. **
  135. ** Arguments:
  136. **
  137. ** Returns:
  138. **
  139. ** Side Effects: none
  140. */
  141. PUBLIC_CODE BOOL InitializeDLL(void)
  142. {
  143. BOOL bResult;
  144. #ifdef DEBUG
  145. DebugEntry(InitializeDLL);
  146. EVAL(InitDebugModule());
  147. #endif
  148. bResult = (InitMemoryManagerModule() &&
  149. InitBriefcaseModule());
  150. #ifdef DEBUG
  151. if (bResult)
  152. {
  153. SpewHeapSummary(0);
  154. }
  155. #endif
  156. DebugExitBOOL(InitializeDLL, bResult);
  157. return(bResult);
  158. }
  159. /*
  160. ** TerminateDLL()
  161. **
  162. **
  163. **
  164. ** Arguments:
  165. **
  166. ** Returns: TRUE
  167. **
  168. ** Side Effects: none
  169. */
  170. PUBLIC_CODE BOOL TerminateDLL(void)
  171. {
  172. BOOL bResult = TRUE;
  173. DebugEntry(TerminateDLL);
  174. #ifdef DEBUG
  175. SpewHeapSummary(0);
  176. TRACE_OUT((TEXT("TerminateDLL(): Starting heap cleanup.")));
  177. #endif
  178. ExitBriefcaseModule();
  179. #ifdef DEBUG
  180. TRACE_OUT((TEXT("TerminateDLL(): Heap cleanup complete.")));
  181. SpewHeapSummary(SHS_FL_SPEW_USED_INFO);
  182. #endif
  183. ExitMemoryManagerModule();
  184. #ifdef DEBUG
  185. ExitDebugModule();
  186. #endif
  187. DebugExitBOOL(TerminateDLL, bResult);
  188. return(bResult);
  189. }