Author: tfaber
Date: Thu Sep 10 11:16:53 2015
New Revision: 69169
URL:
http://svn.reactos.org/svn/reactos?rev=69169&view=rev
Log:
[KMTESTS:MM]
- Add some more reserved mapping tests for special pool tags and unaligned addresses
- Validate MDL pages in MmMdl test
Modified:
trunk/rostests/kmtests/ntos_mm/MmMdl.c
trunk/rostests/kmtests/ntos_mm/MmReservedMapping.c
Modified: trunk/rostests/kmtests/ntos_mm/MmMdl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/kmtests/ntos_mm/MmMdl.c?r…
==============================================================================
--- trunk/rostests/kmtests/ntos_mm/MmMdl.c [iso-8859-1] (original)
+++ trunk/rostests/kmtests/ntos_mm/MmMdl.c [iso-8859-1] Thu Sep 10 11:16:53 2015
@@ -19,6 +19,8 @@
PMDL Mdls[32];
PVOID SystemVas[32];
ULONG i;
+ PPFN_NUMBER MdlPages;
+ ULONG MdlPageCount;
LowAddress.QuadPart = 0;
HighAddress.QuadPart = -1;
@@ -34,6 +36,14 @@
ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n",
MmGetMdlByteCount(Mdl));
ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n",
MmGetMdlVirtualAddress(Mdl));
ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n",
Mdl->MdlFlags);
+ MdlPages = MmGetMdlPfnArray(Mdl);
+ MdlPageCount = ADDRESS_AND_SIZE_TO_SPAN_PAGES(MmGetMdlVirtualAddress(Mdl),
MmGetMdlByteCount(Mdl));
+ ok(MdlPageCount == 2 * 1024 * 1024 / PAGE_SIZE, "MdlPageCount = %lu\n",
MdlPageCount);
+ for (i = 0; i < MdlPageCount; i++)
+ {
+ ok(MdlPages[i] != 0 && MdlPages[i] != (PFN_NUMBER)-1,
+ "MdlPages[%lu] = 0x%I64x\n", i, (ULONGLONG)MdlPages[i]);
+ }
MmFreePagesFromMdl(Mdl);
ExFreePoolWithTag(Mdl, 0);
@@ -105,6 +115,14 @@
ok(MmGetMdlByteCount(Mdl) != 2UL * 1024 * 1024 * 1024, "Byte count:
%lu\n", MmGetMdlByteCount(Mdl));
ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n",
MmGetMdlVirtualAddress(Mdl));
ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags:
%lx\n", Mdl->MdlFlags);
+ MdlPages = MmGetMdlPfnArray(Mdl);
+ MdlPageCount = ADDRESS_AND_SIZE_TO_SPAN_PAGES(MmGetMdlVirtualAddress(Mdl),
MmGetMdlByteCount(Mdl));
+ ok(MdlPageCount < 2UL * 1024 * 1024 * 1024 / PAGE_SIZE, "MdlPageCount =
%lu\n", MdlPageCount);
+ for (i = 0; i < MdlPageCount; i++)
+ {
+ ok(MdlPages[i] != 0 && MdlPages[i] != (PFN_NUMBER)-1,
+ "MdlPages[%lu] = 0x%I64x\n", i, (ULONGLONG)MdlPages[i]);
+ }
SystemVa = MmMapLockedPagesSpecifyCache(Mdl,
KernelMode,
MmCached,
Modified: trunk/rostests/kmtests/ntos_mm/MmReservedMapping.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/kmtests/ntos_mm/MmReserve…
==============================================================================
--- trunk/rostests/kmtests/ntos_mm/MmReservedMapping.c [iso-8859-1] (original)
+++ trunk/rostests/kmtests/ntos_mm/MmReservedMapping.c [iso-8859-1] Thu Sep 10 11:16:53
2015
@@ -35,6 +35,7 @@
ValidateMapping(
_In_ PVOID BaseAddress,
_In_ ULONG TotalPtes,
+ _In_ ULONG PoolTag,
_In_ ULONG ValidPtes,
_In_ PPFN_NUMBER Pfns)
{
@@ -61,7 +62,7 @@
ok_eq_hex(PointerPte[i].u.Long, 0UL);
}
Valid = Valid &&
- ok_eq_tag(PointerPte[-1].u.Long, 'MRmK' & ~1);
+ ok_eq_tag(PointerPte[-1].u.Long, PoolTag & ~1);
Valid = Valid &&
ok_eq_ulong(PointerPte[-2].u.Long, (TotalPtes + 2) * 2);
#endif
@@ -72,7 +73,9 @@
static
VOID
TestMap(
- _In_ PVOID Mapping)
+ _In_ PVOID Mapping,
+ _In_ ULONG TotalPtes,
+ _In_ ULONG PoolTag)
{
PMDL Mdl;
PHYSICAL_ADDRESS ZeroPhysical;
@@ -99,14 +102,15 @@
MdlPages = (PVOID)(Mdl + 1);
BaseAddress = MmMapLockedPagesWithReservedMapping(Mapping,
- 'MRmK',
- Mdl,
- MmCached);
- if (BaseAddress)
+ PoolTag,
+ Mdl,
+ MmCached);
+ ok(BaseAddress != NULL, "MmMapLockedPagesWithReservedMapping failed\n");
+ if (!skip(BaseAddress != NULL, "Failed to map MDL\n"))
{
ok_eq_pointer(BaseAddress, Mapping);
- ok_bool_true(ValidateMapping(BaseAddress, 10, 1, MdlPages),
+ ok_bool_true(ValidateMapping(BaseAddress, TotalPtes, PoolTag, 1, MdlPages),
"ValidateMapping returned");
KmtStartSeh()
@@ -114,10 +118,35 @@
KmtEndSeh(STATUS_SUCCESS);
MmUnmapReservedMapping(BaseAddress,
- 'MRmK',
- Mdl);
-
- ok_bool_true(ValidateMapping(Mapping, 10, 0, NULL),
+ PoolTag,
+ Mdl);
+
+ ok_bool_true(ValidateMapping(Mapping, TotalPtes, PoolTag, 0, NULL),
+ "ValidateMapping returned");
+ }
+
+ /* Try again but at an unaligned address */
+ BaseAddress = MmMapLockedPagesWithReservedMapping((PUCHAR)Mapping + sizeof(ULONG),
+ PoolTag,
+ Mdl,
+ MmCached);
+ ok(BaseAddress != NULL, "MmMapLockedPagesWithReservedMapping failed\n");
+ if (!skip(BaseAddress != NULL, "Failed to map MDL\n"))
+ {
+ ok_eq_pointer(BaseAddress, (PUCHAR)Mapping + sizeof(ULONG));
+
+ ok_bool_true(ValidateMapping(BaseAddress, TotalPtes, PoolTag, 1, MdlPages),
+ "ValidateMapping returned");
+
+ KmtStartSeh()
+ *(volatile ULONG *)BaseAddress = 0x01234567;
+ KmtEndSeh(STATUS_SUCCESS);
+
+ MmUnmapReservedMapping(BaseAddress,
+ PoolTag,
+ Mdl);
+
+ ok_bool_true(ValidateMapping(Mapping, TotalPtes, PoolTag, 0, NULL),
"ValidateMapping returned");
}
@@ -127,7 +156,7 @@
Mdl = MmAllocatePagesForMdlEx(ZeroPhysical,
MaxPhysical,
ZeroPhysical,
- 10 * PAGE_SIZE,
+ TotalPtes * PAGE_SIZE,
MmCached,
0);
if (skip(Mdl != NULL, "No MDL\n"))
@@ -138,17 +167,18 @@
MdlPages = (PVOID)(Mdl + 1);
BaseAddress = MmMapLockedPagesWithReservedMapping(Mapping,
- 'MRmK',
- Mdl,
- MmCached);
- if (BaseAddress)
+ PoolTag,
+ Mdl,
+ MmCached);
+ ok(BaseAddress != NULL, "MmMapLockedPagesWithReservedMapping failed\n");
+ if (!skip(BaseAddress != NULL, "Failed to map MDL\n"))
{
ok_eq_pointer(BaseAddress, Mapping);
- ok_bool_true(ValidateMapping(BaseAddress, 10, 10, MdlPages),
- "ValidateMapping returned");
-
- for (i = 0; i < 10; i++)
+ ok_bool_true(ValidateMapping(BaseAddress, TotalPtes, PoolTag, TotalPtes,
MdlPages),
+ "ValidateMapping returned");
+
+ for (i = 0; i < TotalPtes; i++)
{
KmtStartSeh()
*((volatile ULONG *)BaseAddress + i * PAGE_SIZE / sizeof(ULONG)) =
0x01234567;
@@ -156,10 +186,10 @@
}
MmUnmapReservedMapping(BaseAddress,
- 'MRmK',
- Mdl);
-
- ok_bool_true(ValidateMapping(Mapping, 10, 0, NULL),
+ PoolTag,
+ Mdl);
+
+ ok_bool_true(ValidateMapping(Mapping, TotalPtes, PoolTag, 0, NULL),
"ValidateMapping returned");
}
@@ -169,7 +199,7 @@
Mdl = MmAllocatePagesForMdlEx(ZeroPhysical,
MaxPhysical,
ZeroPhysical,
- 11 * PAGE_SIZE,
+ (TotalPtes + 1) * PAGE_SIZE,
MmCached,
0);
if (skip(Mdl != NULL, "No MDL\n"))
@@ -178,14 +208,14 @@
}
BaseAddress = MmMapLockedPagesWithReservedMapping(Mapping,
- 'MRmK',
+ PoolTag,
Mdl,
MmCached);
ok_eq_pointer(BaseAddress, NULL);
if (BaseAddress)
{
MmUnmapReservedMapping(BaseAddress,
- 'MRmK',
+ PoolTag,
Mdl);
}
@@ -201,7 +231,7 @@
ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
if (!skip(Mapping != NULL, "No mapping\n"))
{
- ok_bool_true(ValidateMapping(Mapping, 1, 0, NULL),
+ ok_bool_true(ValidateMapping(Mapping, 1, 'MRmK', 0, NULL),
"ValidateMapping returned");
MmFreeMappingAddress(Mapping, 'MRmK');
@@ -212,7 +242,7 @@
ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
if (!skip(Mapping != NULL, "No mapping\n"))
{
- ok_bool_true(ValidateMapping(Mapping, 10, 0, NULL),
+ ok_bool_true(ValidateMapping(Mapping, 10, 'MRmK', 0, NULL),
"ValidateMapping returned");
/* PAGE_FAULT_IN_NONPAGED_AREA can't be caught with SEH */
@@ -221,8 +251,42 @@
(void)*(volatile UCHAR *)Mapping;
}
- TestMap(Mapping);
+ TestMap(Mapping, 10, 'MRmK');
MmFreeMappingAddress(Mapping, 'MRmK');
}
-}
+
+ /* PoolTag = 0 */
+ Mapping = MmAllocateMappingAddress(1, 0);
+ ok(Mapping == NULL, "MmAllocateMappingAddress failed\n");
+ if (Mapping != NULL)
+ {
+ MmFreeMappingAddress(Mapping, 0);
+ }
+
+ /* PoolTag = 1 */
+ Mapping = MmAllocateMappingAddress(1, 1);
+ ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
+ if (Mapping != NULL)
+ {
+ ok_bool_true(ValidateMapping(Mapping, 1, 1, 0, NULL),
+ "ValidateMapping returned");
+
+ TestMap(Mapping, 1, 1);
+
+ MmFreeMappingAddress(Mapping, 1);
+ }
+
+ /* Free an unaligned address */
+ Mapping = MmAllocateMappingAddress(PAGE_SIZE, 'MRmK');
+ ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
+ if (Mapping != NULL)
+ {
+ ok_bool_true(ValidateMapping(Mapping, 1, 'MRmK', 0, NULL),
+ "ValidateMapping returned");
+
+ TestMap(Mapping, 1, 'MRmK');
+
+ MmFreeMappingAddress((PUCHAR)Mapping + sizeof(ULONG), 'MRmK');
+ }
+}