[KMTESTS] Fixes for 2003, Vista, 7, 8, 10 x86 and x64 (#8175)

Fix several kmtests in preparation for testbots with newer versions of Windows. There's still more kmtests to fix, but this fixes all the kmtests that bugchecked during my testing.
This commit is contained in:
Carl J. Bialorucki 2025-07-03 14:33:59 -06:00 committed by GitHub
parent 83faff8706
commit 19e8fbb20e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 614 additions and 178 deletions

View file

@ -18,6 +18,8 @@
#include <kmt_platform.h>
#define GetNTVersion() ((SharedUserData->NtMajorVersion << 8) | SharedUserData->NtMinorVersion)
typedef VOID KMT_TESTFUNC(VOID);
typedef KMT_TESTFUNC *PKMT_TESTFUNC;

View file

@ -58,6 +58,7 @@ static PDEVICE_OBJECT MainDeviceObject;
PDRIVER_OBJECT KmtDriverObject = NULL;
static KMT_USER_WORK_LIST WorkList;
static ULONG RequestId = 0;
static const LONGLONG TimeoutDuration = -10LL * (1000 * 1000 * 10); // 10 seconds
/* Entry */
/**
@ -440,13 +441,19 @@ DriverIoControl(
{
PLIST_ENTRY Entry;
PKMT_USER_WORK_ENTRY WorkItem;
LARGE_INTEGER Timeout;
DPRINT("DriverIoControl. IOCTL_KMTEST_USERMODE_AWAIT_REQ, len=%lu\n",
IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength);
/* TODO: prevent multiple concurrent invocations */
Status = KeWaitForSingleObject(&WorkList.NewWorkEvent, UserRequest, UserMode, FALSE, NULL);
if (Status == STATUS_USER_APC || Status == STATUS_KERNEL_APC)
Timeout.QuadPart = TimeoutDuration;
Status = KeWaitForSingleObject(&WorkList.NewWorkEvent, UserRequest, UserMode, FALSE, &Timeout);
if (Status == STATUS_TIMEOUT)
DPRINT1("KeWaitForSingleObject timed out!\n");
if (Status == STATUS_USER_APC || Status == STATUS_KERNEL_APC || Status == STATUS_TIMEOUT)
break;
if (IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KMT_CALLBACK_REQUEST_PACKET))
@ -580,7 +587,7 @@ KmtUserModeCallback(
KeSetEvent(&WorkList.NewWorkEvent, IO_NO_INCREMENT, FALSE);
Timeout.QuadPart = -10 * 1000 * 1000 * 10; //wait for 10 seconds
Timeout.QuadPart = TimeoutDuration;
Status = KeWaitForSingleObject(&WorkEntry->WorkDoneEvent, Executive, UserMode, FALSE, &Timeout);
if (Status == STATUS_USER_APC || Status == STATUS_KERNEL_APC || Status == STATUS_TIMEOUT)

View file

@ -54,10 +54,13 @@ DpcHandler(
ok_eq_pointer(Dpc->SystemArgument2, SystemArgument2);
ok_eq_pointer(Dpc->DpcData, NULL);
ok_eq_uint(Prcb->DpcRoutineActive, 1);
/* this DPC is not in the list anymore, but it was at the head! */
ok_eq_pointer(Prcb->DpcData[DPC_NORMAL].DpcListHead.Flink, Dpc->DpcListEntry.Flink);
ok_eq_pointer(Prcb->DpcData[DPC_NORMAL].DpcListHead.Blink, Dpc->DpcListEntry.Blink);
if (GetNTVersion() == _WIN32_WINNT_WS03)
{
ok_eq_uint(Prcb->DpcRoutineActive, 1);
/* this DPC is not in the list anymore, but it was at the head! */
ok_eq_pointer(Prcb->DpcData[DPC_NORMAL].DpcListHead.Flink, Dpc->DpcListEntry.Flink);
ok_eq_pointer(Prcb->DpcData[DPC_NORMAL].DpcListHead.Blink, Dpc->DpcListEntry.Blink);
}
}
START_TEST(KeDpc)
@ -81,68 +84,74 @@ START_TEST(KeDpc)
ok_eq_uint(Dpc.Importance, DpcImportance);
ok_eq_uint(Dpc.Number, 0);
ok_eq_pointer(Dpc.DpcListEntry.Flink, (LIST_ENTRY *)0x5555555555555555LL);
ok_eq_pointer(Dpc.DpcListEntry.Blink, (LIST_ENTRY *)0x5555555555555555LL);
if (Dpc.DpcListEntry.Blink)
ok_eq_pointer(Dpc.DpcListEntry.Blink, (LIST_ENTRY *)0x5555555555555555LL);
ok_eq_pointer(Dpc.DeferredRoutine, DpcHandler);
ok_eq_pointer(Dpc.DeferredContext, &Dpc);
ok_eq_pointer(Dpc.SystemArgument1, (PVOID)0x5555555555555555LL);
ok_eq_pointer(Dpc.SystemArgument2, (PVOID)0x5555555555555555LL);
ok_eq_pointer(Dpc.DpcData, NULL);
/* simply run the Dpc a few times */
for (i = 0; i < 5; ++i)
if (GetNTVersion() < _WIN32_WINNT_WIN8)
{
ok_dpccount();
Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
ok_bool_true(Ret, "KeInsertQueueDpc returned");
++ExpectedDpcCount;
ok_dpccount();
}
// Windows 8+ is stricter about misusing DPC, these tests bugcheck there.
/* insert into queue at high irql
* -> should only run when lowered to APC_LEVEL,
* inserting a second time should fail
*/
KeRaiseIrql(APC_LEVEL, &Irql);
for (i = 0; i < 5; ++i)
{
KeRaiseIrql(DISPATCH_LEVEL, &Irql2);
ok_dpccount();
Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
ok_bool_true(Ret, "KeInsertQueueDpc returned");
Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xdef, (PVOID)0x123);
ok_bool_false(Ret, "KeInsertQueueDpc returned");
ok_dpccount();
KeRaiseIrql(HIGH_LEVEL, &Irql3);
/* simply run the Dpc a few times */
for (i = 0; i < 5; ++i)
{
ok_dpccount();
KeLowerIrql(Irql3);
ok_dpccount();
KeLowerIrql(Irql2);
++ExpectedDpcCount;
ok_dpccount();
}
KeLowerIrql(Irql);
Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
ok_bool_true(Ret, "KeInsertQueueDpc returned");
++ExpectedDpcCount;
ok_dpccount();
}
/* now test removing from the queue */
KeRaiseIrql(APC_LEVEL, &Irql);
for (i = 0; i < 5; ++i)
{
KeRaiseIrql(DISPATCH_LEVEL, &Irql2);
ok_dpccount();
Ret = KeRemoveQueueDpc(&Dpc);
ok_bool_false(Ret, "KeRemoveQueueDpc returned");
Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
ok_bool_true(Ret, "KeInsertQueueDpc returned");
ok_dpccount();
KeRaiseIrql(HIGH_LEVEL, &Irql3);
/* insert into queue at high irql
* -> should only run when lowered to APC_LEVEL,
* inserting a second time should fail
*/
KeRaiseIrql(APC_LEVEL, &Irql);
for (i = 0; i < 5; ++i)
{
KeRaiseIrql(DISPATCH_LEVEL, &Irql2);
ok_dpccount();
KeLowerIrql(Irql3);
ok_dpccount();
Ret = KeRemoveQueueDpc(&Dpc);
ok_bool_true(Ret, "KeRemoveQueueDpc returned");
KeLowerIrql(Irql2);
ok_dpccount();
Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
ok_bool_true(Ret, "KeInsertQueueDpc returned");
Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xdef, (PVOID)0x123);
ok_bool_false(Ret, "KeInsertQueueDpc returned");
ok_dpccount();
KeRaiseIrql(HIGH_LEVEL, &Irql3);
ok_dpccount();
KeLowerIrql(Irql3);
ok_dpccount();
KeLowerIrql(Irql2);
++ExpectedDpcCount;
ok_dpccount();
}
KeLowerIrql(Irql);
/* now test removing from the queue */
KeRaiseIrql(APC_LEVEL, &Irql);
for (i = 0; i < 5; ++i)
{
KeRaiseIrql(DISPATCH_LEVEL, &Irql2);
ok_dpccount();
Ret = KeRemoveQueueDpc(&Dpc);
ok_bool_false(Ret, "KeRemoveQueueDpc returned");
Ret = KeInsertQueueDpc(&Dpc, (PVOID)0xabc123, (PVOID)0x5678);
ok_bool_true(Ret, "KeInsertQueueDpc returned");
ok_dpccount();
KeRaiseIrql(HIGH_LEVEL, &Irql3);
ok_dpccount();
KeLowerIrql(Irql3);
ok_dpccount();
Ret = KeRemoveQueueDpc(&Dpc);
ok_bool_true(Ret, "KeRemoveQueueDpc returned");
KeLowerIrql(Irql2);
ok_dpccount();
}
KeLowerIrql(Irql);
}
KeLowerIrql(Irql);
/* parameter checks */
Status = STATUS_SUCCESS;
@ -153,8 +162,10 @@ START_TEST(KeDpc)
} _SEH2_END;
ok_eq_hex(Status, STATUS_SUCCESS);
if (!skip(Status == STATUS_SUCCESS, "KeInitializeDpc failed\n"))
if (!skip(Status == STATUS_SUCCESS, "KeInitializeDpc failed\n") &&
GetNTVersion() < _WIN32_WINNT_WIN8)
{
// Inserting NULL in a DPC gives a TIMER_OR_DPC_INVALID bugcheck on Windows 8+.
KeRaiseIrql(HIGH_LEVEL, &Irql);
Ret = KeInsertQueueDpc(&Dpc, NULL, NULL);
ok_bool_true(Ret, "KeInsertQueueDpc returned");

View file

@ -238,8 +238,10 @@ BOOLEAN TryNoRaise(PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData) {
\
if ((CheckData)->IsAcquired) \
ExpectedIrql = (CheckData)->IrqlWhenAcquired; \
ok_irql(ExpectedIrql); \
ok_bool_false(KeAreApcsDisabled(), "KeAreApcsDisabled returned"); \
if (GetNTVersion() < _WIN32_WINNT_WIN8) \
ok_irql(ExpectedIrql); \
if (GetNTVersion() == _WIN32_WINNT_WS03) \
ok_bool_false(KeAreApcsDisabled(), "KeAreApcsDisabled returned"); \
ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:"); \
} while (0)
@ -257,9 +259,15 @@ TestSpinLock(
if (SpinLock)
ok_eq_ulongptr(*SpinLock, 0);
CheckData->Acquire(SpinLock, CheckData);
CheckSpinLock(SpinLock, CheckData, 1);
#ifdef _M_IX86
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckSpinLock(SpinLock, CheckData, 1);
#endif
CheckData->Release(SpinLock, CheckData);
CheckSpinLock(SpinLock, CheckData, 0);
#ifdef _M_IX86
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckSpinLock(SpinLock, CheckData, 0);
#endif
if (CheckData->TryAcquire)
{
@ -295,19 +303,31 @@ TestSpinLock(
{
/* acquire/release without irql change */
CheckData->AcquireNoRaise(SpinLock, CheckData);
CheckSpinLock(SpinLock, CheckData, 1);
#ifdef _M_IX86
// Fails on x64 and Windows 8+
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckSpinLock(SpinLock, CheckData, 1);
#endif
CheckData->ReleaseNoLower(SpinLock, CheckData);
CheckSpinLock(SpinLock, CheckData, 0);
/* acquire without raise, but normal release */
CheckData->AcquireNoRaise(SpinLock, CheckData);
CheckSpinLock(SpinLock, CheckData, 1);
#ifdef _M_IX86
// Fails on x64 and Windows 8+
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckSpinLock(SpinLock, CheckData, 1);
#endif
CheckData->Release(SpinLock, CheckData);
CheckSpinLock(SpinLock, CheckData, 0);
/* acquire normally but release without lower */
CheckData->Acquire(SpinLock, CheckData);
CheckSpinLock(SpinLock, CheckData, 1);
#ifdef _M_IX86
// Fails on x64 and Windows 8+
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckSpinLock(SpinLock, CheckData, 1);
#endif
CheckData->ReleaseNoLower(SpinLock, CheckData);
CheckSpinLock(SpinLock, CheckData, 0);
CheckData->IsAcquired = FALSE;
@ -349,7 +369,7 @@ START_TEST(KeSpinLock)
PKSPIN_LOCK pSpinLock = &SpinLock;
KIRQL Irql, SynchIrql = KmtIsMultiProcessorBuild ? IPI_LEVEL - 2 : DISPATCH_LEVEL;
KIRQL OriginalIrqls[] = { PASSIVE_LEVEL, APC_LEVEL, DISPATCH_LEVEL, HIGH_LEVEL };
CHECK_DATA TestData[] =
CHECK_DATA TestDataWS03[] =
{
{ CheckLock, DISPATCH_LEVEL, AcquireNormal, ReleaseNormal, NULL, AcquireNoRaise, ReleaseNoLower, TryNoRaise },
{ CheckLock, DISPATCH_LEVEL, AcquireExp, ReleaseExp, NULL, AcquireExpNoRaise, ReleaseExpNoLower, NULL },
@ -363,6 +383,18 @@ START_TEST(KeSpinLock)
{ CheckQueue, DISPATCH_LEVEL, AcquireQueued, ReleaseQueued, TryQueued, NULL, NULL, NULL, LockQueuePfnLock },
{ CheckQueue, SynchIrql, AcquireQueuedSynch, ReleaseQueued, TryQueuedSynch, NULL, NULL, NULL, LockQueuePfnLock },
};
CHECK_DATA TestDataWin7[] =
{
{ CheckLock, DISPATCH_LEVEL, AcquireNormal, ReleaseNormal, NULL, AcquireNoRaise, ReleaseNoLower, TryNoRaise },
{ CheckLock, DISPATCH_LEVEL, AcquireExp, ReleaseExp, NULL, AcquireExpNoRaise, ReleaseExpNoLower, NULL },
{ CheckLock, DISPATCH_LEVEL, AcquireNormal, ReleaseNormal, NULL, AcquireInt, ReleaseInt, NULL },
{ CheckLock, SynchIrql, AcquireSynch, ReleaseNormal, NULL, NULL, NULL, NULL },
{ CheckQueueHandle, DISPATCH_LEVEL, AcquireInStackQueued, ReleaseInStackQueued, NULL, AcquireInStackNoRaise, ReleaseInStackNoRaise, NULL },
{ CheckQueueHandle, SynchIrql, AcquireInStackSynch, ReleaseInStackQueued, NULL, NULL, NULL, NULL },
{ CheckQueueHandle, DISPATCH_LEVEL, AcquireInStackQueued, ReleaseInStackQueued, NULL, AcquireInStackForDpc, ReleaseInStackForDpc, NULL },
};
CHECK_DATA *TestData;
ULONG TestElements;
int i, iIrql;
PKPRCB Prcb;
@ -398,7 +430,30 @@ START_TEST(KeSpinLock)
if (!KmtIsMultiProcessorBuild && !KmtIsCheckedBuild)
pSpinLock = NULL;
for (i = 0; i < sizeof TestData / sizeof TestData[0]; ++i)
switch (GetNTVersion())
{
case _WIN32_WINNT_VISTA:
#ifdef _M_X64
skip(FALSE, "This test is broken on Vista x64.\n");
goto done;
#endif
case _WIN32_WINNT_WS03:
TestData = TestDataWS03;
TestElements = RTL_NUMBER_OF(TestDataWS03);
break;
case _WIN32_WINNT_WIN7:
case _WIN32_WINNT_WIN8:
case _WIN32_WINNT_WINBLUE:
case _WIN32_WINNT_WIN10:
TestData = TestDataWin7;
TestElements = RTL_NUMBER_OF(TestDataWin7);
break;
default:
skip(FALSE, "Unknown NT version (0x%X).\n", GetNTVersion());
goto done;
}
for (i = 0; i < TestElements; ++i)
{
memset(&SpinLock, 0x55, sizeof SpinLock);
KeInitializeSpinLock(&SpinLock);
@ -423,6 +478,6 @@ START_TEST(KeSpinLock)
KeLowerIrql(Irql);
}
}
done:
KmtSetIrql(PASSIVE_LEVEL);
}

View file

@ -133,7 +133,9 @@ TestMmAllocatePagesForMdl(VOID)
NULL,
FALSE,
NormalPagePriority);
#ifdef _M_IX86
ok(SystemVa == NULL, "MmMapLockedPagesSpecifyCache succeeded for 2 GB\n");
#endif
if (SystemVa != NULL)
MmUnmapLockedPages(SystemVa, Mdl);
ok(MmGetMdlByteCount(Mdl) <= 2UL * 1024 * 1024 * 1024, "Byte count: %lu\n", MmGetMdlByteCount(Mdl));
@ -209,9 +211,13 @@ TestMmBuildMdlForNonPagedPool(VOID)
ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) == 0, "MDL locked\n");
ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
MmBuildMdlForNonPagedPool(Mdl);
ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) == 0, "MDL locked\n");
ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) != 0, "MDL from paged\n");
// This fails an assertion on Windows 8+ checked and can bugcheck Windows 10+ free.
if (GetNTVersion() < _WIN32_WINNT_WIN8)
{
MmBuildMdlForNonPagedPool(Mdl);
ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) == 0, "MDL locked\n");
ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) != 0, "MDL from paged\n");
}
IoFreeMdl(Mdl);
ExFreePoolWithTag(Page, 'Test');

