2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/mm/special.c
5 * PURPOSE: Special types of memory region
6 * PROGRAMMER: David Welch (welch@mcmail.com)
11 /* INCLUDES *****************************************************************/
13 #include <ddk/ntddk.h>
14 #include <internal/mm.h>
17 #include <internal/debug.h>
19 /* FUNCTIONS *****************************************************************/
21 PVOID
MmAllocateSection(ULONG Length
)
29 DPRINT("MmAllocateSection(Length %x)\n",Length
);
32 Status
= MmCreateMemoryArea(KernelMode
,
33 PsGetCurrentProcess(),
39 if (Status
!=STATUS_SUCCESS
)
43 DPRINT("Result %x\n",Result
);
44 Attributes
= PA_WRITE
| PA_READ
| PA_EXECUTE
| PA_SYSTEM
;
45 for (i
=0;i
<=(Length
/PAGESIZE
);i
++)
47 set_page(Result
+(i
*PAGESIZE
),Attributes
,get_free_page());
49 return((PVOID
)Result
);
52 PVOID
MmAllocateContiguousMemory(ULONG NumberOfBytes
,
53 PHYSICAL_ADDRESS HighestAcceptableAddress
)
58 VOID
MmFreeContiguousMemory(PVOID BaseAddress
)
63 PVOID
MmMapIoSpace(PHYSICAL_ADDRESS PhysicalAddress
,
74 Status
= MmCreateMemoryArea(KernelMode
,
75 PsGetCurrentProcess(),
76 MEMORY_AREA_IO_MAPPING
,
81 if (Status
!=STATUS_SUCCESS
)
85 Attributes
= PA_WRITE
| PA_READ
| PA_EXECUTE
| PA_SYSTEM
;
88 Attributes
= Attributes
| PA_PWT
| PA_PCD
;
90 for (i
=0;i
<=(NumberOfBytes
/PAGESIZE
);i
++)
92 set_page(Result
+(i
*PAGESIZE
),Attributes
,PhysicalAddress
.LowPart
);
94 return((PVOID
)Result
);
97 VOID
MmUnmapIoSpace(PVOID BaseAddress
, ULONG NumberOfBytes
)
99 (void)MmFreeMemoryArea(PsGetCurrentProcess(),BaseAddress
,NumberOfBytes
,
103 PVOID
MmAllocateNonCachedMemory(ULONG NumberOfBytes
)
111 Status
= MmCreateMemoryArea(KernelMode
,
112 PsGetCurrentProcess(),
113 MEMORY_AREA_NO_CACHE
,
118 if (Status
!=STATUS_SUCCESS
)
122 for (i
=0;i
<=(NumberOfBytes
/PAGESIZE
);i
++)
124 set_page(Result
+(i
*PAGESIZE
),
125 PA_WRITE
| PA_READ
| PA_EXECUTE
| PA_SYSTEM
| PA_PCD
| PA_PWT
,
128 return((PVOID
)Result
);
131 VOID
MmFreeNonCachedMemory(PVOID BaseAddress
, ULONG NumberOfBytes
)
133 MmFreeMemoryArea(PsGetCurrentProcess(),BaseAddress
,NumberOfBytes
,TRUE
);