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.

235 lines
5.5 KiB

  1. // DllMain
  2. #include "precomp.hxx"
  3. #define DLL_IMPLEMENTATION
  4. #define IMPLEMENTATION_EXPORT
  5. #include <irtldbg.h>
  6. #include <lkrhash.h>
  7. #include <inetinfo.h>
  8. #include "sched.hxx"
  9. #include "date.hxx"
  10. #include "alloc.h"
  11. #undef SMALL_BLOCK_HEAP
  12. #ifdef SMALL_BLOCK_HEAP
  13. # include <malloc.h>
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // Globals
  17. #ifndef _NO_TRACING_
  18. #include <initguid.h>
  19. #ifndef _EXEXPRESS
  20. DEFINE_GUID(IisRtlGuid,
  21. 0x784d8900, 0xaa8c, 0x11d2, 0x92, 0x5e, 0x00, 0xc0, 0x4f, 0x72, 0xd9, 0x0e);
  22. #else
  23. DEFINE_GUID(IisKRtlGuid,
  24. 0x784d8912, 0xaa8c, 0x11d2, 0x92, 0x5e, 0x00, 0xc0, 0x4f, 0x72, 0xd9, 0x0e);
  25. #endif
  26. // NOTE: It is very important to remember that anything that needs to be
  27. // initialized here also needs to be initialized in the main of iisrtl2!!!
  28. extern "C" CRITICAL_SECTION g_csGuidList;
  29. extern "C" LIST_ENTRY g_pGuidList;
  30. extern "C" DWORD g_dwSequenceNumber;
  31. #else // _NO_TRACING
  32. DECLARE_DEBUG_VARIABLE();
  33. #endif // _NO_TRACING
  34. DECLARE_DEBUG_PRINTS_OBJECT();
  35. DECLARE_PLATFORM_TYPE();
  36. // HKLM\System\CurrentControlSet\Services\InetInfo\IISRTL\DebugFlags
  37. const CHAR g_pszIisRtlRegLocation[] =
  38. INET_INFO_PARAMETERS_KEY TEXT("\\IISRTL");
  39. #undef ALWAYS_CLEANUP
  40. /////////////////////////////////////////////////////////////////////////////
  41. // Additional initialization needed. The shutdown of the scheduler threads
  42. // in DLLMain has caused us some considerable grief.
  43. int g_cRefs;
  44. CRITICAL_SECTION g_csInit;
  45. BOOL
  46. WINAPI
  47. InitializeIISRTL()
  48. {
  49. BOOL fReturn = TRUE; // ok
  50. EnterCriticalSection(&g_csInit);
  51. IF_DEBUG(INIT_CLEAN)
  52. DBGPRINTF((DBG_CONTEXT, "InitializeIISRTL, %d %s\n",
  53. g_cRefs, (g_cRefs == 0 ? "initializing" : "")));
  54. if (g_cRefs++ == 0)
  55. {
  56. if (SchedulerInitialize())
  57. {
  58. DBG_REQUIRE(ALLOC_CACHE_HANDLER::SetLookasideCleanupInterval());
  59. IF_DEBUG(INIT_CLEAN)
  60. DBGPRINTF((DBG_CONTEXT, "Scheduler Initialized\n"));
  61. }
  62. else
  63. {
  64. DBGPRINTF((DBG_CONTEXT, "Initializing Scheduler Failed\n"));
  65. fReturn = FALSE;
  66. }
  67. }
  68. LeaveCriticalSection(&g_csInit);
  69. return fReturn;
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // Additional termination needed
  73. void
  74. WINAPI
  75. TerminateIISRTL()
  76. {
  77. EnterCriticalSection(&g_csInit);
  78. IF_DEBUG(INIT_CLEAN)
  79. DBGPRINTF((DBG_CONTEXT, "TerminateIISRTL, %d %s\n",
  80. g_cRefs, (g_cRefs == 1 ? "Uninitializing" : "")));
  81. if (--g_cRefs == 0)
  82. {
  83. DBG_REQUIRE(ALLOC_CACHE_HANDLER::ResetLookasideCleanupInterval());
  84. SchedulerTerminate();
  85. }
  86. LeaveCriticalSection(&g_csInit);
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. // DLL Entry Point
  90. // Note: any changes here probably also need to go into ..\iisrtl2\main.cxx
  91. extern "C"
  92. BOOL WINAPI
  93. DllMain(
  94. HINSTANCE hInstance,
  95. DWORD dwReason,
  96. LPVOID lpvReserved)
  97. {
  98. BOOL fReturn = TRUE; // ok
  99. if (dwReason == DLL_PROCESS_ATTACH)
  100. {
  101. DisableThreadLibraryCalls(hInstance);
  102. #ifdef SMALL_BLOCK_HEAP
  103. // _set_sbh_threshold(480); // VC5
  104. _set_sbh_threshold(1016); // VC6
  105. #endif
  106. g_cRefs = 0;
  107. INITIALIZE_CRITICAL_SECTION(&g_csInit);
  108. IisHeapInitialize();
  109. InitializeStringFunctions();
  110. IRTL_DEBUG_INIT();
  111. #ifdef _NO_TRACING_
  112. CREATE_DEBUG_PRINT_OBJECT("iisrtl");
  113. #else
  114. // These initializations MUST always be before the CREATE_DEBUG_PRINT_OBJECT
  115. InitializeListHead(&g_pGuidList);
  116. InitializeCriticalSection(&g_csGuidList);
  117. #ifndef _EXEXPRESS
  118. CREATE_DEBUG_PRINT_OBJECT("iisrtl", IisRtlGuid);
  119. #else
  120. CREATE_DEBUG_PRINT_OBJECT("kisrtl", IisKRtlGuid);
  121. #endif
  122. #endif
  123. if (!VALID_DEBUG_PRINT_OBJECT()) {
  124. return (FALSE);
  125. }
  126. #ifdef _NO_TRACING_
  127. LOAD_DEBUG_FLAGS_FROM_REG_STR( g_pszIisRtlRegLocation, DEBUG_ERROR );
  128. #endif
  129. IF_DEBUG(INIT_CLEAN)
  130. DBGPRINTF((DBG_CONTEXT, "IISRTL::DllMain::DLL_PROCESS_ATTACH\n"));
  131. //
  132. // Initialize the platform type
  133. //
  134. INITIALIZE_PLATFORM_TYPE();
  135. IRTLASSERT(IISIsValidPlatform());
  136. InitializeSecondsTimer();
  137. InitializeDateTime();
  138. DBG_REQUIRE(ALLOC_CACHE_HANDLER::Initialize());
  139. IF_DEBUG(INIT_CLEAN) {
  140. DBGPRINTF((DBG_CONTEXT, "Alloc Cache initialized\n"));
  141. }
  142. fReturn = LKRHashTableInit();
  143. }
  144. else if (dwReason == DLL_PROCESS_DETACH)
  145. {
  146. #ifndef ALWAYS_CLEANUP
  147. if (lpvReserved == NULL)
  148. #endif
  149. {
  150. //
  151. // Only Cleanup if there is a FreeLibrary() call.
  152. //
  153. IF_DEBUG(INIT_CLEAN)
  154. DBGPRINTF((DBG_CONTEXT,
  155. "IISRTL::DllMain::DLL_PROCESS_DETACH\n"));
  156. if (g_cRefs != 0)
  157. DBGPRINTF((DBG_CONTEXT, "iisrtl!g_cRefs = %d\n", g_cRefs));
  158. LKRHashTableUninit();
  159. DBG_REQUIRE(ALLOC_CACHE_HANDLER::Cleanup());
  160. TerminateDateTime();
  161. TerminateSecondsTimer();
  162. DELETE_DEBUG_PRINT_OBJECT();
  163. #ifndef _NO_TRACING_
  164. // This delete MUST always be after the DELETE_DEBUG_PRINT_OBJECT
  165. DeleteCriticalSection(&g_csGuidList);
  166. #endif
  167. IRTL_DEBUG_TERM();
  168. IisHeapTerminate();
  169. DeleteCriticalSection(&g_csInit);
  170. }
  171. }
  172. return fReturn;
  173. }