ReactOS  0.4.15-dev-2704-gd5265b0
hypermap.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: BSD - See COPYING.ARM in the top level directory
4  * FILE: ntoskrnl/mm/ARM3/hypermap.c
5  * PURPOSE: ARM Memory Manager Hyperspace Mapping Functionality
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 
23 
24 /* PRIVATE FUNCTIONS **********************************************************/
25 
26 PVOID
27 NTAPI
31 {
32  MMPTE TempPte;
33  PMMPTE PointerPte;
35 
36  //
37  // Never accept page 0 or non-physical pages
38  //
39  ASSERT(Page != 0);
41 
42  //
43  // Build the PTE
44  //
46  TempPte.u.Hard.PageFrameNumber = Page;
47 
48  //
49  // Pick the first hyperspace PTE
50  //
51  PointerPte = MmFirstReservedMappingPte;
52 
53  //
54  // Acquire the hyperlock
55  //
57  KeAcquireSpinLock(&Process->HyperSpaceLock, OldIrql);
58 
59  //
60  // Now get the first free PTE
61  //
62  Offset = PFN_FROM_PTE(PointerPte);
63  if (!Offset)
64  {
65  //
66  // Reset the PTEs
67  //
70  }
71 
72  //
73  // Prepare the next PTE
74  //
75  PointerPte->u.Hard.PageFrameNumber = Offset - 1;
76 
77  //
78  // Write the current PTE
79  //
80  PointerPte += Offset;
81  MI_WRITE_VALID_PTE(PointerPte, TempPte);
82 
83  //
84  // Return the address
85  //
86  return MiPteToAddress(PointerPte);
87 }
88 
89 VOID
90 NTAPI
94 {
96 
97  //
98  // Blow away the mapping
99  //
100  MiAddressToPte(Address)->u.Long = 0;
101 
102  //
103  // Release the hyperlock
104  //
106  KeReleaseSpinLock(&Process->HyperSpaceLock, OldIrql);
107 }
108 
109 PVOID
110 NTAPI
112  IN PFN_NUMBER NumberOfPages)
113 {
114  MMPTE TempPte;
115  PMMPTE PointerPte;
116  PFN_NUMBER Offset, PageFrameIndex;
117 
118  //
119  // Sanity checks
120  //
122  ASSERT(NumberOfPages != 0);
123  ASSERT(NumberOfPages <= MI_ZERO_PTES);
124 
125  //
126  // Pick the first zeroing PTE
127  //
128  PointerPte = MiFirstReservedZeroingPte;
129 
130  //
131  // Now get the first free PTE
132  //
133  Offset = PFN_FROM_PTE(PointerPte);
134  if (NumberOfPages > Offset)
135  {
136  //
137  // Reset the PTEs
138  //
140  PointerPte->u.Hard.PageFrameNumber = Offset;
142  }
143 
144  //
145  // Prepare the next PTE
146  //
147  PointerPte->u.Hard.PageFrameNumber = Offset - NumberOfPages;
148 
149  /* Choose the correct PTE to use, and which template */
150  PointerPte += (Offset + 1);
152 
153  /* Make sure the list isn't empty and loop it */
154  ASSERT(Pfn1 != (PVOID)LIST_HEAD);
155  while (Pfn1 != (PVOID)LIST_HEAD)
156  {
157  /* Get the page index for this PFN */
158  PageFrameIndex = MiGetPfnEntryIndex(Pfn1);
159 
160  //
161  // Write the PFN
162  //
163  TempPte.u.Hard.PageFrameNumber = PageFrameIndex;
164 
165  //
166  // Set the correct PTE to write to, and set its new value
167  //
168  PointerPte--;
169  MI_WRITE_VALID_PTE(PointerPte, TempPte);
170 
171  /* Move to the next PFN */
172  Pfn1 = (PMMPFN)Pfn1->u1.Flink;
173  }
174 
175  //
176  // Return the address
177  //
178  return MiPteToAddress(PointerPte);
179 }
180 
181 VOID
182 NTAPI
184  IN PFN_NUMBER NumberOfPages)
185 {
186  PMMPTE PointerPte;
187 
188  //
189  // Sanity checks
190  //
192  ASSERT (NumberOfPages != 0);
193  ASSERT(NumberOfPages <= MI_ZERO_PTES);
194 
195  //
196  // Get the first PTE for the mapped zero VA
197  //
198  PointerPte = MiAddressToPte(VirtualAddress);
199 
200  //
201  // Blow away the mapped zero PTEs
202  //
203  RtlZeroMemory(PointerPte, NumberOfPages * sizeof(MMPTE));
204 }
205 
PVOID NTAPI MiMapPagesInZeroSpace(IN PMMPFN Pfn1, IN PFN_NUMBER NumberOfPages)
Definition: hypermap.c:111
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
VOID NTAPI MiUnmapPagesInZeroSpace(IN PVOID VirtualAddress, IN PFN_NUMBER NumberOfPages)
Definition: hypermap.c:183
#define IN
Definition: typedefs.h:39
PMMPTE MmLastReservedMappingPte
Definition: hypermap.c:20
MMPTE HyperTemplatePte
Definition: hypermap.c:22
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define MiAddressToPte(x)
Definition: mmx86.c:19
ULONG PFN_NUMBER
Definition: ke.h:9
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:969
PMMPTE MmFirstReservedMappingPte
Definition: hypermap.c:20
union _MMPTE::@2311 u
#define PsGetCurrentProcess
Definition: psfuncs.h:17
#define MI_HYPERSPACE_PTES
Definition: mm.h:81
static WCHAR Address[46]
Definition: ping.c:68
PFN_NUMBER Page
Definition: section.c:4757
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
VOID NTAPI MiUnmapPageInHyperSpace(IN PEPROCESS Process, IN PVOID Address, IN KIRQL OldIrql)
Definition: hypermap.c:91
#define ASSERT(a)
Definition: mode.c:44
PVOID NTAPI MiMapPageInHyperSpace(IN PEPROCESS Process, IN PFN_NUMBER Page, IN PKIRQL OldIrql)
Definition: hypermap.c:28
MMPTE ValidKernelPteLocal
Definition: init.c:33
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
MMPTE ValidKernelPte
Definition: init.c:29
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Definition: mm.h:345
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
LIST_HEAD(acpi_bus_event_list)
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:969
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
struct _MMPFN * PMMPFN
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
FORCEINLINE VOID KeFlushProcessTb(VOID)
Definition: ke.h:268
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
FORCEINLINE PFN_NUMBER MiGetPfnEntryIndex(IN PMMPFN Pfn1)
Definition: mm.h:989
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
PMMPTE MiFirstReservedZeroingPte
Definition: hypermap.c:21
FORCEINLINE PVOID MiPteToAddress(PMMPTE PointerPte)
Definition: mm.h:201
#define MI_ZERO_PTES
Definition: mm.h:82
#define PFN_FROM_PTE(v)
Definition: mm.h:92
ULONG PageFrameNumber
Definition: mmtypes.h:109