ReactOS 0.4.15-dev-7934-g1dc8d80
MmReservedMapping.c File Reference
#include <kmt_test.h>
Include dependency graph for MmReservedMapping.c:

Go to the source code of this file.

Functions

static _Must_inspect_result_ _IRQL_requires_max_ (DISPATCH_LEVEL)
 
static VOID TestMap (_In_ PVOID Mapping, _In_ ULONG TotalPtes, _In_ ULONG PoolTag)
 
 START_TEST (MmReservedMapping)
 

Variables

static BOOLEAN g_IsPae
 

Function Documentation

◆ _IRQL_requires_max_()

static _Must_inspect_result_ _IRQL_requires_max_ ( DISPATCH_LEVEL  )
static

Definition at line 56 of file MmReservedMapping.c.

75{
76 BOOLEAN Valid = TRUE;
77#if defined(_M_IX86) || defined(_M_AMD64)
78 PUCHAR CurrentAddress;
79 ULONGLONG PteValue;
80 ULONG i;
81
82 for (i = 0; i < ValidPtes; i++)
83 {
84 CurrentAddress = (PUCHAR)BaseAddress + i * PAGE_SIZE;
85 PteValue = GET_PTE_VALUE(CurrentAddress);
86 Valid = Valid &&
87 ok(PTE_IS_VALID(PteValue),
88 "[%lu] PTE for %p is not valid (0x%I64x)\n",
89 i, CurrentAddress, PteValue);
90
91 Valid = Valid &&
92 ok(PTE_GET_PFN(PteValue) == Pfns[i],
93 "[%lu] PTE for %p has PFN %Ix, expected %Ix\n",
94 i, CurrentAddress, PTE_GET_PFN(PteValue), Pfns[i]);
95 }
96 for (; i < TotalPtes; i++)
97 {
98 CurrentAddress = (PUCHAR)BaseAddress + i * PAGE_SIZE;
99 PteValue = GET_PTE_VALUE(CurrentAddress);
100 Valid = Valid &&
101 ok(PteValue == 0,
102 "[%lu] PTE for %p is nonzero (0x%I64x)\n",
103 i, CurrentAddress, PteValue);
104 }
105 CurrentAddress = (PUCHAR)BaseAddress - 1 * PAGE_SIZE;
106 PteValue = GET_PTE_VALUE(CurrentAddress);
107 Valid = Valid &&
108 ok(PteValue == (PoolTag & ~1ULL),
109 "PTE for %p contains 0x%I64x, expected %x\n",
110 CurrentAddress, PteValue, PoolTag & ~1);
111 CurrentAddress = (PUCHAR)BaseAddress - 2 * PAGE_SIZE;
112 PteValue = GET_PTE_VALUE(CurrentAddress);
113 Valid = Valid &&
114 ok(PteValue == (TotalPtes + 2) * 2,
115 "PTE for %p contains 0x%I64x, expected %x\n",
116 CurrentAddress, PteValue, (TotalPtes + 2) * 2);
117#endif
118
119 return Valid;
120}
unsigned char BOOLEAN
#define ok(value,...)
Definition: atltest.h:57
#define TRUE
Definition: types.h:120
#define PAGE_SIZE
Definition: env_spec_w32.h:49
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
Definition: wdfmemory.h:164

◆ START_TEST()

START_TEST ( MmReservedMapping  )

Definition at line 279 of file MmReservedMapping.c.

