preliminary comment out the self-modifying code for RtlPrefetchMemoryNonTemporal
[reactos.git] / reactos / ntoskrnl / mm / ncache.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/ncache.c
6 * PURPOSE: Manages non-cached memory
7 *
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <internal/debug.h>
16
17 /* FUNCTIONS *****************************************************************/
18
19
20 /**********************************************************************
21 * NAME EXPORTED
22 * MmAllocateNonCachedMemory@4
23 *
24 * DESCRIPTION
25 * Allocates a virtual address range of noncached and cache
26 * aligned memory.
27 *
28 * ARGUMENTS
29 * NumberOfBytes
30 * Size of region to allocate.
31 *
32 * RETURN VALUE
33 * The base address of the range on success;
34 * NULL on failure.
35 *
36 * NOTE
37 * Description taken from include/ddk/mmfuncs.h.
38 * Code taken from ntoskrnl/mm/special.c.
39 *
40 * REVISIONS
41 *
42 * @implemented
43 */
44 PVOID STDCALL
45 MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
46 {
47 PVOID Result;
48 MEMORY_AREA* marea;
49 NTSTATUS Status;
50 ULONG i;
51 ULONG Protect = PAGE_READWRITE|PAGE_SYSTEM|PAGE_NOCACHE|PAGE_WRITETHROUGH;
52 PHYSICAL_ADDRESS BoundaryAddressMultiple;
53
54 BoundaryAddressMultiple.QuadPart = 0;
55 MmLockAddressSpace(MmGetKernelAddressSpace());
56 Result = NULL;
57 Status = MmCreateMemoryArea (MmGetKernelAddressSpace(),
58 MEMORY_AREA_NO_CACHE,
59 &Result,
60 NumberOfBytes,
61 Protect,
62 &marea,
63 FALSE,
64 0,
65 BoundaryAddressMultiple);
66 MmUnlockAddressSpace(MmGetKernelAddressSpace());
67
68 if (!NT_SUCCESS(Status))
69 {
70 return (NULL);
71 }
72
73 for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / PAGE_SIZE); i++)
74 {
75 PFN_TYPE NPage;
76
77 Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &NPage);
78 MmCreateVirtualMapping (NULL,
79 (char*)Result + (i * PAGE_SIZE),
80 Protect,
81 &NPage,
82 1);
83 }
84 return ((PVOID)Result);
85 }
86
87 VOID STATIC
88 MmFreeNonCachedPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
89 PFN_TYPE Page, SWAPENTRY SwapEntry,
90 BOOLEAN Dirty)
91 {
92 ASSERT(SwapEntry == 0);
93 if (Page != 0)
94 {
95 MmReleasePageMemoryConsumer(MC_NPPOOL, Page);
96 }
97 }
98
99 /**********************************************************************
100 * NAME EXPORTED
101 * MmFreeNonCachedMemory@8
102 *
103 * DESCRIPTION
104 * Releases a range of noncached memory allocated with
105 * MmAllocateNonCachedMemory.
106 *
107 * ARGUMENTS
108 * BaseAddress
109 * Virtual address to be freed;
110 *
111 * NumberOfBytes
112 * Size of the region to be freed.
113 *
114 * RETURN VALUE
115 * None.
116 *
117 * NOTE
118 * Description taken from include/ddk/mmfuncs.h.
119 * Code taken from ntoskrnl/mm/special.c.
120 *
121 * REVISIONS
122 *
123 * @implemented
124 */
125 VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
126 IN ULONG NumberOfBytes)
127 {
128 MmLockAddressSpace(MmGetKernelAddressSpace());
129 MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
130 BaseAddress,
131 MmFreeNonCachedPage,
132 NULL);
133 MmUnlockAddressSpace(MmGetKernelAddressSpace());
134 }
135
136 /* EOF */