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.

250 lines
6.1 KiB

  1. //*************************************************************
  2. //
  3. // File name: TSrvMisc.c
  4. //
  5. // Description: Misc TShareSRV support routines
  6. //
  7. // Microsoft Confidential
  8. // Copyright (c) Microsoft Corporation 1991-1997
  9. // All rights reserved
  10. //
  11. //*************************************************************
  12. #include <TSrv.h>
  13. // Data declarations
  14. BOOL g_fTSrvReady = FALSE;
  15. BOOL g_fTSrvTerminating = FALSE;
  16. //*************************************************************
  17. //
  18. // TSrvReady()
  19. //
  20. // Purpose: Sets the TShareSRV "ready" state
  21. //
  22. // Parameters: IN [fReady] -- TSrv ready state
  23. //
  24. // Return: void
  25. //
  26. // History: 07-17-97 BrianTa Created
  27. //
  28. //*************************************************************
  29. void
  30. TSrvReady(IN BOOL fReady)
  31. {
  32. TRACE((DEBUG_TSHRSRV_FLOW,
  33. "TShrSRV: TSrvReady entry\n"));
  34. g_fTSrvReady = fReady;
  35. TRACE((DEBUG_TSHRSRV_NORMAL, "TShrSRV: TShareSRV %sready\n",
  36. (g_fTSrvReady ? "" : "not ")));
  37. if (g_hReadyEvent)
  38. SetEvent(g_hReadyEvent);
  39. TRACE((DEBUG_TSHRSRV_FLOW,
  40. "TShrSRV: TSrvReady exit\n"));
  41. }
  42. //*************************************************************
  43. //
  44. // TSrvIsReady()
  45. //
  46. // Purpose: Returns the TShareSRV "ready" state
  47. //
  48. // Parameters: IN [fWait] -- Wait if not ready
  49. //
  50. // Return: TRUE if ready
  51. // FALSE if not
  52. //
  53. // History: 07-17-97 BrianTa Created
  54. //
  55. //*************************************************************
  56. BOOL
  57. TSrvIsReady(IN BOOL fWait)
  58. {
  59. if (!g_fTSrvReady && fWait)
  60. {
  61. TRACE((DEBUG_TSHRSRV_NORMAL,
  62. "TShrSRV: Waiting for TShareSRV to become ready\n"));
  63. WaitForSingleObject(g_hReadyEvent, 60000);
  64. TRACE((DEBUG_TSHRSRV_NORMAL,
  65. "TShrSRV: Done Waiting for TShareSRV to become ready - 0x%x\n",
  66. g_fTSrvReady));
  67. }
  68. return (g_fTSrvReady);
  69. }
  70. //*************************************************************
  71. //
  72. // TSrvTerminating()
  73. //
  74. // Purpose: Sets the TShareSRV "terminating" state
  75. //
  76. // Parameters: IN [fTerminating] -- TSrv ready state
  77. //
  78. // Return: void
  79. //
  80. // History: 07-17-97 BrianTa Created
  81. //
  82. //*************************************************************
  83. void
  84. TSrvTerminating(BOOL fTerminating)
  85. {
  86. TRACE((DEBUG_TSHRSRV_FLOW,
  87. "TShrSRV: TSrvTerminating entry\n"));
  88. g_fTSrvTerminating = fTerminating;
  89. TRACE((DEBUG_TSHRSRV_FLOW,
  90. "TShrSRV: TSrvTerminating exit\n"));
  91. }
  92. //*************************************************************
  93. //
  94. // TSrvIsTerminating()
  95. //
  96. // Purpose: Returns the TShareSRV "terminating" state
  97. //
  98. // Parameters: void
  99. //
  100. // Return: TRUE if terminating
  101. // FALSE if not
  102. //
  103. // History: 07-17-97 BrianTa Created
  104. //
  105. //*************************************************************
  106. BOOL
  107. TSrvIsTerminating(void)
  108. {
  109. return (g_fTSrvTerminating);
  110. }
  111. //*************************************************************
  112. //
  113. // TSrvAllocSection()
  114. //
  115. // Purpose: Allocates and mapps a section object
  116. //
  117. // Parameters: ulSize -- Section size
  118. // phSection -- ptr to section handle
  119. //
  120. // Return: Ptr to section base - if successfull
  121. // NULL otherwise
  122. //
  123. // History: 12-17-97 BrianTa Created
  124. //
  125. //*************************************************************
  126. PVOID
  127. TSrvAllocSection(PHANDLE phSection,
  128. ULONG ulSize)
  129. {
  130. LARGE_INTEGER SectionSize;
  131. LARGE_INTEGER liOffset;
  132. ULONG_PTR ulViewSize;
  133. NTSTATUS ntStatus;
  134. PVOID pvBase;
  135. // Create section and map it into the kernel
  136. pvBase = NULL;
  137. SectionSize.QuadPart = ulSize;
  138. ntStatus = NtCreateSection(phSection,
  139. SECTION_ALL_ACCESS,
  140. NULL,
  141. &SectionSize,
  142. PAGE_READWRITE,
  143. SEC_COMMIT,
  144. NULL);
  145. if (NT_SUCCESS(ntStatus))
  146. {
  147. pvBase = NULL;
  148. ulViewSize = ulSize;
  149. // Map the section into the current process and commit it
  150. liOffset.QuadPart = 0;
  151. ntStatus = NtMapViewOfSection(*phSection,
  152. GetCurrentProcess(),
  153. &pvBase,
  154. 0,
  155. ulViewSize,
  156. &liOffset,
  157. &ulViewSize,
  158. ViewShare,
  159. SEC_NO_CHANGE,
  160. PAGE_READWRITE);
  161. if (!NT_SUCCESS(ntStatus))
  162. {
  163. KdPrint(("NtMapViewOfSection failed - 0x%x\n", ntStatus));
  164. }
  165. }
  166. else
  167. {
  168. KdPrint(("NtCreateSection failed - 0x%x\n", ntStatus));
  169. }
  170. return (pvBase);
  171. }
  172. //*************************************************************
  173. //
  174. // TSrvFreeSection()
  175. //
  176. // Purpose: Frees a section object
  177. //
  178. // Parameters: hSection -- Section handle
  179. // pvBase -- Base section address
  180. //
  181. // Return: None
  182. //
  183. // History: 12-17-97 BrianTa Created
  184. //
  185. //*************************************************************
  186. void
  187. TSrvFreeSection(HANDLE hSection,
  188. PVOID pvBase)
  189. {
  190. NTSTATUS ntStatus;
  191. TS_ASSERT(hSection);
  192. ntStatus = NtUnmapViewOfSection(GetCurrentProcess, pvBase);
  193. if (NT_SUCCESS(ntStatus))
  194. {
  195. ntStatus = CloseHandle(hSection);
  196. if (NT_SUCCESS(ntStatus))
  197. KdPrint(("Closehandle failed - 0x%x\n", ntStatus));
  198. }
  199. else
  200. {
  201. KdPrint(("NtUnmapViewOfSection failed - 0x%x\n", ntStatus));
  202. }
  203. }