280{
282
284
285 pMmAllocatePagesForMdlEx = KmtGetSystemRoutineAddress(L"MmAllocatePagesForMdlEx");
286
287 /* one byte - single page */
289 ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
290 if (!skip(Mapping != NULL, "No mapping\n"))
291 {
292 ok_bool_true(ValidateMapping(Mapping, 1, 'MRmK', 0, NULL),
293 "ValidateMapping returned");
294
296 }
297
298 /* 10 pages */
299 Mapping = MmAllocateMappingAddress(10 * PAGE_SIZE, 'MRmK' & ~1);
300 ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
301 if (!skip(Mapping != NULL, "No mapping\n"))
302 {
303 ok_bool_true(ValidateMapping(Mapping, 10, 'MRmK', 0, NULL),
304 "ValidateMapping returned");
305
306 /* PAGE_FAULT_IN_NONPAGED_AREA can't be caught with SEH */
307 if (0)
308 {
309 (void)*(volatile UCHAR *)Mapping;
310 }
311
312 TestMap(Mapping, 10, 'MRmK');
313
315 }
316
317 /* PoolTag = 0 */
319 ok(Mapping == NULL, "MmAllocateMappingAddress failed\n");
320 if (Mapping != NULL)
321 {
323 }
324
325 /* PoolTag = 1 */
327 ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
328 if (Mapping != NULL)
329 {
330 ok_bool_true(ValidateMapping(Mapping, 1, 1, 0, NULL),
331 "ValidateMapping returned");
332
333 TestMap(Mapping, 1, 1);
334
336 }
337
338 /* Free an unaligned address */
340 ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
341 if (Mapping != NULL)
342 {
343 ok_bool_true(ValidateMapping(Mapping, 1, 'MRmK', 0, NULL),
344 "ValidateMapping returned");
345
346 TestMap(Mapping, 1, 'MRmK');
347
348 MmFreeMappingAddress((PUCHAR)Mapping + sizeof(ULONG), 'MRmK');
349 }
350}
static BOOLEAN g_IsPae
#define ok_bool_true(value, desc)
Definition: apitest.h:78
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
static PVOID Mapping[EMS_PHYSICAL_PAGES]
Definition: emsdrv.c:41
PVOID KmtGetSystemRoutineAddress(IN PCWSTR RoutineName)
BOOLEAN NTAPI ExIsProcessorFeaturePresent(IN ULONG ProcessorFeature)
Definition: sysinfo.c:363
VOID NTAPI MmFreeMappingAddress(IN PVOID BaseAddress, IN ULONG PoolTag)
Definition: pool.c:1572
PVOID NTAPI MmAllocateMappingAddress(IN SIZE_T NumberOfBytes, IN ULONG PoolTag)
Definition: pool.c:1560
#define L(x)
Definition: ntvdm.h:50
EH_STD::__hash_map__< TestClass, TestClass, ThrowHash, ThrowEqual, eh_allocator(TestClass) > TestMap
#define PF_PAE_ENABLED
Definition: ketypes.h:133
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ TestMap()

static VOID TestMap ( _In_ PVOID  Mapping,
_In_ ULONG  TotalPtes,
_In_ ULONG  PoolTag 
)
static

Definition at line 124 of file MmReservedMapping.c.

