ReactOS 0.4.16-dev-737-g3368adc
mmdbg.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/mmdbg.c
5 * PURPOSE: Memory Manager support routines for the Kernel Debugger
6 * PROGRAMMERS: Stefan Ginsberg (stefan.ginsberg@reactos.org)
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#ifdef NDEBUG
19#define KdpDprintf(...)
20#endif
21
26);
27
28/* GLOBALS ********************************************************************/
29
32
33/* FUNCTIONS ******************************************************************/
34
39{
40 PFN_NUMBER Pfn;
42 PVOID MappingBaseAddress;
43
44 /* Check if we are called too early */
45 if (MmDebugPte == NULL)
46 {
47 /* The structures we require aren't initialized yet, fail */
48 KdpDprintf("MiDbgTranslatePhysicalAddress called too early! "
49 "Address: 0x%I64x\n",
51 return NULL;
52 }
53
54 /* FIXME: No support for cache flags yet */
55 if ((Flags & (MMDBG_COPY_CACHED |
58 {
59 /* Fail */
60 KdpDprintf("MiDbgTranslatePhysicalAddress: Cache flags not yet supported. "
61 "Flags: 0x%lx\n",
65 return NULL;
66 }
67
68 /* Save the base address of our mapping page */
69 MappingBaseAddress = MiPteToAddress(MmDebugPte);
70
71 /* Get the template */
73
74 /* Convert physical address to PFN */
76
77 /* Check if this could be an I/O mapping */
78 if (!MiGetPfnEntry(Pfn))
79 {
80 /* FIXME: We don't support this yet */
81 KdpDprintf("MiDbgTranslatePhysicalAddress: I/O Space not yet supported. "
82 "PFN: 0x%I64x\n",
83 (ULONG64)Pfn);
84 return NULL;
85 }
86 else
87 {
88 /* Set the PFN in the PTE */
89 TempPte.u.Hard.PageFrameNumber = Pfn;
90 }
91
92 /* Map the PTE and invalidate its TLB entry */
94 KeInvalidateTlbEntry(MappingBaseAddress);
95
96 /* Calculate and return the virtual offset into our mapping page */
97 return (PVOID)((ULONG_PTR)MappingBaseAddress +
99}
100
101VOID
102NTAPI
104{
105 PVOID MappingBaseAddress;
106
107 /* The address must still be valid at this point */
108 MappingBaseAddress = MiPteToAddress(MmDebugPte);
109 ASSERT(MmIsAddressValid(MappingBaseAddress));
110
111 /* Clear the mapping PTE and invalidate its TLB entry */
112 MmDebugPte->u.Long = 0;
113 KeInvalidateTlbEntry(MappingBaseAddress);
114}
115
116
117//
118// We handle 8-byte requests at most
119//
121
123NTAPI
126 IN ULONG Size,
127 IN ULONG Flags)
128{
131 PMMPTE PointerPte;
132 PVOID CopyDestination, CopySource;
133
134 /* No local kernel debugging support yet, so don't worry about locking */
135 if (!(Flags & MMDBG_COPY_UNSAFE))
136 {
137 static BOOLEAN Warned = FALSE;
138 if (!Warned)
139 {
140 KdpDprintf("MmDbgCopyMemory: not providing MMDBG_COPY_UNSAFE is UNIMPLEMENTED\n");
141 Warned = TRUE;
142 }
143 }
144
145 /* We only handle 1, 2, 4 and 8 byte requests */
146 if ((Size != 1) &&
147 (Size != 2) &&
148 (Size != 4) &&
149 (Size != 8))
150 {
151 /* Invalid size, fail */
152 KdpDprintf("MmDbgCopyMemory: Received Illegal Size 0x%lx\n",
153 Size);
155 }
156
157 /* The copy must be aligned */
158 if ((Address & (Size - 1)) != 0)
159 {
160 /* Not allowing unaligned access */
161 KdpDprintf("MmDbgCopyMemory: Received Unaligned Address 0x%I64x Size %lx\n",
162 Address,
163 Size);
165 }
166
167 /* Check for physical or virtual copy */
169 {
170 /* Physical: translate and map it to our mapping space */
172 Flags);
173
174 /* Check if translation failed */
175 if (!TargetAddress)
176 {
177 /* Fail */
178 KdpDprintf("MmDbgCopyMemory: Failed to Translate Physical Address %I64x\n",
179 Address);
180 return STATUS_UNSUCCESSFUL;
181 }
182
183 /* The address we received must be valid! */
185 }
186 else
187 {
188 /* Virtual; truncate it to avoid casts later down */
190
191 /* Make sure address is valid */
193 {
194 /* Fail */
195 KdpDprintf("MmDbgCopyMemory: Failing %s for invalid Virtual Address 0x%p\n",
196 Flags & MMDBG_COPY_WRITE ? "write" : "read",
198 return STATUS_UNSUCCESSFUL;
199 }
200
201 /* Not handling session space correctly yet */
203 {
204 /* FIXME */
205 }
206
207 /* If we are going to write to the address, then check if its writable */
208 PointerPte = MiAddressToPte(TargetAddress);
209 if ((Flags & MMDBG_COPY_WRITE) &&
210 (!MI_IS_PAGE_WRITEABLE(PointerPte)))
211 {
212 /* Not writable, we need to do a physical copy */
214
215 /* Calculate the physical address */
218
219 /* Translate the physical address */
221 Flags);
222
223 /* Check if translation failed */
224 if (!TargetAddress)
225 {
226 /* Fail */
227 KdpDprintf("MmDbgCopyMemory: Failed to translate for write %I64x (%I64x)\n",
229 Address);
230 return STATUS_UNSUCCESSFUL;
231 }
232 }
233 }
234
235 /* Check what kind of operation this is */
237 {
238 /* Write */
239 CopyDestination = TargetAddress;
240 CopySource = Buffer;
241 }
242 else
243 {
244 /* Read */
245 CopyDestination = Buffer;
246 CopySource = TargetAddress;
247 }
248
249 /* Do the copy */
250 switch (Size)
251 {
252 case 1:
253
254 /* 1 byte */
255 *(PUCHAR)CopyDestination = *(PUCHAR)CopySource;
256 break;
257
258 case 2:
259
260 /* 2 bytes */
261 *(PUSHORT)CopyDestination = *(PUSHORT)CopySource;
262 break;
263
264 case 4:
265
266 /* 4 bytes */
267 *(PULONG)CopyDestination = *(PULONG)CopySource;
268 break;
269
270 case 8:
271
272 /* 8 bytes */
273 *(PULONGLONG)CopyDestination = *(PULONGLONG)CopySource;
274 break;
275
276 /* Size is sanitized above */
278 }
279
280 /* Get rid of the mapping if this was a physical copy */
282 {
283 /* Unmap and flush it */
285 }
286
287 /* And we are done */
288 return STATUS_SUCCESS;
289}
unsigned char BOOLEAN
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ULONG_PTR
Definition: config.h:101
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
#define C_ASSERT(e)
Definition: intsafe.h:73
VOID NTAPI MiDbgUnTranslatePhysicalAddress(VOID)
Definition: mmdbg.c:103
BOOLEAN NTAPI MmIsSessionAddress(IN PVOID Address)
Definition: session.c:48
PMMPTE MmDebugPte
Definition: mmdbg.c:31
NTSTATUS NTAPI MmDbgCopyMemory(IN ULONG64 Address, IN PVOID Buffer, IN ULONG Size, IN ULONG Flags)
Definition: mmdbg.c:124
PVOID MiDebugMapping
Definition: mmdbg.c:30
#define KdpDprintf(...)
Definition: mmdbg.c:19
PVOID NTAPI MiDbgTranslatePhysicalAddress(IN ULONG64 PhysicalAddress, IN ULONG Flags)
Definition: mmdbg.c:37
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
#define MiAddressToPte(x)
Definition: mmx86.c:19
#define ASSERT(a)
Definition: mode.c:44
unsigned __int64 ULONG64
Definition: imports.h:198
#define DEFAULT_UNREACHABLE
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:391
FORCEINLINE VOID KeInvalidateTlbEntry(IN PVOID Address)
Definition: ke.h:264
#define MI_IS_PAGE_WRITEABLE(x)
Definition: mm.h:106
#define MI_DEBUG_MAPPING
Definition: mm.h:20
#define MiPteToAddress(_Pte)
Definition: mm.h:116
#define MMDBG_COPY_PHYSICAL
Definition: mm.h:76
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:1054
#define MMDBG_COPY_UNSAFE
Definition: mm.h:77
#define MMDBG_COPY_MAX_SIZE
Definition: mm.h:85
#define MMDBG_COPY_WRITE_COMBINED
Definition: mm.h:80
#define MMDBG_COPY_CACHED
Definition: mm.h:78
#define MMDBG_COPY_UNCACHED
Definition: mm.h:79
#define MMDBG_COPY_WRITE
Definition: mm.h:75
MMPTE ValidKernelPte
Definition: init.c:29
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
static WCHAR Address[46]
Definition: ping.c:68
ULONG PFN_NUMBER
Definition: ke.h:9
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG PageFrameNumber
Definition: mmtypes.h:109
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
union _MMPTE::@2342 u
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
ULONG_PTR Long
Definition: mmtypes.h:215
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
uint16_t * PUSHORT
Definition: typedefs.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER _Outptr_ PVOID * TargetAddress
Definition: iotypes.h:1037
#define BYTE_OFFSET(Va)