View file

@ -9,7 +9,6 @@
#include <kmt_test.h>
static BOOLEAN g_IsPae;
static ULONG g_OsVersion;
static BOOLEAN g_IsReactOS;
#ifdef _M_IX86
@ -81,6 +80,12 @@ ValidateMapping(
ULONGLONG PteValue, ExpectedValue;
ULONG i;
#ifdef _M_AMD64
if (skip(GetNTVersion() < _WIN32_WINNT_WIN10,
"Win10 1607+ breaks these next tests.\n"))
return Valid;
#endif
for (i = 0; i < ValidPtes; i++)
{
CurrentAddress = (PUCHAR)BaseAddress + i * PAGE_SIZE;
@ -106,22 +111,42 @@ ValidateMapping(
}
CurrentAddress = (PUCHAR)BaseAddress - 1 * PAGE_SIZE;
PteValue = GET_PTE_VALUE(CurrentAddress);
if (skip(GetNTVersion() < _WIN32_WINNT_WIN10,
"DVRT (Win10 1607+) breaks these next tests.\n"))
return Valid;
#ifdef _M_AMD64
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
ExpectedValue = ((PoolTag & ~1ULL) + 1) << 28;
else if (GetNTVersion() >= _WIN32_WINNT_VISTA)
#else
if (GetNTVersion() >= _WIN32_WINNT_VISTA)
#endif
ExpectedValue = ((PoolTag & ~1ULL) + 1) << 32;
else
ExpectedValue = PoolTag & ~1ULL;
Valid = Valid &&
ok(PteValue == (PoolTag & ~1ULL),
"PTE for %p contains 0x%I64x, expected %x\n",
CurrentAddress, PteValue, PoolTag & ~1);
ok(PteValue == ExpectedValue,
"PTE for %p contains 0x%I64x, expected 0x%I64x\n",
CurrentAddress, PteValue, ExpectedValue);
CurrentAddress = (PUCHAR)BaseAddress - 2 * PAGE_SIZE;
PteValue = GET_PTE_VALUE(CurrentAddress);
if (g_IsReactOS || g_OsVersion >= 0x0600)
#ifdef _M_AMD64
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
{
ExpectedValue = (TotalPtes + 2) << 28;
}
else if (g_IsReactOS || GetNTVersion() >= _WIN32_WINNT_VISTA)
#else
if (g_IsReactOS || GetNTVersion() >= _WIN32_WINNT_VISTA)
#endif
{
/* On ReactOS and on Vista+ the size is stored in
* the NextEntry field of a MMPTE_LIST structure */
#ifdef _M_IX86
ExpectedValue = (TotalPtes + 2) << 12;
#elif defined(_M_AMD64)
ExpectedValue = ((ULONG64)TotalPtes + 2) << 32;
#endif
}
else
{
@ -130,7 +155,7 @@ ValidateMapping(
}
Valid = Valid &&
ok(PteValue == ExpectedValue,
"PTE for %p contains 0x%I64x, expected %x\n",
"PTE for %p contains 0x%I64x, expected 0x%I64x\n",
CurrentAddress, PteValue, ExpectedValue);
#endif
@ -187,6 +212,7 @@ TestMap(
KmtStartSeh()
*(volatile ULONG *)BaseAddress = 0x01234567;
ok_eq_ulong(*(volatile ULONG *)BaseAddress, 0x01234567);
KmtEndSeh(STATUS_SUCCESS);
MmUnmapReservedMapping(BaseAddress,
@ -205,13 +231,17 @@ TestMap(
ok(BaseAddress != NULL, "MmMapLockedPagesWithReservedMapping failed\n");
if (!skip(BaseAddress != NULL, "Failed to map MDL\n"))
{
ok_eq_pointer(BaseAddress, (PUCHAR)Mapping + sizeof(ULONG));
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
ok_eq_pointer(BaseAddress, (PVOID)ALIGN_DOWN_BY((PUCHAR)Mapping + sizeof(ULONG), 16));
else
ok_eq_pointer(BaseAddress, (PUCHAR)Mapping + sizeof(ULONG));
ok_bool_true(ValidateMapping(BaseAddress, TotalPtes, PoolTag, 1, MdlPages),
"ValidateMapping returned");
KmtStartSeh()
*(volatile ULONG *)BaseAddress = 0x01234567;
ok_eq_ulong(*(volatile ULONG *)BaseAddress, 0x01234567);
KmtEndSeh(STATUS_SUCCESS);
MmUnmapReservedMapping(BaseAddress,
@ -223,6 +253,7 @@ TestMap(
}
MmFreePagesFromMdl(Mdl);
ExFreePool(Mdl);
/* Map all pages */
Mdl = pMmAllocatePagesForMdlEx(ZeroPhysical,
@ -253,7 +284,8 @@ TestMap(
for (i = 0; i < TotalPtes; i++)
{
KmtStartSeh()
*((volatile ULONG *)BaseAddress + i * PAGE_SIZE / sizeof(ULONG)) = 0x01234567;
*((volatile ULONG *)((PUCHAR)BaseAddress + i * PAGE_SIZE)) = 0x01234567 + i;
ok_eq_ulong(*((volatile ULONG *)((PUCHAR)BaseAddress + i * PAGE_SIZE)), 0x01234567 + i);
KmtEndSeh(STATUS_SUCCESS);
}
@ -266,6 +298,7 @@ TestMap(
}
MmFreePagesFromMdl(Mdl);
ExFreePool(Mdl);
/* Try to map more pages than we reserved */
Mdl = pMmAllocatePagesForMdlEx(ZeroPhysical,
@ -292,6 +325,7 @@ TestMap(
}
MmFreePagesFromMdl(Mdl);
ExFreePool(Mdl);
}
START_TEST(MmReservedMapping)
@ -299,9 +333,9 @@ START_TEST(MmReservedMapping)
PVOID Mapping;
g_IsPae = ExIsProcessorFeaturePresent(PF_PAE_ENABLED);
g_OsVersion = SharedUserData->NtMajorVersion << 8 | SharedUserData->NtMinorVersion;
g_IsReactOS = *(PULONG)(KI_USER_SHARED_DATA + PAGE_SIZE - sizeof(ULONG)) == 0x8eac705;
ok(g_IsReactOS == 1, "Not reactos\n");
if (!g_IsReactOS)
trace("Not ReactOS\n");
pMmAllocatePagesForMdlEx = KmtGetSystemRoutineAddress(L"MmAllocatePagesForMdlEx");
@ -317,7 +351,7 @@ START_TEST(MmReservedMapping)
}
/* 10 pages */
Mapping = MmAllocateMappingAddress(10 * PAGE_SIZE, 'MRmK' & ~1);
Mapping = MmAllocateMappingAddress(10 * PAGE_SIZE, 'MRmK');
ok(Mapping != NULL, "MmAllocateMappingAddress failed\n");
if (!skip(Mapping != NULL, "No mapping\n"))
{

View file

@ -96,15 +96,31 @@ TestCreateSection(
IN HANDLE FileHandle2,
IN PFILE_OBJECT FileObject2)
{
NTSTATUS Status = STATUS_SUCCESS;
NTSTATUS Status = STATUS_SUCCESS, ExceptionStatus = STATUS_SUCCESS;
PVOID SectionObject;
LARGE_INTEGER MaximumSize;
ULONG PointerCount1, PointerCount2;
KmtStartSeh()
_SEH2_TRY
{
Status = MmCreateSection(NULL, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL);
KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
ExceptionStatus = _SEH2_GetExceptionCode();
}
_SEH2_END;
if (GetNTVersion() < _WIN32_WINNT_WIN10)
{
ok_eq_hex(ExceptionStatus, STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);
}
else
{
ok_eq_hex(ExceptionStatus, STATUS_ACCESS_VIOLATION);
ok_eq_hex(Status, STATUS_SUCCESS);
}
if (!KmtIsCheckedBuild)
{
@ -119,10 +135,26 @@ TestCreateSection(
}
SectionObject = KmtInvalidPointer;
KmtStartSeh()
_SEH2_TRY
{
Status = MmCreateSection(&SectionObject, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL);
KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
ExceptionStatus = _SEH2_GetExceptionCode();
}
_SEH2_END;
if (GetNTVersion() < _WIN32_WINNT_WIN10)
{
ok_eq_hex(ExceptionStatus, STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);
}
else
{
ok_eq_hex(ExceptionStatus, STATUS_ACCESS_VIOLATION);
ok_eq_hex(Status, STATUS_SUCCESS);
}
ok_eq_pointer(SectionObject, KmtInvalidPointer);
if (SectionObject && SectionObject != KmtInvalidPointer)
@ -211,8 +243,21 @@ TestCreateSection(
if (!skip(FileHandle1 != NULL && FileObject1 != NULL &&
FileHandle2 != NULL && FileObject2 != NULL, "No file handle or object\n"))
{
PointerCount1 = 3;
PointerCount2 = 3;
if (GetNTVersion() < _WIN32_WINNT_WIN8)
{
PointerCount1 = 3;
PointerCount2 = 3;
}
else
{
#ifdef _M_IX86
PointerCount1 = 31;
PointerCount2 = 33;
#else
PointerCount1 = 32767;
PointerCount2 = 32769;
#endif
}
/* image section */
CheckObject(FileHandle2, PointerCount2, 1L);
SectionObject = KmtInvalidPointer;
@ -224,45 +269,64 @@ TestCreateSection(
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PointerCount2 -= 2;
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, SEC_IMAGE);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckSection(SectionObject, SEC_IMAGE);
TestMapView(SectionObject, FALSE, TRUE);
if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PointerCount2--;
CheckObject(FileHandle2, PointerCount2, 1L);
SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject2);
KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
//++PointerCount2;
if (GetNTVersion() == _WIN32_WINNT_WS03)
++PointerCount2;
else if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount2;
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, SEC_IMAGE);
TestMapView(SectionObject, FALSE, TRUE);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, TRUE);
if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
//--PointerCount2; // ????
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PointerCount2--;
CheckObject(FileHandle2, PointerCount2, 1L);
SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject2);
KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PointerCount2--;
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, SEC_IMAGE);
TestMapView(SectionObject, FALSE, TRUE);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, TRUE);
if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
@ -277,40 +341,58 @@ TestCreateSection(
ok_eq_hex(Status, STATUS_INVALID_IMAGE_NOT_MZ);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok_eq_pointer(SectionObject, KmtInvalidPointer);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PointerCount1 -= 2;
CheckObject(FileHandle1, PointerCount1, 1L);
if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PointerCount1--;
CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject1);
KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
++PointerCount1;
if (GetNTVersion() == _WIN32_WINNT_WS03)
++PointerCount1;
else if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
//--PointerCount1; // ????
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject1);
KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
@ -319,34 +401,56 @@ TestCreateSection(
ObDereferenceObject(SectionObject);
/* image section with two different files */
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2);
KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
{
--PointerCount1;
--PointerCount2;
}
CheckObject(FileHandle1, PointerCount1, 1L);
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, SEC_IMAGE);
TestMapView(SectionObject, FALSE, TRUE);
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, TRUE);
if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1);
KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
if (GetNTVersion() < _WIN32_WINNT_WIN8)
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
{
--PointerCount1;
--PointerCount2;
}
CheckObject(FileHandle1, PointerCount1, 1L);
CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, 0);
@ -356,6 +460,8 @@ TestCreateSection(
ObDereferenceObject(SectionObject);
/* data file section */
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
@ -366,30 +472,39 @@ TestCreateSection(
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PointerCount1 -= 2;
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, FileObject1);
KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1;
@ -400,13 +515,18 @@ TestCreateSection(
ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n");
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
--PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L);
}
}
@ -700,7 +820,10 @@ TestPhysicalMemorySection(VOID)
ViewUnmap,
0,
PAGE_READWRITE);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
if (GetNTVersion() < _WIN32_WINNT_WIN10)
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
else
ok_eq_hex(Status, STATUS_SUCCESS);
if (NT_SUCCESS(Status))
{
KmtStartSeh()
@ -746,7 +869,10 @@ TestPhysicalMemorySection(VOID)
ViewUnmap,
0,
PAGE_READWRITE);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
if (GetNTVersion() < _WIN32_WINNT_WIN10)
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
else
ok_eq_hex(Status, STATUS_SUCCESS);
if (NT_SUCCESS(Status))
{
KmtStartSeh()
@ -788,7 +914,7 @@ TestPhysicalMemorySection(VOID)
ZwClose(SectionHandle);
/* Assertion failure: AllocationAttributes & SEC_IMAGE | SEC_RESERVE | SEC_COMMIT */
if (!KmtIsCheckedBuild)
if (!KmtIsCheckedBuild && !(GetNTVersion() >= _WIN32_WINNT_WIN10))
{
InitializeObjectAttributes(&ObjectAttributes,
NULL,
@ -808,22 +934,25 @@ TestPhysicalMemorySection(VOID)
ObDereferenceObject(SectionObject);
}
InitializeObjectAttributes(&ObjectAttributes,
NULL,
OBJ_KERNEL_HANDLE,
NULL,
NULL);
Status = MmCreateSection(&SectionObject,
SECTION_ALL_ACCESS,
&ObjectAttributes,
NULL,
PAGE_READWRITE,
SEC_RESERVE | 0x80000000,
NULL,
NULL);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
if (NT_SUCCESS(Status))
ObDereferenceObject(SectionObject);
if (GetNTVersion() < _WIN32_WINNT_WIN10)
{
InitializeObjectAttributes(&ObjectAttributes,
NULL,
OBJ_KERNEL_HANDLE,
NULL,
NULL);
Status = MmCreateSection(&SectionObject,
SECTION_ALL_ACCESS,
&ObjectAttributes,
NULL,
PAGE_READWRITE,
SEC_RESERVE | 0x80000000,
NULL,
NULL);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_6);
if (NT_SUCCESS(Status))
ObDereferenceObject(SectionObject);
}
ExFreePoolWithTag(ZeroPageContents, 'ZPmK');
ExFreePoolWithTag(MyPage, 'MPmK');
@ -866,7 +995,15 @@ START_TEST(MmSection)
ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_ulongptr(IoStatusBlock.Information, FILE_OPENED);
ok(FileHandle1 != NULL, "FileHandle1 is NULL\n");
CheckObject(FileHandle1, 2L, 1L);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckObject(FileHandle1, 2L, 1L);
#ifdef _M_IX86
else
CheckObject(FileHandle1, 33L, 1L);
#else
else
CheckObject(FileHandle1, 32769L, 1L);
#endif
InitializeObjectAttributes(&ObjectAttributes, &FileName2, OBJ_CASE_INSENSITIVE, NULL, NULL);
Status = ZwCreateFile(&FileHandle2, GENERIC_READ, &ObjectAttributes, &IoStatusBlock, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0);
@ -879,7 +1016,15 @@ START_TEST(MmSection)
Status = ObReferenceObjectByHandle(FileHandle1, FILE_READ_DATA | FILE_WRITE_DATA, *IoFileObjectType, KernelMode, (PVOID *)&FileObject1, NULL);
ok_eq_hex(Status, STATUS_SUCCESS);
ok(FileObject1 != NULL, "FileObject1 is NULL\n");
CheckObject(FileHandle1, 3L, 1L);
if (GetNTVersion() < _WIN32_WINNT_WIN8)
CheckObject(FileHandle1, 3L, 1L);
#ifdef _M_IX86
else
CheckObject(FileHandle1, 32L, 1L);
#else
else
CheckObject(FileHandle1, 32768L, 1L);
#endif
}
if (!skip(Status == STATUS_SUCCESS && FileHandle2 != NULL, "Failed to open file 2\n"))

View file

@ -473,7 +473,14 @@ BasicBehaviorChecks(HANDLE FileHandle)
Length.QuadPart = TestStringSize;
CREATE_SECTION(Section, (SECTION_ALL_ACCESS), NULL, Length, PAGE_READONLY, SEC_COMMIT, FileHandle, STATUS_SUCCESS, NO_HANDLE_CLOSE);
CheckObject(Section, 2, 1);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
#ifdef _M_IX86
CheckObject(Section, 33, 1);
#else
CheckObject(Section, 32769, 1);
#endif
else
CheckObject(Section, 2, 1);
CheckSection(Section, SEC_FILE, Length.QuadPart, STATUS_SUCCESS);
ZwClose(Section); //manually close it due to NO_HANDLE_CLOSE in CREATE_SECTION

View file

@ -10,6 +10,10 @@
#define IGNORE -99
#define NEW_CONTENT "NewContent"
#define NEW_CONTENT_LEN sizeof(NEW_CONTENT)
#define IsInvalidParamStatus(Status) \
(Status == STATUS_INVALID_PARAMETER || Status == STATUS_INVALID_PARAMETER_MIX || \
(Status >= STATUS_INVALID_PARAMETER_1 && Status <= STATUS_INVALID_PARAMETER_12))
#define ok_invalid_parameter(Status) ok(IsInvalidParamStatus(Status), "Invalid status code (0x%X)\n", Status)
static UNICODE_STRING FileReadOnlyPath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntdll.dll");
static UNICODE_STRING NtosImgPath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntoskrnl.exe");
@ -24,7 +28,10 @@ static OBJECT_ATTRIBUTES NtoskrnlFileObject;
#define TestMapView(SectionHandle, ProcessHandle, BaseAddress2, ZeroBits, CommitSize, SectionOffset, ViewSize2, InheritDisposition, AllocationType, Win32Protect, MapStatus, UnmapStatus) do \
{ \
Status = ZwMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress2, ZeroBits, CommitSize, SectionOffset, ViewSize2, InheritDisposition, AllocationType, Win32Protect); \
ok_eq_hex(Status, MapStatus); \
if (GetNTVersion() >= _WIN32_WINNT_WIN10 && IsInvalidParamStatus(MapStatus)) \
ok_invalid_parameter(MapStatus); \
else \
ok_eq_hex(Status, MapStatus); \
if (NT_SUCCESS(Status)) \
{ \
Status = ZwUnmapViewOfSection(ProcessHandle, BaseAddress); \
@ -161,9 +168,15 @@ SimpleErrorChecks(HANDLE FileHandleReadOnly, HANDLE FileHandleWriteOnly, HANDLE
}
//zero bits
#ifdef _M_IX86
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 1, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE, STATUS_SUCCESS, STATUS_SUCCESS);
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 5, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE, STATUS_SUCCESS, STATUS_SUCCESS);
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, -1, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE, STATUS_INVALID_PARAMETER_4, IGNORE);
#else
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 1, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE, GetNTVersion() >= _WIN32_WINNT_WIN8 ? STATUS_INVALID_PARAMETER_4 : STATUS_SUCCESS, STATUS_SUCCESS);
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 5, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE, GetNTVersion() >= _WIN32_WINNT_WIN8 ? STATUS_INVALID_PARAMETER_4 : STATUS_SUCCESS, STATUS_SUCCESS);
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, -1, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE, STATUS_SUCCESS, IGNORE);
#endif
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 20, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE, STATUS_NO_MEMORY, IGNORE);
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 21, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE, STATUS_NO_MEMORY, IGNORE);
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 22, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READWRITE, STATUS_INVALID_PARAMETER_4, IGNORE);
@ -207,7 +220,7 @@ SimpleErrorChecks(HANDLE FileHandleReadOnly, HANDLE FileHandleWriteOnly, HANDLE
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 0, 0, NULL, &ViewSize, ViewUnmap, MEM_RESERVE, PAGE_READWRITE, STATUS_SUCCESS, STATUS_SUCCESS);
TestMapView(PageFileSectionHandle, NtCurrentProcess(), &BaseAddress, 0, 0, NULL, &ViewSize, ViewUnmap, MEM_RESERVE, PAGE_READWRITE, STATUS_INVALID_PARAMETER_9, STATUS_SUCCESS);
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 0, 0, NULL, &ViewSize, ViewUnmap, (MEM_RESERVE | MEM_COMMIT), PAGE_READWRITE, STATUS_INVALID_PARAMETER_9, IGNORE);
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 0, 0, NULL, &ViewSize, ViewUnmap, (MEM_LARGE_PAGES | MEM_RESERVE), PAGE_READWRITE, STATUS_SUCCESS, STATUS_SUCCESS);
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 0, 0, NULL, &ViewSize, ViewUnmap, (MEM_LARGE_PAGES | MEM_RESERVE), PAGE_READWRITE, (NTSTATUS)(GetNTVersion() >= _WIN32_WINNT_WIN10 ? STATUS_INVALID_PARAMETER : STATUS_SUCCESS), STATUS_SUCCESS);
//win32protect
TestMapView(WriteSectionHandle, NtCurrentProcess(), &BaseAddress, 0, 0, NULL, &ViewSize, ViewUnmap, 0, PAGE_READONLY, STATUS_SUCCESS, STATUS_SUCCESS);
@ -258,7 +271,29 @@ AdvancedErrorChecks(HANDLE FileHandleReadOnly, HANDLE FileHandleWriteOnly)
//test first conditional branch
ViewSize = -1;
MmTestMapView(SectionObject, PsGetCurrentProcess(), &BaseAddress, 0, TestStringSize, &SectionOffset, &ViewSize, ViewUnmap, MEM_RESERVE, PAGE_READWRITE, STATUS_INVALID_VIEW_SIZE, IGNORE);
#ifdef _M_IX86
NTSTATUS MapStatus;
switch (GetNTVersion())
{
case _WIN32_WINNT_WIN8:
case _WIN32_WINNT_WINBLUE:
MapStatus = STATUS_INVALID_VIEW_SIZE;
break;
case _WIN32_WINNT_WIN10:
MapStatus = STATUS_CONFLICTING_ADDRESSES;
break;
default:
MapStatus = STATUS_SUCCESS;
break;
}
MmTestMapView(SectionObject, PsGetCurrentProcess(), &BaseAddress, 0, TestStringSize,
&SectionOffset, &ViewSize, ViewUnmap, MEM_RESERVE, PAGE_READWRITE, MapStatus, IGNORE);
#else
MmTestMapView(SectionObject, PsGetCurrentProcess(), &BaseAddress, 0, TestStringSize,
&SectionOffset, &ViewSize, ViewUnmap, MEM_RESERVE, PAGE_READWRITE, STATUS_INVALID_VIEW_SIZE, IGNORE);
#endif
//test second conditional branch
ViewSize = 1;
@ -286,7 +321,7 @@ CompareFileContents(HANDLE FileHandle, ULONG BufferLength, PVOID Buffer)
if (!skip((FileContent != NULL), "Error allocating memory for FileContent\n"))
{
Status = ZwReadFile(FileHandle, NULL, NULL, NULL, &IoStatusBlock, FileContent, BufferLength, &ByteOffset, NULL);
ok_eq_hex(Status, STATUS_SUCCESS);
ok(Status == STATUS_SUCCESS || Status == STATUS_PENDING, "Unexpected status (0x%X).\n", Status);
ok_eq_ulongptr(IoStatusBlock.Information, BufferLength);
Match = 0;
@ -310,9 +345,19 @@ SystemProcessWorker(PVOID StartContext)
SIZE_T Match;
LARGE_INTEGER SectionOffset;
OBJECT_ATTRIBUTES ObjectAttributes;
ULONG PtrCnt;
UNREFERENCED_PARAMETER(StartContext);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
#ifdef _M_IX86
PtrCnt = 64;
#else
PtrCnt = 65536;
#endif
else
PtrCnt = 4;
BaseAddress = NULL;
ViewSize = TestStringSize;
SectionOffset.QuadPart = 0;
@ -321,11 +366,15 @@ SystemProcessWorker(PVOID StartContext)
Status = ZwOpenSection(&SectionHandle, SECTION_ALL_ACCESS, &ObjectAttributes);
if (!skip(NT_SUCCESS(Status), "Error acquiring handle to section. Error = %p\n", Status))
{
CheckObject(SectionHandle, 4, 2);
CheckObject(SectionHandle, PtrCnt, 2);
Status = ZwMapViewOfSection(SectionHandle, NtCurrentProcess(), &BaseAddress, 0, TestStringSize, &SectionOffset, &ViewSize, ViewUnmap, 0, PAGE_READWRITE);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt -= 2;
//make sure ZwMapViewofSection doesn't touch the section ref counts.
CheckObject(SectionHandle, 4, 2);
CheckObject(SectionHandle, PtrCnt, 2);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt--;
if (!skip(NT_SUCCESS(Status), "Error mapping page file view in system process. Error = %p\n", Status))
{
@ -336,7 +385,7 @@ SystemProcessWorker(PVOID StartContext)
ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
//make sure ZwMapViewofSection doesn't touch the section ref counts.
CheckObject(SectionHandle, 4, 2);
CheckObject(SectionHandle, PtrCnt, 2);
}
ZwClose(SectionHandle);
@ -360,18 +409,30 @@ BehaviorChecks(HANDLE FileHandleReadOnly, HANDLE FileHandleWriteOnly)
LARGE_INTEGER MaximumSize;
SIZE_T Match;
SIZE_T ViewSize = 0;
ULONG PtrCnt;
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
#ifdef _M_IX86
PtrCnt = 34;
#else
PtrCnt = 32770;
#endif
else
PtrCnt = 3;
InitializeObjectAttributes(&ObjectAttributes, &SharedSectionName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
MaximumSize.QuadPart = TestStringSize;
SectionOffset.QuadPart = 0;
Status = ZwCreateSection(&WriteSectionHandle, SECTION_ALL_ACCESS, &ObjectAttributes, &MaximumSize, PAGE_READWRITE, SEC_COMMIT, FileHandleWriteOnly);
CheckObject(WriteSectionHandle, 3, 1);
CheckObject(WriteSectionHandle, PtrCnt, 1);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt -= 2;
ok(NT_SUCCESS(Status), "Error creating write section from file. Error = %p\n", Status);
//check for section reading/writing by comparing section content to a well-known value.
Status = ZwMapViewOfSection(WriteSectionHandle, NtCurrentProcess() ,&BaseAddress, 0, 0, &SectionOffset, &ViewSize, ViewUnmap, 0, PAGE_READWRITE);
CheckObject(WriteSectionHandle, 3, 1);
CheckObject(WriteSectionHandle, PtrCnt, 1);
if (!skip(NT_SUCCESS(Status), "Error mapping view with READ/WRITE priv. Error = %p\n", Status))
{
Match = RtlCompareMemory(BaseAddress, TestString, TestStringSize);
@ -505,6 +566,16 @@ PageFileBehaviorChecks()
SIZE_T Match;
PVOID ThreadObject;
OBJECT_ATTRIBUTES ObjectAttributes;
ULONG PtrCnt;
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
#ifdef _M_IX86
PtrCnt = 34;
#else
PtrCnt = 32770;
#endif
else
PtrCnt = 3;
MaxSectionSize.QuadPart = TestStringSize;
SectionOffset.QuadPart = 0;
@ -517,13 +588,15 @@ PageFileBehaviorChecks()
Status = ZwCreateSection(&PageFileSectionHandle, SECTION_ALL_ACCESS, &ObjectAttributes, &MaxSectionSize, PAGE_READWRITE, SEC_COMMIT, NULL);
if (!skip(NT_SUCCESS(Status), "Error creating page file section. Error = %p\n", Status))
{
CheckObject(PageFileSectionHandle, 3, 1);
CheckObject(PageFileSectionHandle, PtrCnt, 1);
Status = ZwMapViewOfSection(PageFileSectionHandle, NtCurrentProcess(), &BaseAddress, 0, TestStringSize, &SectionOffset, &ViewSize, ViewUnmap, 0, PAGE_READWRITE);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt -= 2;
if (!skip(NT_SUCCESS(Status), "Error mapping page file view. Error = %p\n", Status))
{
HANDLE SysThreadHandle;
CheckObject(PageFileSectionHandle, 3, 1);
CheckObject(PageFileSectionHandle, PtrCnt, 1);
//check also the SEC_COMMIT flag
Test_NtQueryVirtualMemory(BaseAddress, PAGE_SIZE, MEM_COMMIT, PAGE_READWRITE);

View file

@ -34,6 +34,7 @@ TestDuplicate(
{
NTSTATUS Status;
HANDLE NewHandle;
ULONG i, PtrCnt1, PtrCnt2;
struct
{
ACCESS_MASK DesiredAccess;
@ -59,10 +60,33 @@ TestDuplicate(
{ DIRECTORY_QUERY, OBJ_INHERIT, DUPLICATE_SAME_ACCESS | DUPLICATE_SAME_ATTRIBUTES,
DIRECTORY_ALL_ACCESS, 0 },
};
ULONG i;
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
{
#ifdef _M_IX86
PtrCnt1 = 65UL;
PtrCnt2 = 31UL;
#else
PtrCnt1 = 65537UL;
PtrCnt2 = 32767UL;
#endif
}
else
{
PtrCnt1 = 3UL;
PtrCnt2 = 2UL;
}
for (i = 0; i < RTL_NUMBER_OF(Tests); i++)
{
if (GetNTVersion() >= _WIN32_WINNT_WIN7 &&
Tests[i].RequestedAttributes == OBJ_KERNEL_HANDLE)
{
skip(FALSE, "Invalid on NT 6.1+\n");
continue;
}
trace("Test %lu\n", i);
Status = ZwDuplicateObject(ZwCurrentProcess(),
Handle,
@ -75,12 +99,18 @@ TestDuplicate(
if (!skip(NT_SUCCESS(Status), "DuplicateHandle failed\n"))
{
ok(IsUserHandle(NewHandle), "New handle = %p\n", NewHandle);
CheckObject(NewHandle, 3UL, 2UL, Tests[i].ExpectedAttributes, Tests[i].GrantedAccess);
CheckObject(Handle, 3UL, 2UL, 0UL, DIRECTORY_ALL_ACCESS);
CheckObject(NewHandle, PtrCnt1, 2UL, Tests[i].ExpectedAttributes, Tests[i].GrantedAccess);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt1--;
CheckObject(Handle, PtrCnt1, 2UL, 0UL, DIRECTORY_ALL_ACCESS);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt1--;
Status = ObCloseHandle(NewHandle, UserMode);
ok_eq_hex(Status, STATUS_SUCCESS);
CheckObject(Handle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
CheckObject(Handle, PtrCnt2, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt2 -= 2;
}
}
@ -96,19 +126,26 @@ TestDuplicate(
if (!skip(NT_SUCCESS(Status), "DuplicateHandle failed\n"))
{
ok(IsKernelHandle(NewHandle), "New handle = %p\n", NewHandle);
CheckObject(NewHandle, 3UL, 2UL, 0, DIRECTORY_ALL_ACCESS);
CheckObject(Handle, 3UL, 2UL, 0UL, DIRECTORY_ALL_ACCESS);
CheckObject(NewHandle, PtrCnt1, 2UL, 0, DIRECTORY_ALL_ACCESS);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt1--;
CheckObject(Handle, PtrCnt1, 2UL, 0UL, DIRECTORY_ALL_ACCESS);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt1--;
Status = ObCloseHandle(NewHandle, UserMode);
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
CheckObject(NewHandle, 3UL, 2UL, 0, DIRECTORY_ALL_ACCESS);
CheckObject(Handle, 3UL, 2UL, 0UL, DIRECTORY_ALL_ACCESS);
CheckObject(NewHandle, PtrCnt1, 2UL, 0, DIRECTORY_ALL_ACCESS);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt1--;
CheckObject(Handle, PtrCnt1, 2UL, 0UL, DIRECTORY_ALL_ACCESS);
if (IsKernelHandle(NewHandle))
{
Status = ObCloseHandle(NewHandle, KernelMode);
ok_eq_hex(Status, STATUS_SUCCESS);
CheckObject(Handle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
PtrCnt2--;
CheckObject(Handle, PtrCnt2, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
}
}
}
@ -145,7 +182,14 @@ START_TEST(ObHandle)
if (!skip(NT_SUCCESS(Status), "No directory handle\n"))
{
ok(IsUserHandle(UserDirectoryHandle), "User handle = %p\n", UserDirectoryHandle);
CheckObject(UserDirectoryHandle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
#ifdef _M_IX86
CheckObject(UserDirectoryHandle, 33UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
#else
CheckObject(UserDirectoryHandle, 32769UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
#endif
else
CheckObject(UserDirectoryHandle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
TestDuplicate(UserDirectoryHandle);
@ -165,13 +209,27 @@ START_TEST(ObHandle)
if (!skip(NT_SUCCESS(Status), "No directory handle\n"))
{
ok(IsKernelHandle(KernelDirectoryHandle), "Kernel handle = %p\n", KernelDirectoryHandle);
CheckObject(KernelDirectoryHandle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
#ifdef _M_IX86
CheckObject(KernelDirectoryHandle, 33UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
#else
CheckObject(KernelDirectoryHandle, 32769UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
#endif
else
CheckObject(KernelDirectoryHandle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
TestDuplicate(KernelDirectoryHandle);
Status = ObCloseHandle(KernelDirectoryHandle, UserMode);
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
CheckObject(KernelDirectoryHandle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
#ifdef _M_IX86
CheckObject(KernelDirectoryHandle, 17UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
#else
CheckObject(KernelDirectoryHandle, 32753UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
#endif
else
CheckObject(KernelDirectoryHandle, 2UL, 1UL, 0UL, DIRECTORY_ALL_ACCESS);
Status = ObCloseHandle(KernelDirectoryHandle, KernelMode);
ok_eq_hex(Status, STATUS_SUCCESS);
@ -191,10 +249,16 @@ START_TEST(ObHandle)
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
DPRINT("Closing -1 kernel handle (NtClose)\n");
Status = NtClose(LongToHandle(0xFFFFFFFF));
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
if (GetNTVersion() >= _WIN32_WINNT_WIN10)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
DPRINT("Closing 123 handle (NtClose)\n");
Status = NtClose(LongToHandle(123));
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
if (GetNTVersion() >= _WIN32_WINNT_WIN8)
ok_eq_hex(Status, STATUS_SUCCESS);
else if (GetNTVersion() != _WIN32_WINNT_WS03)
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
DPRINT("Closing 123 kernel handle (NtClose)\n");
Status = NtClose(LongToHandle(123 | 0x80000000));
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
@ -211,7 +275,10 @@ START_TEST(ObHandle)
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
DPRINT("Closing -1 kernel handle (ObCloseHandle, UserMode)\n");
Status = ObCloseHandle(LongToHandle(0xFFFFFFFF), UserMode);
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
if (GetNTVersion() >= _WIN32_WINNT_WIN10)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
DPRINT("Closing 123 handle (ObCloseHandle, UserMode)\n");
Status = ObCloseHandle(LongToHandle(123), UserMode);
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
@ -230,7 +297,10 @@ START_TEST(ObHandle)
Status = ZwClose((HANDLE)0x7FFFFFFF);*/
DPRINT("Closing -1 kernel handle (ZwClose)\n");
Status = ZwClose(LongToHandle(0xFFFFFFFF));
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
if (GetNTVersion() >= _WIN32_WINNT_WIN10)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
/* INVALID_KERNEL_HANDLE, 0x7B, 1, 0, 0
Status = ZwClose(LongToHandle(123));
Status = ZwClose(LongToHandle(123 | 0x80000000));*/
@ -246,7 +316,10 @@ START_TEST(ObHandle)
Status = ObCloseHandle((HANDLE)0x7FFFFFFF, KernelMode);*/
DPRINT("Closing -1 kernel handle (ObCloseHandle, KernelMode)\n");
Status = ObCloseHandle(LongToHandle(0xFFFFFFFF), KernelMode);
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
if (GetNTVersion() >= _WIN32_WINNT_WIN10)
ok_eq_hex(Status, STATUS_SUCCESS);
else
ok_eq_hex(Status, STATUS_INVALID_HANDLE);
/* INVALID_KERNEL_HANDLE, 0x7B, 1, 0, 0
Status = ObCloseHandle(LongToHandle(123), KernelMode);
Status = ObCloseHandle(LongToHandle(123 | 0x80000000), KernelMode);*/

View file

@ -151,7 +151,7 @@ static OB_SECURITY_METHOD SeDefaultObjectMethod;
static
VOID
TestObjectTypes(VOID)
TestWin2003ObjectTypes(VOID)
{
ULONG Index;
@ -258,5 +258,13 @@ TestObjectTypes(VOID)
START_TEST(ObTypes)
{
TestObjectTypes();
switch (GetNTVersion())
{
case _WIN32_WINNT_WS03:
TestWin2003ObjectTypes();
break;
default:
skip(FALSE, "FIXME: kmtest:ObTypes is invalid for this NT version (0x%X).\n", GetNTVersion());
break;
}
}

View file

@ -253,9 +253,13 @@ START_TEST(RtlMemory)
RtlCopyMemoryNonTemporal(Buffer + 13, Buffer + 62, 95);
ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
#ifdef _M_IX86
MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
RtlCopyMemoryNonTemporal(Buffer + 78, Buffer + 43, 107);
ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
#else
skip(FALSE, "FIXME: This part of the test is broken on x64.\n");
#endif
KeLowerIrql(Irql);
Status = STATUS_SUCCESS;

View file

@ -25,6 +25,7 @@ TestStackWalk4(VOID)
ULONG ExpectedHash;
ULONG i;
const ULONG FunctionSizeGuess = 0x1000;
NTSTATUS ExceptionStatus = STATUS_SUCCESS;
ReturnAddresses[3] = _ReturnAddress();
@ -56,9 +57,19 @@ TestStackWalk4(VOID)
ok_eq_pointer(Frames[3], ReturnAddresses[1]);
ok_eq_pointer(Frames[4], (PVOID)(ULONG_PTR)0x5555555555555555);
KmtStartSeh()
_SEH2_TRY
{
RtlCaptureStackBackTrace(0, 5, NULL, NULL);
KmtEndSeh(STATUS_ACCESS_VIOLATION);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
ExceptionStatus = _SEH2_GetExceptionCode();
}
_SEH2_END;
if (GetNTVersion() == _WIN32_WINNT_WS03)
ok_eq_hex(ExceptionStatus, STATUS_ACCESS_VIOLATION);
else
ok_eq_hex(ExceptionStatus, STATUS_SUCCESS);
RtlFillMemory(Frames, sizeof(Frames), 0x55);
Hash = 0x55555555;
@ -157,7 +168,7 @@ TestRtlPcToFileHeader(VOID)
#ifdef NTOS_MODE_USER
Teb = NtCurrentTeb();
#else
Teb = KeGetCurrentThread()->Teb;
Teb = PsGetCurrentThreadTeb();
#endif
ok(Teb != NULL, "Teb is NULL!\n");
if (Teb == NULL)