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.

172 lines
5.0 KiB

  1. // --------------------------------------------------------------------------------
  2. // Dllmain.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #include "pch.hxx"
  7. #include <shfusion.h>
  8. #ifndef MAC
  9. #define DEFINE_STRCONST
  10. #include "dllmain.h"
  11. #include "demand.h"
  12. #include "strconst.h"
  13. #include "oertpriv.h"
  14. #include <BadStrFunctions.h>
  15. // --------------------------------------------------------------------------------
  16. // Globals - Object count and lock count
  17. // --------------------------------------------------------------------------------
  18. HINSTANCE g_hInst=NULL;
  19. IMalloc *g_pMalloc=NULL;
  20. CRITICAL_SECTION g_csTempFileList={0};
  21. LPTEMPFILEINFO g_pTempFileHead=NULL;
  22. DWORD g_dwTlsMsgBuffIndex=0xffffffff;
  23. OSVERSIONINFO g_rOSVersionInfo ={0};
  24. // --------------------------------------------------------------------------------
  25. // Debug Globals
  26. // --------------------------------------------------------------------------------
  27. #ifdef DEBUG
  28. DWORD dwDOUTLevel=0;
  29. DWORD dwDOUTLMod=0;
  30. DWORD dwDOUTLModLevel=0;
  31. #endif
  32. #ifndef WIN16
  33. // --------------------------------------------------------------------------------
  34. // GetDllMajorVersion
  35. // --------------------------------------------------------------------------------
  36. OEDLLVERSION WINAPI GetDllMajorVersion(void)
  37. {
  38. return OEDLL_VERSION_CURRENT;
  39. }
  40. // --------------------------------------------------------------------------------
  41. // Dll Entry Point
  42. // --------------------------------------------------------------------------------
  43. EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved)
  44. {
  45. // Handle Attach - detach reason
  46. if (DLL_PROCESS_ATTACH == dwReason)
  47. {
  48. SHFusionInitialize(NULL);
  49. // Save the Instance Handle
  50. g_hInst = hInst;
  51. // Create the task allocator
  52. CoGetMalloc(1, &g_pMalloc);
  53. // Critical Section for the tempfile list
  54. InitializeCriticalSection(&g_csTempFileList);
  55. // Initialize Demand Loaded libs
  56. InitDemandLoadedLibs();
  57. // Allocate a TLS index
  58. g_dwTlsMsgBuffIndex = TlsAlloc();
  59. Assert(g_dwTlsMsgBuffIndex != 0xffffffff);
  60. // Allocate a buffer and store it into the tls index
  61. ThreadAllocateTlsMsgBuffer();
  62. g_rOSVersionInfo.dwOSVersionInfoSize = sizeof(g_rOSVersionInfo);
  63. GetVersionEx(&g_rOSVersionInfo);
  64. // Initialize Debug Stuff
  65. #ifdef DEBUG
  66. dwDOUTLevel=GetPrivateProfileInt("Debug", "ICLevel", 0, "athena.ini");
  67. dwDOUTLMod=GetPrivateProfileInt("Debug", "Mod", 0, "athena.ini");
  68. dwDOUTLModLevel=GetPrivateProfileInt("Debug", "ModLevel", 0, "athena.ini");
  69. #endif
  70. }
  71. // Thread Attach
  72. else if (DLL_THREAD_ATTACH == dwReason)
  73. {
  74. // Allocate a buffer and store it into the tls index
  75. ThreadAllocateTlsMsgBuffer();
  76. }
  77. // Thread Dettach
  78. else if (DLL_THREAD_DETACH == dwReason)
  79. {
  80. // Allocate a buffer and store it into the tls index
  81. ThreadFreeTlsMsgBuffer();
  82. }
  83. // Process Detach
  84. else if (DLL_PROCESS_DETACH == dwReason)
  85. {
  86. // Allocate a buffer and store it into the tls index
  87. ThreadFreeTlsMsgBuffer();
  88. // Free the tls index
  89. TlsFree(g_dwTlsMsgBuffIndex);
  90. g_dwTlsMsgBuffIndex = 0xffffffff;
  91. // Cleanup Global Temp Files
  92. CleanupGlobalTempFiles();
  93. // Kill the temp file list critical Section
  94. DeleteCriticalSection(&g_csTempFileList);
  95. // Free demand loaded libs
  96. FreeDemandLoadedLibs();
  97. // Release task allocator
  98. SafeRelease(g_pMalloc);
  99. SHFusionUninitialize();
  100. }
  101. // Done
  102. return TRUE;
  103. }
  104. #else //WIN16
  105. BOOL FAR PASCAL LibMain( HINSTANCE hDll, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine )
  106. {
  107. g_hInst = hDll;
  108. OleInitialize( NULL );
  109. CoGetMalloc( 1, &g_pMalloc );
  110. InitDemandLoadedLibs();
  111. #ifdef DEBUG
  112. dwDOUTLevel=GetPrivateProfileInt("Debug", "ICLevel", 0, "athena.ini");
  113. dwDOUTLMod=GetPrivateProfileInt("Debug", "Mod", 0, "athena.ini");
  114. dwDOUTLModLevel=GetPrivateProfileInt("Debug", "ModLevel", 0, "athena.ini");
  115. #endif
  116. return( TRUE );
  117. }
  118. int CALLBACK WEP( int nExitType )
  119. {
  120. BOOL fDSExist = FALSE;
  121. // Following ASM code is to check if DS has been loaded properly
  122. // This is because WEP can be called even before DS is initialized in
  123. // some low memory situation.
  124. _asm {
  125. push bx
  126. push cx
  127. mov cx, ds
  128. lar bx, cx
  129. jnz wrong
  130. test bx, 8000h
  131. jz wrong
  132. mov fDSExist, ax
  133. wrong: pop cx
  134. pop bx
  135. }
  136. if ( fDSExist )
  137. {
  138. SafeRelease( g_pMalloc );
  139. }
  140. return( TRUE );
  141. }
  142. #endif //WIN16
  143. #endif // !MAC