128{
129 PMDL Mdl;
130 PHYSICAL_ADDRESS ZeroPhysical;
131 PHYSICAL_ADDRESS MaxPhysical;
133 PPFN_NUMBER MdlPages;
134 ULONG i;
135
136 if (skip(pMmAllocatePagesForMdlEx != NULL, "MmAllocatePagesForMdlEx unavailable\n"))
137 {
138 return;
139 }
140
141 ZeroPhysical.QuadPart = 0;
142 MaxPhysical.QuadPart = 0xffffffffffffffffLL;
143
144 /* Create a one-page MDL and map it */
145 Mdl = pMmAllocatePagesForMdlEx(ZeroPhysical,
146 MaxPhysical,
147 ZeroPhysical,
148 PAGE_SIZE,
149 MmCached,
150 0);
151 if (skip(Mdl != NULL, "No MDL\n"))
152 {
153 return;
154 }
155
156 MdlPages = (PVOID)(Mdl + 1);
157
159 PoolTag,
160 Mdl,
161 MmCached);
162 ok(BaseAddress != NULL, "MmMapLockedPagesWithReservedMapping failed\n");
163 if (!skip(BaseAddress != NULL, "Failed to map MDL\n"))
164 {
166
167 ok_bool_true(ValidateMapping(BaseAddress, TotalPtes, PoolTag, 1, MdlPages),
168 "ValidateMapping returned");
169
171 *(volatile ULONG *)BaseAddress = 0x01234567;
173
175 PoolTag,
176 Mdl);
177
178 ok_bool_true(ValidateMapping(Mapping, TotalPtes, PoolTag, 0, NULL),
179 "ValidateMapping returned");
180 }
181
182 /* Try again but at an unaligned address */
184 PoolTag,
185 Mdl,
186 MmCached);
187 ok(BaseAddress != NULL, "MmMapLockedPagesWithReservedMapping failed\n");
188 if (!skip(BaseAddress != NULL, "Failed to map MDL\n"))
189 {
191
192 ok_bool_true(ValidateMapping(BaseAddress, TotalPtes, PoolTag, 1, MdlPages),
193 "ValidateMapping returned");
194
196 *(volatile ULONG *)BaseAddress = 0x01234567;
198
200 PoolTag,
201 Mdl);
202
203 ok_bool_true(ValidateMapping(Mapping, TotalPtes, PoolTag, 0, NULL),
204 "ValidateMapping returned");
205 }
206
208
209 /* Map all pages */
210 Mdl = pMmAllocatePagesForMdlEx(ZeroPhysical,
211 MaxPhysical,
212 ZeroPhysical,
213 TotalPtes * PAGE_SIZE,
214 MmCached,
215 0);
216 if (skip(Mdl != NULL, "No MDL\n"))
217 {
218 return;
219 }
220
221 MdlPages = (PVOID)(Mdl + 1);
222
224 PoolTag,
225 Mdl,
226 MmCached);
227 ok(BaseAddress != NULL, "MmMapLockedPagesWithReservedMapping failed\n");
228 if (!skip(BaseAddress != NULL, "Failed to map MDL\n"))
229 {
231
232 ok_bool_true(ValidateMapping(BaseAddress, TotalPtes, PoolTag, TotalPtes, MdlPages),
233 "ValidateMapping returned");
234
235 for (i = 0; i < TotalPtes; i++)
236 {
238 *((volatile ULONG *)BaseAddress + i * PAGE_SIZE / sizeof(ULONG)) = 0x01234567;
240 }
241
243 PoolTag,
244 Mdl);
245
246 ok_bool_true(ValidateMapping(Mapping, TotalPtes, PoolTag, 0, NULL),
247 "ValidateMapping returned");
248 }
249
251
252 /* Try to map more pages than we reserved */
253 Mdl = pMmAllocatePagesForMdlEx(ZeroPhysical,
254 MaxPhysical,
255 ZeroPhysical,
256 (TotalPtes + 1) * PAGE_SIZE,
257 MmCached,
258 0);
259 if (skip(Mdl != NULL, "No MDL\n"))
260 {
261 return;
262 }
263
265 PoolTag,
266 Mdl,
267 MmCached);
269 if (BaseAddress)
270 {
272 PoolTag,
273 Mdl);
274 }
275
277}
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
#define KmtStartSeh()
Definition: kmt_test.h:282
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:288
VOID NTAPI MmFreePagesFromMdl(IN PMDL Mdl)
Definition: mdlsup.c:564
VOID NTAPI MmUnmapReservedMapping(IN PVOID BaseAddress, IN ULONG PoolTag, IN PMDL MemoryDescriptorList)
Definition: mdlsup.c:1643
PVOID NTAPI MmMapLockedPagesWithReservedMapping(IN PVOID MappingAddress, IN ULONG PoolTag, IN PMDL MemoryDescriptorList, IN MEMORY_CACHING_TYPE CacheType)
Definition: mdlsup.c:1629
ULONG * PPFN_NUMBER
Definition: ke.h:9
#define STATUS_SUCCESS
Definition: shellext.h:65
void * PVOID
Definition: typedefs.h:50
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
@ MmCached
Definition: mmtypes.h:130

Variable Documentation

◆ g_IsPae

BOOLEAN g_IsPae
static

Definition at line 11 of file MmReservedMapping.c.

Referenced by START_TEST().