Source code of Windows XP (NT5)
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.

155 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. xmscmt86.c
  5. Abstract:
  6. This module conains the memory commit/decommit routines
  7. for x86.
  8. Author:
  9. Dave Hastings (daveh) creation-date 25-Jan-1994
  10. Revision History:
  11. --*/
  12. #include <xms.h>
  13. #include <suballoc.h>
  14. NTSTATUS
  15. xmsCommitBlock(
  16. ULONG BaseAddress,
  17. ULONG Size
  18. )
  19. /*++
  20. Routine Description:
  21. This routine commits a block of memory using NtAllocateVirtualMemory.
  22. Arguments:
  23. BaseAddress -- Supplies the base address to commit memory at
  24. Size -- Supplies the size of the block to commit
  25. Return Value:
  26. Same as NtAllocateVirtualMemory.
  27. --*/
  28. {
  29. PVOID Address;
  30. ULONG s;
  31. NTSTATUS Status;
  32. //
  33. // Copy the parameters locally, so that MM doesn't
  34. // change them for us
  35. //
  36. Address = (PVOID)BaseAddress;
  37. s = Size;
  38. //
  39. // Perform the allocation
  40. //
  41. Status = NtAllocateVirtualMemory(
  42. NtCurrentProcess(),
  43. &Address,
  44. 0L,
  45. &s,
  46. MEM_COMMIT,
  47. PAGE_READWRITE
  48. );
  49. return Status;
  50. }
  51. NTSTATUS
  52. xmsDecommitBlock(
  53. ULONG BaseAddress,
  54. ULONG Size
  55. )
  56. /*++
  57. Routine Description:
  58. This routine commits a block of memory using NtAllocateVirtualMemory.
  59. Arguments:
  60. BaseAddress -- Supplies the base address to decommit memory at
  61. Size -- Supplies the size of the block to decommit
  62. Return Value:
  63. Same as NtFreeVirtualMemory.
  64. --*/
  65. {
  66. PVOID Address;
  67. ULONG s;
  68. NTSTATUS Status;
  69. //
  70. // Copy the parameters locally, so that MM doesn't
  71. // change them for us
  72. //
  73. Address = (PVOID)BaseAddress;
  74. s = Size;
  75. //
  76. // Perform the allocation
  77. //
  78. Status = NtFreeVirtualMemory( NtCurrentProcess(),
  79. &Address,
  80. &s,
  81. MEM_DECOMMIT
  82. );
  83. return Status;
  84. }
  85. VOID
  86. xmsMoveMemory(
  87. ULONG Destination,
  88. ULONG Source,
  89. ULONG Count
  90. )
  91. /*++
  92. Routine Description:
  93. This routine moves a block of memory, and notifies the emulator.
  94. It correctly handles overlapping source and destination
  95. Arguments:
  96. Destination -- Supplies a pointer to the destination Linear
  97. Address
  98. Source -- Supplies a pointer to the source Linear Address
  99. Count -- Supplies the number of bytes to move
  100. Return Value:
  101. None.
  102. --*/
  103. {
  104. //
  105. // Move the memory
  106. //
  107. RtlMoveMemory(
  108. (PVOID)Destination,
  109. (PVOID)Source,
  110. Count
  111. );
  112. }