Windows NT 4.0 source code leak
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.

179 lines
3.4 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. vrdll.c
  5. Abstract:
  6. Initialization for VdmRedir as DLL
  7. Contents:
  8. VrDllInitialize
  9. Author:
  10. Richard L Firth (rfirth) 11-May-1992
  11. Revision History:
  12. --*/
  13. #if DBG
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #endif
  19. #include <nt.h>
  20. #include <ntrtl.h>
  21. #include <nturtl.h>
  22. #include <windows.h>
  23. #include <vrnmpipe.h>
  24. #include <vrinit.h>
  25. #include "vrdebug.h"
  26. //
  27. // external data
  28. //
  29. //
  30. // external functions
  31. //
  32. extern
  33. VOID
  34. TerminateDlcEmulation(
  35. VOID
  36. );
  37. #if DBG
  38. FILE* hVrDebugLog = NULL;
  39. #endif
  40. BOOLEAN
  41. VrDllInitialize(
  42. IN PVOID DllHandle,
  43. IN ULONG Reason,
  44. IN PCONTEXT Context OPTIONAL
  45. )
  46. /*++
  47. Routine Description:
  48. Gets control as a process or thread attaches/detaches from VdmRedir DLL.
  49. Always returns success
  50. Arguments:
  51. DllHandle -
  52. Reason -
  53. Context -
  54. Return Value:
  55. BOOLEAN
  56. TRUE
  57. --*/
  58. {
  59. BOOL ok;
  60. #if DBG
  61. if (Reason == DLL_PROCESS_ATTACH) {
  62. //
  63. // a little run-time diagnostication, madam?
  64. //
  65. LPSTR ptr;
  66. //
  67. // override VrDebugFlags from VR environment variable
  68. //
  69. if (ptr = getenv("VR")) {
  70. if (!_strnicmp(ptr, "0x", 2)) {
  71. ptr += 2;
  72. }
  73. for (VrDebugFlags = 0; isxdigit(*ptr); ++ptr) {
  74. VrDebugFlags = VrDebugFlags * 16
  75. + (*ptr
  76. - ('0' + ((*ptr <= '9') ? 0
  77. : ((islower(*ptr) ? 'a' : 'A') - ('9' + 1)))));
  78. }
  79. IF_DEBUG(DLL) {
  80. DBGPRINT("Setting VrDebugFlags to %#08x from environment variable (VR)\n", VrDebugFlags);
  81. }
  82. }
  83. IF_DEBUG(TO_FILE) {
  84. if ((hVrDebugLog = fopen(VRDEBUG_FILE, "w+")) == NULL) {
  85. VrDebugFlags &= ~DEBUG_TO_FILE;
  86. } else {
  87. char currentDirectory[256];
  88. int n;
  89. currentDirectory[0] = 0;
  90. if (n = GetCurrentDirectory(sizeof(currentDirectory), currentDirectory)) {
  91. if (currentDirectory[n-1] == '\\') {
  92. currentDirectory[n-1] = 0;
  93. }
  94. }
  95. DbgPrint("Writing debug output to %s\\" VRDEBUG_FILE "\n", currentDirectory);
  96. }
  97. }
  98. IF_DEBUG(DLL) {
  99. DBGPRINT("VrDllInitialize: process %d Attaching\n", GetCurrentProcessId());
  100. }
  101. } else if (Reason == DLL_PROCESS_DETACH) {
  102. IF_DEBUG(DLL) {
  103. DBGPRINT("VrDllInitialize: process %d Detaching\n", GetCurrentProcessId());
  104. }
  105. if (hVrDebugLog) {
  106. fclose(hVrDebugLog);
  107. }
  108. } else {
  109. IF_DEBUG(DLL) {
  110. DBGPRINT("VrDllInitialize: Thread %d.%d %staching\n",
  111. GetCurrentProcessId(),
  112. GetCurrentThreadId(),
  113. (Reason == DLL_THREAD_ATTACH) ? "At" : "De"
  114. );
  115. }
  116. }
  117. #endif
  118. if (Reason == DLL_PROCESS_ATTACH) {
  119. //
  120. // we now perform initialization at load time due to deferred loading
  121. // of VdmRedir.DLL
  122. //
  123. ok = VrInitialize();
  124. } else if (Reason == DLL_PROCESS_DETACH) {
  125. //
  126. // clean up resources
  127. //
  128. VrUninitialize();
  129. TerminateDlcEmulation();
  130. ok = TRUE;
  131. }
  132. //
  133. // basically, nothing to do
  134. //
  135. return ok;
  136. }