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,
55 MmUnlockAddressSpace(MmGetKernelAddressSpace());
57 if (!NT_SUCCESS(Status))
61 DPRINT( "Base = %x\n", BaseAddress );
62 PBase = MmGetContinuousPages(NumberOfBytes,
63 HighestAcceptableAddress,
65 if (PBase.QuadPart == 0LL)
67 MmLockAddressSpace(MmGetKernelAddressSpace());
68 MmFreeMemoryArea(MmGetKernelAddressSpace(),
73 MmUnlockAddressSpace(MmGetKernelAddressSpace());
76 for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / 4096); i++)
78 MmCreateVirtualMapping(NULL,
79 BaseAddress + (i * 4096),
80 PAGE_EXECUTE_READWRITE | PAGE_SYSTEM,
81 (LARGE_INTEGER)(PBase.QuadPart + (i * 4096)),
87 /**********************************************************************
89 * MmAllocateContiguousMemory@12
92 * Allocates a range of physically contiguous cache aligned
93 * memory from the non-paged pool.
97 * Size of the memory block to allocate;
99 * HighestAcceptableAddress
100 * Highest address valid for the caller.
103 * The virtual address of the memory block on success;
107 * Description taken from include/ddk/mmfuncs.h.
108 * Code taken from ntoskrnl/mm/special.c.
115 MmAllocateContiguousMemory (IN ULONG NumberOfBytes,
116 IN PHYSICAL_ADDRESS HighestAcceptableAddress)
118 return(MmAllocateContiguousAlignedMemory(NumberOfBytes,
119 HighestAcceptableAddress,
124 /**********************************************************************
126 * MmFreeContiguousMemory@4
129 * Releases a range of physically contiguous memory allocated
130 * with MmAllocateContiguousMemory.
134 * Virtual address of the memory to be freed.
140 * Description taken from include/ddk/mmfuncs.h.
141 * Code taken from ntoskrnl/mm/special.c.
148 MmFreeContiguousMemory(IN PVOID BaseAddress)
150 MmLockAddressSpace(MmGetKernelAddressSpace());
151 MmFreeMemoryArea(MmGetKernelAddressSpace(),
154 MmFreeContinuousPage,
156 MmUnlockAddressSpace(MmGetKernelAddressSpace());