mirror of
https://github.com/reactos/reactos.git
synced 2024-07-04 19:54:58 +00:00
[KMTESTS:MM]
- Add some more reserved mapping tests for special pool tags and unaligned addresses - Validate MDL pages in MmMdl test svn path=/trunk/; revision=69169
This commit is contained in:
parent
62d6fa7706
commit
317b564ba0
|
@ -19,6 +19,8 @@ TestMmAllocatePagesForMdl(VOID)
|
||||||
PMDL Mdls[32];
|
PMDL Mdls[32];
|
||||||
PVOID SystemVas[32];
|
PVOID SystemVas[32];
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
PPFN_NUMBER MdlPages;
|
||||||
|
ULONG MdlPageCount;
|
||||||
|
|
||||||
LowAddress.QuadPart = 0;
|
LowAddress.QuadPart = 0;
|
||||||
HighAddress.QuadPart = -1;
|
HighAddress.QuadPart = -1;
|
||||||
|
@ -34,6 +36,14 @@ TestMmAllocatePagesForMdl(VOID)
|
||||||
ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
|
ok(MmGetMdlByteCount(Mdl) == 2 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
|
||||||
ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
|
ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
|
||||||
ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
|
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);
|
MmFreePagesFromMdl(Mdl);
|
||||||
ExFreePoolWithTag(Mdl, 0);
|
ExFreePoolWithTag(Mdl, 0);
|
||||||
|
|
||||||
|
@ -105,6 +115,14 @@ TestMmAllocatePagesForMdl(VOID)
|
||||||
ok(MmGetMdlByteCount(Mdl) != 2UL * 1024 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
|
ok(MmGetMdlByteCount(Mdl) != 2UL * 1024 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
|
||||||
ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
|
ok(MmGetMdlVirtualAddress(Mdl) == NULL, "Virtual address: %p\n", MmGetMdlVirtualAddress(Mdl));
|
||||||
ok(!(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA), "MdlFlags: %lx\n", Mdl->MdlFlags);
|
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,
|
SystemVa = MmMapLockedPagesSpecifyCache(Mdl,
|
||||||
KernelMode,
|
KernelMode,
|
||||||
MmCached,
|
MmCached,
|
||||||
|
|
|
@ -35,6 +35,7 @@ BOOLEAN
|
||||||
ValidateMapping(
|
ValidateMapping(
|
||||||
_In_ PVOID BaseAddress,
|
_In_ PVOID BaseAddress,
|
||||||
_In_ ULONG TotalPtes,
|
_In_ ULONG TotalPtes,
|
||||||
|
_In_ ULONG PoolTag,
|
||||||
_In_ ULONG ValidPtes,
|
_In_ ULONG ValidPtes,
|
||||||
_In_ PPFN_NUMBER Pfns)
|
_In_ PPFN_NUMBER Pfns)
|
||||||
{
|
{
|
||||||
|
@ -61,7 +62,7 @@ ValidateMapping(
|
||||||
ok_eq_hex(PointerPte[i].u.Long, 0UL);
|
ok_eq_hex(PointerPte[i].u.Long, 0UL);
|
||||||
}
|
}
|
||||||
Valid = Valid &&
|
Valid = Valid &&
|
||||||
ok_eq_tag(PointerPte[-1].u.Long, 'MRmK' & ~1);
|
ok_eq_tag(PointerPte[-1].u.Long, PoolTag & ~1);
|
||||||
Valid = Valid &&
|
Valid = Valid &&
|
||||||
ok_eq_ulong(PointerPte[-2].u.Long, (TotalPtes + 2) * 2);
|
ok_eq_ulong(PointerPte[-2].u.Long, (TotalPtes + 2) * 2);
|
||||||
#endif
|
#endif
|
||||||
|
@ -72,7 +73,9 @@ ValidateMapping(
|
||||||
static
|
static
|
||||||
VOID
|
VOID
|
||||||
TestMap(
|
TestMap(
|
||||||
_In_ PVOID Mapping)
|
_In_ PVOID Mapping,
|
||||||
|
_In_ ULONG TotalPtes,
|
||||||
|
_In_ ULONG PoolTag)
|
||||||
{
|
{
|
||||||
PMDL Mdl;
|
PMDL Mdl;
|
||||||
PHYSICAL_ADDRESS ZeroPhysical;
|
PHYSICAL_ADDRESS ZeroPhysical;
|
||||||
|
@ -99,14 +102,15 @@ TestMap(
|
||||||
MdlPages = (PVOID)(Mdl + 1);
|
MdlPages = (PVOID)(Mdl + 1);
|
||||||
|
|
||||||
BaseAddress = MmMapLockedPagesWithReservedMapping(Mapping,
|
BaseAddress = MmMapLockedPagesWithReservedMapping(Mapping,
|
||||||
'MRmK',
|
PoolTag,
|
||||||
Mdl,
|
Mdl,
|
||||||
MmCached);
|
MmCached);
|
||||||
if (BaseAddress)
|
ok(BaseAddress != NULL, "MmMapLockedPagesWithReservedMapping failed\n");
|
||||||
|
if (!skip(BaseAddress != NULL, "Failed to map MDL\n"))
|
||||||
{
|
{
|
||||||
ok_eq_pointer(BaseAddress, Mapping);
|
ok_eq_pointer(BaseAddress, Mapping);
|
||||||
|
|
||||||
ok_bool_true(ValidateMapping(BaseAddress, 10, 1, MdlPages),
|
ok_bool_true(ValidateMapping(BaseAddress, TotalPtes, PoolTag, 1, MdlPages),
|
||||||
"ValidateMapping returned");
|
"ValidateMapping returned");
|
||||||
|
|
||||||
KmtStartSeh()
|
KmtStartSeh()
|
||||||
|
@ -114,10 +118,35 @@ TestMap(
|
||||||
KmtEndSeh(STATUS_SUCCESS);
|
KmtEndSeh(STATUS_SUCCESS);
|
||||||
|
|
||||||
MmUnmapReservedMapping(BaseAddress,
|
MmUnmapReservedMapping(BaseAddress,
|
||||||
'MRmK',
|
PoolTag,
|
||||||
Mdl);
|
Mdl);
|
||||||
|
|
||||||
ok_bool_true(ValidateMapping(Mapping, 10, 0, NULL),
|
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");
|
"ValidateMapping returned");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +156,7 @@ TestMap(
|
||||||
Mdl = MmAllocatePagesForMdlEx(ZeroPhysical,
|
Mdl = MmAllocatePagesForMdlEx(ZeroPhysical,
|
||||||
MaxPhysical,
|
MaxPhysical,
|
||||||
ZeroPhysical,
|
ZeroPhysical,
|
||||||
10 * PAGE_SIZE,
|
TotalPtes * PAGE_SIZE,
|
||||||
MmCached,
|
MmCached,
|
||||||
0);
|
0);
|
||||||
if (skip(Mdl != NULL, "No MDL\n"))
|
if (skip(Mdl != NULL, "No MDL\n"))
|
||||||
|
@ -138,17 +167,18 @@ TestMap(
|
||||||
MdlPages = (PVOID)(Mdl + 1);
|
MdlPages = (PVOID)(Mdl + 1);
|
||||||
|
|
||||||
BaseAddress = MmMapLockedPagesWithReservedMapping(Mapping,
|
BaseAddress = MmMapLockedPagesWithReservedMapping(Mapping,
|
||||||
'MRmK',
|
PoolTag,
|
||||||
Mdl,
|
Mdl,
|
||||||
MmCached);
|
MmCached);
|
||||||
if (BaseAddress)
|
ok(BaseAddress != NULL, "MmMapLockedPagesWithReservedMapping failed\n");
|
||||||
|
if (!skip(BaseAddress != NULL, "Failed to map MDL\n"))
|
||||||
{
|
{
|
||||||
ok_eq_pointer(BaseAddress, Mapping);
|
ok_eq_pointer(BaseAddress, Mapping);
|
||||||
|
|
||||||
ok_bool_true(ValidateMapping(BaseAddress, 10, 10, MdlPages),
|
ok_bool_true(ValidateMapping(BaseAddress, TotalPtes, PoolTag, TotalPtes, MdlPages),
|
||||||
"ValidateMapping returned");
|
"ValidateMapping returned");
|
||||||
|
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < TotalPtes; i++)
|
||||||
{
|
{
|
||||||
KmtStartSeh()
|
KmtStartSeh()
|
||||||
*((volatile ULONG *)BaseAddress + i * PAGE_SIZE / sizeof(ULONG)) = 0x01234567;
|
*((volatile ULONG *)BaseAddress + i * PAGE_SIZE / sizeof(ULONG)) = 0x01234567;
|
||||||
|
@ -156,10 +186,10 @@ TestMap(
|
||||||
}
|
}
|
||||||
|
|
||||||
MmUnmapReservedMapping(BaseAddress,
|
MmUnmapReservedMapping(BaseAddress,
|
||||||
'MRmK',
|
PoolTag,
|
||||||
Mdl);
|
Mdl);
|
||||||
|
|
||||||
ok_bool_true(ValidateMapping(Mapping, 10, 0, NULL),
|
ok_bool_true(ValidateMapping(Mapping, TotalPtes, PoolTag, 0, NULL),
|
||||||
"ValidateMapping returned");
|
"ValidateMapping returned");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +199,7 @@ TestMap(
|
||||||
Mdl = MmAllocatePagesForMdlEx(ZeroPhysical,
|
Mdl = MmAllocatePagesForMdlEx(ZeroPhysical,
|
||||||
MaxPhysical,
|
MaxPhysical,
|
||||||
ZeroPhysical,
|
ZeroPhysical,
|
||||||
11 * PAGE_SIZE,
|
(TotalPtes + 1) * PAGE_SIZE,
|
||||||
MmCached,
|
MmCached,
|
||||||
0);
|
0);
|
||||||
if (skip(Mdl != NULL, "No MDL\n"))
|
if (skip(Mdl != NULL, "No MDL\n"))
|
||||||
|
@ -178,14 +208,14 @@ TestMap(
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseAddress = MmMapLockedPagesWithReservedMapping(Mapping,
|
BaseAddress = MmMapLockedPagesWithReservedMapping(Mapping,
|
||||||
'MRmK',
|
PoolTag,
|
||||||
Mdl,
|
Mdl,
|
||||||
MmCached);
|
MmCached);
|
||||||
ok_eq_pointer(BaseAddress, NULL);
|
ok_eq_pointer(BaseAddress, NULL);
|
||||||
if (BaseAddress)
|
if (BaseAddress)
|
||||||
{
|
{
|
||||||
MmUnmapReservedMapping(BaseAddress,
|
MmUnmapReservedMapping(BaseAddress,
|
||||||
'MRmK',
|
PoolTag,
|
||||||
Mdl);
|
Mdl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +231,7 @@ START_TEST(MmReservedMapping)
|
||||||
ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
|
ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
|
||||||
if (!skip(Mapping != NULL, "No mapping\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");
|
"ValidateMapping returned");
|
||||||
|
|
||||||
MmFreeMappingAddress(Mapping, 'MRmK');
|
MmFreeMappingAddress(Mapping, 'MRmK');
|
||||||
|
@ -212,7 +242,7 @@ START_TEST(MmReservedMapping)
|
||||||
ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
|
ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
|
||||||
if (!skip(Mapping != NULL, "No mapping\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");
|
"ValidateMapping returned");
|
||||||
|
|
||||||
/* PAGE_FAULT_IN_NONPAGED_AREA can't be caught with SEH */
|
/* PAGE_FAULT_IN_NONPAGED_AREA can't be caught with SEH */
|
||||||
|
@ -221,8 +251,42 @@ START_TEST(MmReservedMapping)
|
||||||
(void)*(volatile UCHAR *)Mapping;
|
(void)*(volatile UCHAR *)Mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestMap(Mapping);
|
TestMap(Mapping, 10, 'MRmK');
|
||||||
|
|
||||||
MmFreeMappingAddress(Mapping, '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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue