3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/cont.c
6 * PURPOSE: Manages continuous memory
7 * PROGRAMMER: David Welch (welch@cwcom.net)
12 /* INCLUDES *****************************************************************/
14 #include <ddk/ntddk.h>
15 #include <internal/mm.h>
18 #include <internal/debug.h>
20 /* FUNCTIONS *****************************************************************/
23 MmFreeContinuousPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
24 PHYSICAL_ADDRESS PhysAddr, SWAPENTRY SwapEntry,
27 assert(SwapEntry == 0);
28 if (PhysAddr.QuadPart != 0)
30 MmReleasePageMemoryConsumer(MC_NPPOOL, PhysAddr);
35 MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
36 IN PHYSICAL_ADDRESS HighestAcceptableAddress,
41 PVOID BaseAddress = 0;
42 PHYSICAL_ADDRESS PBase;
45 MmLockAddressSpace(MmGetKernelAddressSpace());
46 Status = MmCreateMemoryArea(NULL,
47 MmGetKernelAddressSpace(),
48 MEMORY_AREA_CONTINUOUS_MEMORY,
54 MmUnlockAddressSpace(MmGetKernelAddressSpace());
56 if (!NT_SUCCESS(Status))
60 DPRINT( "Base = %x\n", BaseAddress );
61 PBase = MmGetContinuousPages(NumberOfBytes,
62 HighestAcceptableAddress,
64 if (PBase.QuadPart == 0LL)
66 MmLockAddressSpace(MmGetKernelAddressSpace());
67 MmFreeMemoryArea(MmGetKernelAddressSpace(),
72 MmUnlockAddressSpace(MmGetKernelAddressSpace());
75 for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / 4096); i++)
77 MmCreateVirtualMapping(NULL,
78 BaseAddress + (i * 4096),
79 PAGE_EXECUTE_READWRITE | PAGE_SYSTEM,
80 (LARGE_INTEGER)(PBase.QuadPart + (i * 4096)),
86 /**********************************************************************
88 * MmAllocateContiguousMemory@12
91 * Allocates a range of physically contiguous cache aligned
92 * memory from the non-paged pool.
96 * Size of the memory block to allocate;
98 * HighestAcceptableAddress
99 * Highest address valid for the caller.
102 * The virtual address of the memory block on success;
106 * Description taken from include/ddk/mmfuncs.h.
107 * Code taken from ntoskrnl/mm/special.c.
113 MmAllocateContiguousMemory (IN ULONG NumberOfBytes,
114 IN PHYSICAL_ADDRESS HighestAcceptableAddress)
116 return(MmAllocateContiguousAlignedMemory(NumberOfBytes,
117 HighestAcceptableAddress,
122 /**********************************************************************
124 * MmFreeContiguousMemory@4
127 * Releases a range of physically contiguous memory allocated
128 * with MmAllocateContiguousMemory.
132 * Virtual address of the memory to be freed.
138 * Description taken from include/ddk/mmfuncs.h.
139 * Code taken from ntoskrnl/mm/special.c.
145 MmFreeContiguousMemory(IN PVOID BaseAddress)
147 MmLockAddressSpace(MmGetKernelAddressSpace());
148 MmFreeMemoryArea(MmGetKernelAddressSpace(),
151 MmFreeContinuousPage,
153 MmUnlockAddressSpace(MmGetKernelAddressSpace());