xref: /reactos/ntoskrnl/mm/arm/page.c (revision 3adf4508)
1 /*
2  * PROJECT:         ReactOS Kernel
3  * LICENSE:         BSD - See COPYING.ARM in the top level directory
4  * FILE:            ntoskrnl/mm/arm/page.c
5  * PURPOSE:         Old-school Page Management
6  * PROGRAMMERS:     ReactOS Portable Systems Group
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14 
15 #define MODULE_INVOLVED_IN_ARM3
16 #include <mm/ARM3/miarm.h>
17 
18 /* GLOBALS ********************************************************************/
19 
20 const
21 ULONG
22 MmProtectToPteMask[32] =
23 {
24     //
25     // These are the base MM_ protection flags
26     //
27     0,
28     PTE_READONLY            | PTE_ENABLE_CACHE,
29     PTE_EXECUTE             | PTE_ENABLE_CACHE,
30     PTE_EXECUTE_READ        | PTE_ENABLE_CACHE,
31     PTE_READWRITE           | PTE_ENABLE_CACHE,
32     PTE_WRITECOPY           | PTE_ENABLE_CACHE,
33     PTE_EXECUTE_READWRITE   | PTE_ENABLE_CACHE,
34     PTE_EXECUTE_WRITECOPY   | PTE_ENABLE_CACHE,
35     //
36     // These OR in the MM_NOCACHE flag
37     //
38     0,
39     PTE_READONLY            | PTE_DISABLE_CACHE,
40     PTE_EXECUTE             | PTE_DISABLE_CACHE,
41     PTE_EXECUTE_READ        | PTE_DISABLE_CACHE,
42     PTE_READWRITE           | PTE_DISABLE_CACHE,
43     PTE_WRITECOPY           | PTE_DISABLE_CACHE,
44     PTE_EXECUTE_READWRITE   | PTE_DISABLE_CACHE,
45     PTE_EXECUTE_WRITECOPY   | PTE_DISABLE_CACHE,
46     //
47     // These OR in the MM_DECOMMIT flag, which doesn't seem supported on x86/64/ARM
48     //
49     0,
50     PTE_READONLY            | PTE_ENABLE_CACHE,
51     PTE_EXECUTE             | PTE_ENABLE_CACHE,
52     PTE_EXECUTE_READ        | PTE_ENABLE_CACHE,
53     PTE_READWRITE           | PTE_ENABLE_CACHE,
54     PTE_WRITECOPY           | PTE_ENABLE_CACHE,
55     PTE_EXECUTE_READWRITE   | PTE_ENABLE_CACHE,
56     PTE_EXECUTE_WRITECOPY   | PTE_ENABLE_CACHE,
57     //
58     // These OR in the MM_NOACCESS flag, which seems to enable WriteCombining?
59     //
60     0,
61     PTE_READONLY            | PTE_WRITECOMBINED_CACHE,
62     PTE_EXECUTE             | PTE_WRITECOMBINED_CACHE,
63     PTE_EXECUTE_READ        | PTE_WRITECOMBINED_CACHE,
64     PTE_READWRITE           | PTE_WRITECOMBINED_CACHE,
65     PTE_WRITECOPY           | PTE_WRITECOMBINED_CACHE,
66     PTE_EXECUTE_READWRITE   | PTE_WRITECOMBINED_CACHE,
67     PTE_EXECUTE_WRITECOPY   | PTE_WRITECOMBINED_CACHE,
68 };
69 
70 const
71 ULONG MmProtectToValue[32] =
72 {
73     PAGE_NOACCESS,
74     PAGE_READONLY,
75     PAGE_EXECUTE,
76     PAGE_EXECUTE_READ,
77     PAGE_READWRITE,
78     PAGE_WRITECOPY,
79     PAGE_EXECUTE_READWRITE,
80     PAGE_EXECUTE_WRITECOPY,
81     PAGE_NOACCESS,
82     PAGE_NOCACHE | PAGE_READONLY,
83     PAGE_NOCACHE | PAGE_EXECUTE,
84     PAGE_NOCACHE | PAGE_EXECUTE_READ,
85     PAGE_NOCACHE | PAGE_READWRITE,
86     PAGE_NOCACHE | PAGE_WRITECOPY,
87     PAGE_NOCACHE | PAGE_EXECUTE_READWRITE,
88     PAGE_NOCACHE | PAGE_EXECUTE_WRITECOPY,
89     PAGE_NOACCESS,
90     PAGE_GUARD | PAGE_READONLY,
91     PAGE_GUARD | PAGE_EXECUTE,
92     PAGE_GUARD | PAGE_EXECUTE_READ,
93     PAGE_GUARD | PAGE_READWRITE,
94     PAGE_GUARD | PAGE_WRITECOPY,
95     PAGE_GUARD | PAGE_EXECUTE_READWRITE,
96     PAGE_GUARD | PAGE_EXECUTE_WRITECOPY,
97     PAGE_NOACCESS,
98     PAGE_WRITECOMBINE | PAGE_READONLY,
99     PAGE_WRITECOMBINE | PAGE_EXECUTE,
100     PAGE_WRITECOMBINE | PAGE_EXECUTE_READ,
101     PAGE_WRITECOMBINE | PAGE_READWRITE,
102     PAGE_WRITECOMBINE | PAGE_WRITECOPY,
103     PAGE_WRITECOMBINE | PAGE_EXECUTE_READWRITE,
104     PAGE_WRITECOMBINE | PAGE_EXECUTE_WRITECOPY
105 };
106 
107 ULONG MmGlobalKernelPageDirectory[4096];
108 
109 /* Template PTE and PDE for a kernel page */
110 MMPDE ValidKernelPde = {.u.Hard.Valid = 1};
111 MMPTE ValidKernelPte = {.u.Hard.Valid = 1, .u.Hard.Sbo = 1};
112 
113 /* Template PDE for a demand-zero page */
114 MMPDE DemandZeroPde  = {.u.Long = (MM_READWRITE << MM_PTE_SOFTWARE_PROTECTION_BITS)};
115 MMPTE DemandZeroPte  = {.u.Long = (MM_READWRITE << MM_PTE_SOFTWARE_PROTECTION_BITS)};
116 
117 /* Template PTE for prototype page */
118 MMPTE PrototypePte = {.u.Long = (MM_READWRITE << MM_PTE_SOFTWARE_PROTECTION_BITS) | PTE_PROTOTYPE | (MI_PTE_LOOKUP_NEEDED << PAGE_SHIFT)};
119 
120 MMPTE ValidKernelPteLocal = {{0}};
121 MMPDE ValidKernelPdeLocal = {{0}};
122 MMPTE MmDecommittedPte = {{0}};
123 
124 /* PRIVATE FUNCTIONS **********************************************************/
125 
126 VOID
127 NTAPI
MiFlushTlb(IN PMMPTE PointerPte,IN PVOID Address)128 MiFlushTlb(IN PMMPTE PointerPte,
129            IN PVOID Address)
130 {
131     UNIMPLEMENTED_DBGBREAK();
132 }
133 
134 BOOLEAN
135 NTAPI
MmCreateProcessAddressSpace(IN ULONG MinWs,IN PEPROCESS Process,IN PULONG DirectoryTableBase)136 MmCreateProcessAddressSpace(IN ULONG MinWs,
137                             IN PEPROCESS Process,
138                             IN PULONG DirectoryTableBase)
139 {
140     UNIMPLEMENTED_DBGBREAK();
141     return FALSE;
142 }
143 
144 NTSTATUS
145 NTAPI
MmCreateVirtualMappingUnsafe(IN PEPROCESS Process,IN PVOID Address,IN ULONG Protection,IN PPFN_NUMBER Pages,IN ULONG PageCount)146 MmCreateVirtualMappingUnsafe(IN PEPROCESS Process,
147                              IN PVOID Address,
148                              IN ULONG Protection,
149                              IN PPFN_NUMBER Pages,
150                              IN ULONG PageCount)
151 {
152     UNIMPLEMENTED_DBGBREAK();
153     return STATUS_SUCCESS;
154 }
155 
156 NTSTATUS
157 NTAPI
MmCreateVirtualMapping(IN PEPROCESS Process,IN PVOID Address,IN ULONG Protection,IN PPFN_NUMBER Pages,IN ULONG PageCount)158 MmCreateVirtualMapping(IN PEPROCESS Process,
159                        IN PVOID Address,
160                        IN ULONG Protection,
161                        IN PPFN_NUMBER Pages,
162                        IN ULONG PageCount)
163 {
164     UNIMPLEMENTED_DBGBREAK();
165     return STATUS_SUCCESS;
166 }
167 
168 VOID
169 NTAPI
MmRawDeleteVirtualMapping(IN PVOID Address)170 MmRawDeleteVirtualMapping(IN PVOID Address)
171 {
172     UNIMPLEMENTED_DBGBREAK();
173 }
174 
175 VOID
176 NTAPI
MmDeleteVirtualMapping(IN PEPROCESS Process,IN PVOID Address,OUT PBOOLEAN WasDirty,OUT PPFN_NUMBER Page)177 MmDeleteVirtualMapping(IN PEPROCESS Process,
178                        IN PVOID Address,
179                        OUT PBOOLEAN WasDirty,
180                        OUT PPFN_NUMBER Page)
181 {
182     UNIMPLEMENTED_DBGBREAK();
183 }
184 
185 VOID
186 NTAPI
MmDeletePageFileMapping(IN PEPROCESS Process,IN PVOID Address,IN SWAPENTRY * SwapEntry)187 MmDeletePageFileMapping(IN PEPROCESS Process,
188                         IN PVOID Address,
189                         IN SWAPENTRY *SwapEntry)
190 {
191     UNIMPLEMENTED_DBGBREAK();
192 }
193 
194 NTSTATUS
195 NTAPI
MmCreatePageFileMapping(IN PEPROCESS Process,IN PVOID Address,IN SWAPENTRY SwapEntry)196 MmCreatePageFileMapping(IN PEPROCESS Process,
197                         IN PVOID Address,
198                         IN SWAPENTRY SwapEntry)
199 {
200     UNIMPLEMENTED_DBGBREAK();
201     return STATUS_NOT_IMPLEMENTED;
202 }
203 
204 PFN_NUMBER
205 NTAPI
MmGetPfnForProcess(IN PEPROCESS Process,IN PVOID Address)206 MmGetPfnForProcess(IN PEPROCESS Process,
207                    IN PVOID Address)
208 {
209     UNIMPLEMENTED_DBGBREAK();
210     return 0;
211 }
212 
213 BOOLEAN
214 NTAPI
MmIsDirtyPage(IN PEPROCESS Process,IN PVOID Address)215 MmIsDirtyPage(IN PEPROCESS Process,
216               IN PVOID Address)
217 {
218     UNIMPLEMENTED_DBGBREAK();
219     return FALSE;
220 }
221 
222 VOID
223 NTAPI
MmSetCleanPage(IN PEPROCESS Process,IN PVOID Address)224 MmSetCleanPage(IN PEPROCESS Process,
225                IN PVOID Address)
226 {
227     UNIMPLEMENTED_DBGBREAK();
228 }
229 
230 VOID
231 NTAPI
MmSetDirtyPage(IN PEPROCESS Process,IN PVOID Address)232 MmSetDirtyPage(IN PEPROCESS Process,
233                IN PVOID Address)
234 {
235     UNIMPLEMENTED_DBGBREAK();
236 }
237 
238 BOOLEAN
239 NTAPI
MmIsPagePresent(IN PEPROCESS Process,IN PVOID Address)240 MmIsPagePresent(IN PEPROCESS Process,
241                 IN PVOID Address)
242 {
243     UNIMPLEMENTED_DBGBREAK();
244     return FALSE;
245 }
246 
247 BOOLEAN
248 NTAPI
MmIsPageSwapEntry(IN PEPROCESS Process,IN PVOID Address)249 MmIsPageSwapEntry(IN PEPROCESS Process,
250                   IN PVOID Address)
251 {
252     UNIMPLEMENTED_DBGBREAK();
253     return FALSE;
254 }
255 
256 ULONG
257 NTAPI
MmGetPageProtect(IN PEPROCESS Process,IN PVOID Address)258 MmGetPageProtect(IN PEPROCESS Process,
259                  IN PVOID Address)
260 {
261     /* We don't enforce any protection on the pages -- they are all RWX */
262     return PAGE_READWRITE;
263 }
264 
265 VOID
266 NTAPI
MmSetPageProtect(IN PEPROCESS Process,IN PVOID Address,IN ULONG Protection)267 MmSetPageProtect(IN PEPROCESS Process,
268                  IN PVOID Address,
269                  IN ULONG Protection)
270 {
271     /* We don't enforce any protection on the pages -- they are all RWX */
272     return;
273 }
274 
275 VOID
276 NTAPI
MmInitGlobalKernelPageDirectory(VOID)277 MmInitGlobalKernelPageDirectory(VOID)
278 {
279     ULONG i;
280     PULONG CurrentPageDirectory = (PULONG)PDE_BASE;
281 
282     /* Loop the 2GB of address space which belong to the kernel */
283     for (i = MiGetPdeOffset(MmSystemRangeStart); i < 2048; i++)
284     {
285         /* Check if we have an entry for this already */
286         if ((i != MiGetPdeOffset(PTE_BASE)) &&
287             (i != MiGetPdeOffset(HYPER_SPACE)) &&
288             (!MmGlobalKernelPageDirectory[i]) &&
289             (CurrentPageDirectory[i]))
290         {
291             /* We don't, link it in our global page directory */
292             MmGlobalKernelPageDirectory[i] = CurrentPageDirectory[i];
293         }
294     }
295 }
296 
297 VOID
298 NTAPI
MmGetPageFileMapping(PEPROCESS Process,PVOID Address,SWAPENTRY * SwapEntry)299 MmGetPageFileMapping(
300     PEPROCESS Process,
301     PVOID Address,
302     SWAPENTRY* SwapEntry)
303 {
304     ASSERT(FALSE);
305 }
306 
307 BOOLEAN
308 NTAPI
MmIsDisabledPage(PEPROCESS Process,PVOID Address)309 MmIsDisabledPage(PEPROCESS Process, PVOID Address)
310 {
311     ASSERT(FALSE);
312     return FALSE;
313 }
314 
315 CODE_SEG("INIT")
316 VOID
317 NTAPI
MiInitializeSessionSpaceLayout(VOID)318 MiInitializeSessionSpaceLayout(VOID)
319 {
320     ASSERT(FALSE);
321 }
322 
323