1 /* $Id: cont.c,v 1.17 2002/01/01 00:21:55 dwelch Exp $
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
, ULONG PhysAddr
,
24 SWAPENTRY SwapEntry
, BOOLEAN Dirty
)
26 assert(SwapEntry
== 0);
29 MmDereferencePage((PVOID
)PhysAddr
);
34 MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes
,
35 IN PHYSICAL_ADDRESS HighestAcceptableAddress
,
40 PVOID BaseAddress
= 0;
44 MmLockAddressSpace(MmGetKernelAddressSpace());
45 Status
= MmCreateMemoryArea(NULL
,
46 MmGetKernelAddressSpace(),
47 MEMORY_AREA_CONTINUOUS_MEMORY
,
53 MmUnlockAddressSpace(MmGetKernelAddressSpace());
55 if (!NT_SUCCESS(Status
))
59 DPRINT( "Base = %x\n", BaseAddress
);
60 PBase
= MmGetContinuousPages(NumberOfBytes
,
61 HighestAcceptableAddress
,
65 MmFreeMemoryArea(MmGetKernelAddressSpace(),
72 for (i
= 0; i
< (PAGE_ROUND_UP(NumberOfBytes
) / 4096); i
++)
74 MmCreateVirtualMapping(NULL
,
75 BaseAddress
+ (i
* 4096),
76 PAGE_EXECUTE_READWRITE
| PAGE_SYSTEM
,
77 (ULONG
)(PBase
+ (i
* 4096)),
83 /**********************************************************************
85 * MmAllocateContiguousMemory@12
88 * Allocates a range of physically contiguous cache aligned
89 * memory from the non-paged pool.
93 * Size of the memory block to allocate;
95 * HighestAcceptableAddress
96 * Highest address valid for the caller.
99 * The virtual address of the memory block on success;
103 * Description taken from include/ddk/mmfuncs.h.
104 * Code taken from ntoskrnl/mm/special.c.
110 MmAllocateContiguousMemory (IN ULONG NumberOfBytes
,
111 IN PHYSICAL_ADDRESS HighestAcceptableAddress
)
113 return(MmAllocateContiguousAlignedMemory(NumberOfBytes
,
114 HighestAcceptableAddress
,
119 /**********************************************************************
121 * MmFreeContiguousMemory@4
124 * Releases a range of physically contiguous memory allocated
125 * with MmAllocateContiguousMemory.
129 * Virtual address of the memory to be freed.
135 * Description taken from include/ddk/mmfuncs.h.
136 * Code taken from ntoskrnl/mm/special.c.
142 MmFreeContiguousMemory(IN PVOID BaseAddress
)
144 MmFreeMemoryArea(MmGetKernelAddressSpace(),
147 MmFreeContinuousPage
,