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.

145 lines
3.2 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. DWORD g_TraceId = INVALID_TRACEID;
  4. HANDLE g_LogHandle = NULL;
  5. DWORD g_dwLoggingLevel = 0;
  6. HANDLE g_Heap = INVALID_HANDLE_VALUE;
  7. HANDLE g_Lock = INVALID_HANDLE_VALUE;
  8. //------------------------------------------------------------------------------
  9. // _DllStartup
  10. //
  11. // Creates a private heap,
  12. // and creates the global critical section.
  13. //
  14. // Note: no structures must be allocated from heap here, as StartProtocol()
  15. // if called after StopProtocol() destroys the heap.
  16. // Return Values: TRUE (if no error), else FALSE.
  17. //------------------------------------------------------------------------------
  18. BOOL
  19. DllStartup(
  20. )
  21. {
  22. // create a private heap
  23. g_Heap = HeapCreate(0, 0, 0);
  24. if (g_Heap == NULL) {
  25. goto Error;
  26. }
  27. g_Lock = CreateMutex(NULL, FALSE, L"6to4svc mutex");
  28. if (g_Lock == NULL) {
  29. goto Error;
  30. }
  31. return TRUE;
  32. Error:
  33. if (g_Heap != NULL) {
  34. HeapDestroy(g_Heap);
  35. g_Heap = NULL;
  36. }
  37. return FALSE;
  38. }
  39. //------------------------------------------------------------------------------
  40. // _DllCleanup
  41. //
  42. // Called when the 6to4 dll is being unloaded. StopProtocol() would have
  43. // been called before, and that would have cleaned all the 6to4 structures.
  44. // This call frees the global mutex, destroys the local heap,
  45. //
  46. // Return Value: TRUE
  47. //------------------------------------------------------------------------------
  48. BOOL
  49. DllCleanup(
  50. )
  51. {
  52. CloseHandle(g_Lock);
  53. g_Lock = INVALID_HANDLE_VALUE;
  54. // destroy private heap
  55. if (g_Heap != NULL) {
  56. HeapDestroy(g_Heap);
  57. g_Heap = NULL;
  58. }
  59. return TRUE;
  60. }
  61. //------------------------------------------------------------------------------
  62. // _DLLMAIN
  63. //
  64. // Called immediately after 6to4svc.dll is loaded for the first time by the
  65. // process, and when the 6to4svc.dll is unloaded by the process.
  66. // It does some initialization/final cleanup.
  67. //
  68. // Calls: _DllStartup() or _DllCleanup()
  69. //------------------------------------------------------------------------------
  70. BOOL
  71. WINAPI
  72. DLLMAIN (
  73. HINSTANCE hModule,
  74. DWORD dwReason,
  75. LPVOID lpvReserved
  76. )
  77. {
  78. BOOL bErr;
  79. switch (dwReason) {
  80. //
  81. // Startup Initialization of Dll
  82. //
  83. case DLL_PROCESS_ATTACH:
  84. {
  85. // disable per-thread initialization
  86. DisableThreadLibraryCalls(hModule);
  87. // create and initialize global data
  88. bErr = DllStartup();
  89. break;
  90. }
  91. //
  92. // Cleanup of Dll
  93. //
  94. case DLL_PROCESS_DETACH:
  95. {
  96. // free global data
  97. bErr = DllCleanup();
  98. break;
  99. }
  100. default:
  101. bErr = TRUE;
  102. break;
  103. }
  104. return bErr;
  105. } // end _DLLMAIN
  106. #ifdef STANDALONE
  107. int __cdecl
  108. main(
  109. int argc,
  110. WCHAR **argv)
  111. {
  112. if (!DllStartup())
  113. return 1;
  114. ServiceMain(argc, argv);
  115. Sleep(100 * 1000);
  116. DllCleanup();
  117. return 0;
  118. }
  119. #endif