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.

277 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. name-of-module-filename
  5. Abstract:
  6. This module contains the code for actually allocating memory for dpmi.
  7. It uses the same suballocation pool as the xms code
  8. Author:
  9. Dave Hastings (daveh) creation-date 09-Feb-1994
  10. Notes:
  11. These functions claim to return NTSTATUS. This is for commonality on
  12. x86 where we actually have an NTSTATUS to return. For this file, we
  13. simply logically invert the bool and return that. Callers of these
  14. functions promise not to attach significance to the return values other
  15. than STATUS_SUCCESS.
  16. Revision History:
  17. --*/
  18. #include "precomp.h"
  19. #pragma hdrstop
  20. #include <softpc.h>
  21. #include <suballoc.h>
  22. #include <xmsexp.h>
  23. #include "memapi.h"
  24. NTSTATUS
  25. DpmiAllocateVirtualMemory(
  26. PVOID *Address,
  27. PULONG Size
  28. )
  29. /*++
  30. Routine Description:
  31. This routine allocates a chunk of extended memory for dpmi.
  32. Arguments:
  33. Address -- Supplies a pointer to the Address. This is filled in
  34. if the allocation is successfull
  35. Size -- Supplies the size to allocate
  36. Return Value:
  37. STATUS_SUCCESS if successfull.
  38. --*/
  39. {
  40. BOOL Success;
  41. NTSTATUS Status;
  42. Status = VdmAllocateVirtualMemory((PULONG)Address, *Size, TRUE);
  43. if (Status == STATUS_NOT_IMPLEMENTED) {
  44. ASSERT(STATUS_SUCCESS == 0);
  45. Success = SAAllocate(
  46. ExtMemSA,
  47. *Size,
  48. (PULONG)Address
  49. );
  50. //
  51. // Convert boolean to NTSTATUS (sort of)
  52. //
  53. if (Success) {
  54. Status = STATUS_SUCCESS;
  55. } else {
  56. Status = -1;
  57. }
  58. }
  59. return(Status);
  60. }
  61. NTSTATUS
  62. DpmiFreeVirtualMemory(
  63. PVOID *Address,
  64. PULONG Size
  65. )
  66. /*++
  67. Routine Description:
  68. This function frees memory for dpmi. It is returned to the suballocation
  69. pool.
  70. Arguments:
  71. Address -- Supplies the address of the block to free
  72. Size -- Supplies the size of the block to free
  73. Return Value:
  74. STATUS_SUCCESS if successful
  75. --*/
  76. {
  77. BOOL Success;
  78. NTSTATUS Status;
  79. Status = VdmFreeVirtualMemory(*(PULONG)Address);
  80. if (Status == STATUS_NOT_IMPLEMENTED) {
  81. Success = SAFree(
  82. ExtMemSA,
  83. *Size,
  84. (ULONG)*Address
  85. );
  86. //
  87. // Convert boolean to NTSTATUS (sort of)
  88. //
  89. if (Success) {
  90. Status = STATUS_SUCCESS;
  91. } else {
  92. Status = -1;
  93. }
  94. }
  95. return(Status);
  96. }
  97. NTSTATUS
  98. DpmiReallocateVirtualMemory(
  99. PVOID OldAddress,
  100. ULONG OldSize,
  101. PVOID *NewAddress,
  102. PULONG NewSize
  103. )
  104. /*++
  105. Routine Description:
  106. This function reallocates a block of memory for DPMI.
  107. Arguments:
  108. OldAddress -- Supplies the original address for the block
  109. OldSize -- Supplies the original size for the address
  110. NewAddress -- Supplies the pointer to the place to return the new
  111. address
  112. NewSize -- Supplies the new size
  113. Return Value:
  114. STATUS_SUCCESS if successfull
  115. --*/
  116. {
  117. NTSTATUS Status;
  118. BOOL Success;
  119. Status = VdmReallocateVirtualMemory((ULONG)OldAddress,
  120. (PULONG)NewAddress,
  121. *NewSize);
  122. if (Status == STATUS_NOT_IMPLEMENTED) {
  123. Success = SAReallocate(
  124. ExtMemSA,
  125. OldSize,
  126. (ULONG)OldAddress,
  127. *NewSize,
  128. (PULONG)NewAddress
  129. );
  130. //
  131. // Convert boolean to NTSTATUS (sort of)
  132. //
  133. if (Success) {
  134. Status = STATUS_SUCCESS;
  135. } else {
  136. Status = -1;
  137. }
  138. }
  139. return(Status);
  140. }
  141. VOID
  142. DpmiGetMemoryInfo(
  143. VOID
  144. )
  145. /*++
  146. Routine Description:
  147. This routine returns information about memory to the dos extender
  148. Arguments:
  149. None
  150. Return Value:
  151. None.
  152. --*/
  153. {
  154. PDPMIMEMINFO UNALIGNED MemInfo;
  155. MEMORYSTATUS MemStatus;
  156. ULONG TotalFree, LargestFree;
  157. NTSTATUS Status;
  158. //
  159. // Get a pointer to the return structure
  160. //
  161. MemInfo = (PDPMIMEMINFO)Sim32GetVDMPointer(
  162. ((ULONG)getES()) << 16,
  163. 1,
  164. TRUE
  165. );
  166. (CHAR *)MemInfo += (*GetDIRegister)();
  167. //
  168. // Initialize the structure
  169. //
  170. RtlFillMemory(MemInfo, sizeof(DPMIMEMINFO), 0xFF);
  171. //
  172. // Get the information on memory
  173. //
  174. Status = VdmQueryFreeVirtualMemory(
  175. &TotalFree,
  176. &LargestFree
  177. );
  178. if (Status == STATUS_NOT_IMPLEMENTED) {
  179. SAQueryFree(
  180. ExtMemSA,
  181. &TotalFree,
  182. &LargestFree
  183. );
  184. }
  185. //
  186. // Return the information.
  187. //
  188. // Filled in MaxUnlocked,MaxLocked,UnlockedPages fields in this structute.
  189. // Director 4.0 get completlely confused if these fields are -1.
  190. // MaxUnlocked is correct based on LargestFree. The other two are fake
  191. // and match values on a real WFW machine. I have no way of making them
  192. // any better than this at this point. who cares it makes director happy.
  193. //
  194. // sudeepb 01-Mar-1995.
  195. MemInfo->LargestFree = LargestFree;
  196. MemInfo->MaxUnlocked = LargestFree/4096;
  197. MemInfo->MaxLocked = 0xb61;
  198. MemInfo->AddressSpaceSize = 1024 * 1024 * 16 / 4096;
  199. MemInfo->UnlockedPages = 0xb68;
  200. MemInfo->FreePages = TotalFree / 4096;
  201. MemInfo->PhysicalPages = 1024 * 1024 * 16 / 4096;
  202. MemInfo->FreeAddressSpace = MemInfo->FreePages;
  203. //
  204. // Get the information on the page file
  205. //
  206. MemStatus.dwLength = sizeof(MEMORYSTATUS);
  207. GlobalMemoryStatus(&MemStatus);
  208. MemInfo->PageFileSize = MemStatus.dwTotalPageFile / 4096;
  209. }