ReactOS 0.4.15-dev-7842-g558ab78
MmMdl.c File Reference
#include <kmt_test.h>
Include dependency graph for MmMdl.c:

Go to the source code of this file.

Functions

static VOID TestMmAllocatePagesForMdl (VOID)
 
static VOID TestMmBuildMdlForNonPagedPool (VOID)
 
 START_TEST (MmMdl)
 

Function Documentation

◆ START_TEST()

START_TEST ( MmMdl  )

Definition at line 240 of file MmMdl.c.

241{
244}
static VOID TestMmAllocatePagesForMdl(VOID)
Definition: MmMdl.c:13
static VOID TestMmBuildMdlForNonPagedPool(VOID)
Definition: MmMdl.c:194

◆ TestMmAllocatePagesForMdl()

static VOID TestMmAllocatePagesForMdl ( VOID  )
static

Definition at line 13 of file MmMdl.c.

14{
15 PMDL Mdl;
16 PHYSICAL_ADDRESS LowAddress;
19 PVOID SystemVa;
20 PMDL Mdls[32];
21 PVOID SystemVas[32];
22 ULONG i;
23 PPFN_NUMBER MdlPages;
24 ULONG MdlPageCount;
25
26 LowAddress.QuadPart = 0;
29 /* simple allocate/free */
30 Mdl = MmAllocatePagesForMdl(LowAddress,
33 2 * 1024 * 1024);
34 ok(Mdl != NULL, "MmAllocatePagesForMdl failed\n");
35 if (skip(Mdl != NULL, "No Mdl\n"))
36 return;
37 ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
38 ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
39 ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
40 MdlPages = MmGetMdlPfnArray(Mdl);
42 ok(MdlPageCount == 2 * 1024 * 1024 / PAGE_SIZE, "MdlPageCount = %lu\n", MdlPageCount);
43 for (i = 0; i < MdlPageCount; i++)
44 {
45 ok(MdlPages[i] != 0 && MdlPages[i] != (PFN_NUMBER)-1,
46 "MdlPages[%lu] = 0x%I64x\n", i, (ULONGLONG)MdlPages[i]);
47 }
50
51 /* Now map/unmap it */
52 Mdl = MmAllocatePagesForMdl(LowAddress,
55 2 * 1024 * 1024);
56 ok(Mdl != NULL, "MmAllocatePagesForMdl failed\n");
57 if (skip(Mdl != NULL, "No Mdl\n"))
58 return;
59 ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
60 ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
61 ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
65 NULL,
66 FALSE,
68 ok(SystemVa != NULL, "MmMapLockedPagesSpecifyCache failed\n");
69 if (!skip(SystemVa != NULL, "No system VA\n"))
70 {
71 ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
72 ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p, System VA: %p\n", MmGetMdlVirtualAddress(Mdl), SystemVa);
73 ok(Mdl->MappedSystemVa == SystemVa, "MappedSystemVa: %p, System VA: %p\n", Mdl->MappedSystemVa, SystemVa);
74 ok((Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
75 MmUnmapLockedPages(SystemVa, Mdl);
76 }
77 ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
78 ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
79 ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
82
83 /* Now map it, and free without unmapping */
84 Mdl = MmAllocatePagesForMdl(LowAddress,
87 2 * 1024 * 1024);
88 ok(Mdl != NULL, "MmAllocatePagesForMdl failed\n");
89 if (skip(Mdl != NULL, "No Mdl\n"))
90 return;
91 ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
92 ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
93 ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
97 NULL,
98 FALSE,
100 ok(SystemVa != NULL, "MmMapLockedPagesSpecifyCache failed\n");
101 ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
102 ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p, System VA: %p\n", MmGetMdlVirtualAddress(Mdl), SystemVa);
103 ok(Mdl->MappedSystemVa == SystemVa, "MappedSystemVa: %p, System VA: %p\n", Mdl->MappedSystemVa, SystemVa);
104 ok((Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
107
108 /* try to allocate 2 GB -- should succeed (possibly with fewer pages) but not map */
109 Mdl = MmAllocatePagesForMdl(LowAddress,
111 SkipBytes,
112 2UL * 1024 * 1024 * 1024);
113 ok(Mdl != NULL, "MmAllocatePagesForMdl failed for 2 GB\n");
114 if (Mdl != NULL)
115 {
116 ok(MmGetMdlByteCount(Mdl) <= 2UL * 1024 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
117 ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
118 ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
119 MdlPages = MmGetMdlPfnArray(Mdl);
121 ok(MdlPageCount <= 2UL * 1024 * 1024 * 1024 / PAGE_SIZE, "MdlPageCount = %lu\n", MdlPageCount);
122 for (i = 0; i < MdlPageCount; i++)
123 {
124 if (MdlPages[i] == 0 ||
125 MdlPages[i] == (PFN_NUMBER)-1)
126 {
127 ok(0, "MdlPages[%lu] = 0x%I64x\n", i, (ULONGLONG)MdlPages[i]);
128 }
129 }
132 MmCached,
133 NULL,
134 FALSE,
136 ok(SystemVa == NULL, "MmMapLockedPagesSpecifyCache succeeded for 2 GB\n");
137 if (SystemVa != NULL)
138 MmUnmapLockedPages(SystemVa, Mdl);
139 ok(MmGetMdlByteCount(Mdl) <= 2UL * 1024 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
140 ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
141 ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
144 }
145
146 /* now allocate and map 32 MB Mdls until we fail */
147 for (i = 0; i < sizeof(Mdls) / sizeof(Mdls[0]); i++)
148 {
149 Mdls[i] = MmAllocatePagesForMdl(LowAddress,
151 SkipBytes,
152 32 * 1024 * 1024);
153 if (Mdls[i] == NULL)
154 {
155 trace("MmAllocatePagesForMdl failed with i = %lu\n", i);
156 break;
157 }
158 ok(MmGetMdlVirtualAddress(Mdls[i]) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdls[i]));
159 ok(!(Mdls[i]->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdls[i]->MdlFlags);
160 SystemVas[i] = MmMapLockedPagesSpecifyCache(Mdls[i],
162 MmCached,
163 NULL,
164 FALSE,
166 if (SystemVas[i] == NULL)
167 {
168 ok(MmGetMdlByteCount(Mdls[i]) <= 32 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdls[i]));
169 ok(MmGetMdlVirtualAddress(Mdls[i]) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdls[i]));
170 ok(!(Mdls[i]->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdls[i]->MdlFlags);
171 trace("MmMapLockedPagesSpecifyCache failed with i = %lu\n", i);
172 break;
173 }
174 ok(MmGetMdlByteCount(Mdls[i]) == 32 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdls[i]));
175 ok(MmGetMdlVirtualAddress(Mdls[i]) == NULL, "Virtual address: %p, System VA: %p\n", MmGetMdlVirtualAddress(Mdls[i]), SystemVas[i]);
176 ok(Mdls[i]->MappedSystemVa == SystemVas[i], "MappedSystemVa: %p\n", Mdls[i]->MappedSystemVa, SystemVas[i]);
177 ok((Mdls[i]->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdls[i]->MdlFlags);
178 }
179 for (i = 0; i < sizeof(Mdls) / sizeof(Mdls[0]); i++)
180 {
181 if (Mdls[i] == NULL)
182 break;
183 if (SystemVas[i] != NULL)
184 MmUnmapLockedPages(SystemVas[i], Mdls[i]);
185 MmFreePagesFromMdl(Mdls[i]);
186 ExFreePoolWithTag(Mdls[i], 0);
187 if (SystemVas[i] == NULL)
188 break;
189 }
190}
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#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
VOID NTAPI MmFreePagesFromMdl(IN PMDL Mdl)
Definition: mdlsup.c:564
PMDL NTAPI MmAllocatePagesForMdl(IN PHYSICAL_ADDRESS LowAddress, IN PHYSICAL_ADDRESS HighAddress, IN PHYSICAL_ADDRESS SkipBytes, IN SIZE_T TotalBytes)
Definition: mdlsup.c:489
PVOID NTAPI MmMapLockedPagesSpecifyCache(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN MEMORY_CACHING_TYPE CacheType, IN PVOID BaseAddress, IN ULONG BugCheckOnFailure, IN ULONG Priority)
Definition: mdlsup.c:660
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:837
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
@ NormalPagePriority
Definition: imports.h:56
#define KernelMode
Definition: asm.h:34
ULONG * PPFN_NUMBER
Definition: ke.h:9
ULONG PFN_NUMBER
Definition: ke.h:9
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define MmGetMdlByteCount(_Mdl)
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS HighAddress
Definition: mmfuncs.h:226
#define MmGetMdlVirtualAddress(_Mdl)
#define MmGetMdlPfnArray(_Mdl)
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
_Must_inspect_result_ _In_ PHYSICAL_ADDRESS _In_ PHYSICAL_ADDRESS SkipBytes
Definition: mmfuncs.h:227
@ MmCached
Definition: mmtypes.h:130
#define MDL_MAPPED_TO_SYSTEM_VA
Definition: mmtypes.h:18

Referenced by START_TEST().

◆ TestMmBuildMdlForNonPagedPool()

static VOID TestMmBuildMdlForNonPagedPool ( VOID  )
static

Definition at line 194 of file MmMdl.c.

195{
196 PVOID Page;
197 PMDL Mdl;
198
200 ok(Page != NULL, "ExAllocatePoolWithTag failed\n");
201 if (skip(Page != NULL, "No buffer\n"))
202 return;
203
205 ok(Mdl != NULL, "IoAllocateMdl failed\n");
206 if (skip(Mdl != NULL, "No MDL\n"))
207 return;
208
209 ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) == 0, "MDL locked\n");
210 ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
211
213 ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) == 0, "MDL locked\n");
214 ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) != 0, "MDL from paged\n");
215
216 IoFreeMdl(Mdl);
217 ExFreePoolWithTag(Page, 'Test');
218
220 ok(Page != NULL, "ExAllocatePoolWithTag failed\n");
221 if (skip(Page != NULL, "No buffer\n"))
222 return;
223
225 ok(Mdl != NULL, "IoAllocateMdl failed\n");
226 if (skip(Mdl != NULL, "No MDL\n"))
227 return;
228
229 ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) == 0, "MDL locked\n");
230 ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
231
233 ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) == 0, "MDL locked\n");
234 ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) != 0, "MDL from paged\n");
235
236 IoFreeMdl(Mdl);
237 ExFreePoolWithTag(Page, 'Test');
238}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
#define IoFreeMdl
Definition: fxmdl.h:89
#define IoAllocateMdl
Definition: fxmdl.h:88
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:424
_In_ PVOID _Out_opt_ BOOLEAN _Out_opt_ PPFN_NUMBER Page
Definition: mm.h:1306
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define MDL_SOURCE_IS_NONPAGED_POOL
Definition: mmtypes.h:20

Referenced by START_TEST().