ReactOS 0.4.15-dev-5667-ged97270
mmdbg.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include <mm/ARM3/miarm.h>
Include dependency graph for mmdbg.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define MODULE_INVOLVED_IN_ARM3
 
#define KdpDprintf(...)
 

Functions

BOOLEAN NTAPI MmIsSessionAddress (IN PVOID Address)
 
PVOID NTAPI MiDbgTranslatePhysicalAddress (IN ULONG64 PhysicalAddress, IN ULONG Flags)
 
VOID NTAPI MiDbgUnTranslatePhysicalAddress (VOID)
 
 C_ASSERT (MMDBG_COPY_MAX_SIZE==8)
 
NTSTATUS NTAPI MmDbgCopyMemory (IN ULONG64 Address, IN PVOID Buffer, IN ULONG Size, IN ULONG Flags)
 

Variables

PVOID MiDebugMapping = MI_DEBUG_MAPPING
 
PMMPTE MmDebugPte = NULL
 

Macro Definition Documentation

◆ KdpDprintf

#define KdpDprintf (   ...)

Definition at line 19 of file mmdbg.c.

◆ MODULE_INVOLVED_IN_ARM3

#define MODULE_INVOLVED_IN_ARM3

Definition at line 15 of file mmdbg.c.

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file mmdbg.c.

Function Documentation

◆ C_ASSERT()

C_ASSERT ( MMDBG_COPY_MAX_SIZE  = =8)

◆ MiDbgTranslatePhysicalAddress()

PVOID NTAPI MiDbgTranslatePhysicalAddress ( IN ULONG64  PhysicalAddress,
IN ULONG  Flags 
)

Definition at line 37 of file mmdbg.c.

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}
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
PMMPTE MmDebugPte
Definition: mmdbg.c:31
#define KdpDprintf(...)
Definition: mmdbg.c:19
unsigned __int64 ULONG64
Definition: imports.h:198
FORCEINLINE VOID KeInvalidateTlbEntry(IN PVOID Address)
Definition: ke.h:264
#define MiPteToAddress(_Pte)
Definition: mm.h:116
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:1047
#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
MMPTE ValidKernelPte
Definition: init.c:29
ULONG PFN_NUMBER
Definition: ke.h:9
ULONG PageFrameNumber
Definition: mmtypes.h:109
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
#define BYTE_OFFSET(Va)

Referenced by MmDbgCopyMemory().

◆ MiDbgUnTranslatePhysicalAddress()

VOID NTAPI MiDbgUnTranslatePhysicalAddress ( VOID  )

Definition at line 103 of file mmdbg.c.

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}
BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress)
Definition: mmsup.c:174
#define ASSERT(a)
Definition: mode.c:44
union _MMPTE::@2303 u
ULONG_PTR Long
Definition: mmtypes.h:215

Referenced by MmDbgCopyMemory().

◆ MmDbgCopyMemory()

NTSTATUS NTAPI MmDbgCopyMemory ( IN ULONG64  Address,
IN PVOID  Buffer,
IN ULONG  Size,
IN ULONG  Flags 
)

Definition at line 124 of file mmdbg.c.

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}
Definition: bufpool.h:45
VOID NTAPI MiDbgUnTranslatePhysicalAddress(VOID)
Definition: mmdbg.c:103
BOOLEAN NTAPI MmIsSessionAddress(IN PVOID Address)
Definition: session.c:48
PVOID NTAPI MiDbgTranslatePhysicalAddress(IN ULONG64 PhysicalAddress, IN ULONG Flags)
Definition: mmdbg.c:37
#define MiAddressToPte(x)
Definition: mmx86.c:19
#define DEFAULT_UNREACHABLE
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:383
#define MI_IS_PAGE_WRITEABLE(x)
Definition: mm.h:106
#define MMDBG_COPY_PHYSICAL
Definition: mm.h:76
#define MMDBG_COPY_UNSAFE
Definition: mm.h:77
#define MMDBG_COPY_WRITE
Definition: mm.h:75
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
static WCHAR Address[46]
Definition: ping.c:68
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
uint32_t * PULONG
Definition: typedefs.h:59
void * PVOID
Definition: typedefs.h:50
uint16_t * PUSHORT
Definition: typedefs.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
#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_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER _Outptr_ PVOID * TargetAddress
Definition: iotypes.h:1037

Referenced by KdpCopyMemoryChunks().

◆ MmIsSessionAddress()

BOOLEAN NTAPI MmIsSessionAddress ( IN PVOID  Address)

Definition at line 48 of file session.c.

49{
50 /* Check if it is in range */
52}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MI_IS_SESSION_ADDRESS(Address)
Definition: miarm.h:171

Referenced by MmDbgCopyMemory().

Variable Documentation

◆ MiDebugMapping

PVOID MiDebugMapping = MI_DEBUG_MAPPING

Definition at line 30 of file mmdbg.c.

Referenced by MmArmInitSystem().

◆ MmDebugPte