ReactOS 0.4.16-dev-250-g3ecd236
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 */
136
137 /* We only handle 1, 2, 4 and 8 byte requests */
138 if ((Size != 1) &&
139 (Size != 2) &&
140 (Size != 4) &&
141 (Size != 8))
142 {
143 /* Invalid size, fail */
144 KdpDprintf("MmDbgCopyMemory: Received Illegal Size 0x%lx\n",
145 Size);
147 }
148
149 /* The copy must be aligned */
150 if ((Address & (Size - 1)) != 0)
151 {
152 /* Not allowing unaligned access */
153 KdpDprintf("MmDbgCopyMemory: Received Unaligned Address 0x%I64x Size %lx\n",
154 Address,
155 Size);
157 }
158
159 /* Check for physical or virtual copy */
161 {
162 /* Physical: translate and map it to our mapping space */
164 Flags);
165
166 /* Check if translation failed */
167 if (!TargetAddress)
168 {
169 /* Fail */
170 KdpDprintf("MmDbgCopyMemory: Failed to Translate Physical Address %I64x\n",
171 Address);
172 return STATUS_UNSUCCESSFUL;
173 }
174
175 /* The address we received must be valid! */
177 }
178 else
179 {
180 /* Virtual; truncate it to avoid casts later down */
182
183 /* Make sure address is valid */
185 {
186 /* Fail */
187 KdpDprintf("MmDbgCopyMemory: Failing %s for invalid Virtual Address 0x%p\n",
188 Flags & MMDBG_COPY_WRITE ? "write" : "read",
190 return STATUS_UNSUCCESSFUL;
191 }
192
193 /* Not handling session space correctly yet */
195 {
196 /* FIXME */
197 }
198
199 /* If we are going to write to the address, then check if its writable */
200 PointerPte = MiAddressToPte(TargetAddress);
201 if ((Flags & MMDBG_COPY_WRITE) &&
202 (!MI_IS_PAGE_WRITEABLE(PointerPte)))
203 {
204 /* Not writable, we need to do a physical copy */
206
207 /* Calculate the physical address */
210
211 /* Translate the physical address */
213 Flags);
214
215 /* Check if translation failed */
216 if (!TargetAddress)
217 {
218 /* Fail */
219 KdpDprintf("MmDbgCopyMemory: Failed to translate for write %I64x (%I64x)\n",
221 Address);
222 return STATUS_UNSUCCESSFUL;
223 }
224 }
225 }
226
227 /* Check what kind of operation this is */
229 {
230 /* Write */
231 CopyDestination = TargetAddress;
232 CopySource = Buffer;
233 }
234 else
235 {
236 /* Read */
237 CopyDestination = Buffer;
238 CopySource = TargetAddress;
239 }
240
241 /* Do the copy */
242 switch (Size)
243 {
244 case 1:
245
246 /* 1 byte */
247 *(PUCHAR)CopyDestination = *(PUCHAR)CopySource;
248 break;
249
250 case 2:
251
252 /* 2 bytes */
253 *(PUSHORT)CopyDestination = *(PUSHORT)CopySource;
254 break;
255
256 case 4:
257
258 /* 4 bytes */
259 *(PULONG)CopyDestination = *(PULONG)CopySource;
260 break;
261
262 case 8:
263
264 /* 8 bytes */
265 *(PULONGLONG)CopyDestination = *(PULONGLONG)CopySource;
266 break;
267
268 /* Size is sanitized above */
270 }
271
272 /* Get rid of the mapping if this was a physical copy */
274 {
275 /* Unmap and flush it */
277 }
278
279 /* And we are done */
280 return STATUS_SUCCESS;
281}
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 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:1047
#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::@2337 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)