2011-07-09 22:02:54 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS kernel-mode tests
|
|
|
|
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Kernel-Mode Test Suite Asynchronous Procedure Call test
|
2013-10-12 16:05:54 +00:00
|
|
|
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
|
2011-07-09 22:02:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kmt_test.h>
|
|
|
|
|
2015-02-15 10:23:21 +00:00
|
|
|
static
|
|
|
|
_IRQL_requires_min_(PASSIVE_LEVEL)
|
|
|
|
_IRQL_requires_max_(DISPATCH_LEVEL)
|
|
|
|
BOOLEAN
|
|
|
|
(NTAPI
|
|
|
|
*pKeAreAllApcsDisabled)(VOID);
|
|
|
|
|
|
|
|
static
|
|
|
|
_Acquires_lock_(_Global_critical_region_)
|
|
|
|
_IRQL_requires_max_(APC_LEVEL)
|
|
|
|
VOID
|
|
|
|
(NTAPI
|
|
|
|
*pKeEnterGuardedRegion)(VOID);
|
|
|
|
|
|
|
|
static
|
|
|
|
_Releases_lock_(_Global_critical_region_)
|
|
|
|
_IRQL_requires_max_(APC_LEVEL)
|
|
|
|
VOID
|
|
|
|
(NTAPI
|
|
|
|
*pKeLeaveGuardedRegion)(VOID);
|
|
|
|
|
2011-07-22 12:01:48 +00:00
|
|
|
#define CheckApcs(KernelApcsDisabled, SpecialApcsDisabled, AllApcsDisabled, Irql) do \
|
|
|
|
{ \
|
|
|
|
ok_eq_bool(KeAreApcsDisabled(), KernelApcsDisabled || SpecialApcsDisabled); \
|
|
|
|
ok_eq_int(Thread->KernelApcDisable, KernelApcsDisabled); \
|
2015-02-15 10:23:21 +00:00
|
|
|
if (pKeAreAllApcsDisabled) \
|
|
|
|
ok_eq_bool(pKeAreAllApcsDisabled(), AllApcsDisabled); \
|
2011-07-22 12:01:48 +00:00
|
|
|
ok_eq_int(Thread->SpecialApcDisable, SpecialApcsDisabled); \
|
|
|
|
ok_irql(Irql); \
|
2011-07-09 22:02:54 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
START_TEST(KeApc)
|
|
|
|
{
|
|
|
|
KIRQL Irql;
|
2015-02-15 10:23:21 +00:00
|
|
|
PKTHREAD Thread;
|
|
|
|
|
|
|
|
pKeAreAllApcsDisabled = KmtGetSystemRoutineAddress(L"KeAreAllApcsDisabled");
|
|
|
|
pKeEnterGuardedRegion = KmtGetSystemRoutineAddress(L"KeEnterGuardedRegion");
|
|
|
|
pKeLeaveGuardedRegion = KmtGetSystemRoutineAddress(L"KeLeaveGuardedRegion");
|
|
|
|
|
|
|
|
if (skip(pKeAreAllApcsDisabled != NULL, "KeAreAllApcsDisabled unavailable\n"))
|
|
|
|
{
|
|
|
|
/* We can live without this function here */
|
|
|
|
}
|
|
|
|
|
|
|
|
Thread = KeGetCurrentThread();
|
2011-07-09 22:02:54 +00:00
|
|
|
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
|
|
|
/* critical region */
|
|
|
|
KeEnterCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-1, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeEnterCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-2, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeEnterCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-3, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-2, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-1, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
|
|
|
/* guarded region */
|
2015-02-15 10:23:21 +00:00
|
|
|
if (!skip(pKeEnterGuardedRegion &&
|
|
|
|
pKeLeaveGuardedRegion, "Guarded regions not available\n"))
|
|
|
|
{
|
|
|
|
pKeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
pKeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, -2, TRUE, PASSIVE_LEVEL);
|
|
|
|
pKeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, -3, TRUE, PASSIVE_LEVEL);
|
|
|
|
pKeLeaveGuardedRegion();
|
|
|
|
CheckApcs(0, -2, TRUE, PASSIVE_LEVEL);
|
|
|
|
pKeLeaveGuardedRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
pKeLeaveGuardedRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
2015-02-15 10:23:21 +00:00
|
|
|
/* mix them */
|
|
|
|
pKeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(-1, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
pKeLeaveGuardedRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
2015-02-15 10:23:21 +00:00
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(-1, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
pKeEnterGuardedRegion();
|
|
|
|
CheckApcs(-1, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
pKeLeaveGuardedRegion();
|
|
|
|
CheckApcs(-1, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
}
|
2011-07-22 12:01:48 +00:00
|
|
|
|
|
|
|
/* leave without entering */
|
2011-09-10 10:48:07 +00:00
|
|
|
if (!KmtIsCheckedBuild)
|
|
|
|
{
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(1, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-22 12:01:48 +00:00
|
|
|
|
2015-02-15 10:23:21 +00:00
|
|
|
if (!skip(pKeEnterGuardedRegion &&
|
|
|
|
pKeLeaveGuardedRegion, "Guarded regions not available\n"))
|
|
|
|
{
|
|
|
|
pKeLeaveGuardedRegion();
|
|
|
|
CheckApcs(0, 1, TRUE, PASSIVE_LEVEL);
|
|
|
|
pKeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(1, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
pKeLeaveGuardedRegion();
|
|
|
|
CheckApcs(1, 1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(0, 1, TRUE, PASSIVE_LEVEL);
|
|
|
|
pKeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
}
|
2011-09-10 10:48:07 +00:00
|
|
|
}
|
2011-07-22 12:01:48 +00:00
|
|
|
|
|
|
|
/* manually disable APCs */
|
|
|
|
Thread->KernelApcDisable = -1;
|
|
|
|
CheckApcs(-1, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
Thread->SpecialApcDisable = -1;
|
|
|
|
CheckApcs(-1, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
Thread->KernelApcDisable = 0;
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
Thread->SpecialApcDisable = 0;
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
|
|
|
/* raised irql - APC_LEVEL should disable APCs */
|
|
|
|
KeRaiseIrql(APC_LEVEL, &Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, TRUE, APC_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLowerIrql(Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
|
|
|
/* KeAre*ApcsDisabled are documented to work up to DISPATCH_LEVEL... */
|
|
|
|
KeRaiseIrql(DISPATCH_LEVEL, &Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, TRUE, DISPATCH_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLowerIrql(Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
|
|
|
/* ... but also work on higher levels! */
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, TRUE, HIGH_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLowerIrql(Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
|
|
|
/* now comes the crazy stuff */
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, TRUE, HIGH_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeEnterCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-1, 0, TRUE, HIGH_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, TRUE, HIGH_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
2011-09-10 10:48:07 +00:00
|
|
|
/* Ke*GuardedRegion assert at > APC_LEVEL */
|
2015-02-15 10:23:21 +00:00
|
|
|
if (!KmtIsCheckedBuild &&
|
|
|
|
!skip(pKeEnterGuardedRegion &&
|
|
|
|
pKeLeaveGuardedRegion, "Guarded regions not available\n"))
|
2011-09-10 10:48:07 +00:00
|
|
|
{
|
2015-02-15 10:23:21 +00:00
|
|
|
pKeEnterGuardedRegion();
|
2011-09-10 10:48:07 +00:00
|
|
|
CheckApcs(0, -1, TRUE, HIGH_LEVEL);
|
2015-02-15 10:23:21 +00:00
|
|
|
pKeLeaveGuardedRegion();
|
2011-09-10 10:48:07 +00:00
|
|
|
}
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, TRUE, HIGH_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLowerIrql(Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
2015-02-15 10:23:21 +00:00
|
|
|
if (!KmtIsCheckedBuild &&
|
|
|
|
!skip(pKeEnterGuardedRegion &&
|
|
|
|
pKeLeaveGuardedRegion, "Guarded regions not available\n"))
|
2011-09-10 10:48:07 +00:00
|
|
|
{
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
CheckApcs(0, 0, TRUE, HIGH_LEVEL);
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(-1, 0, TRUE, HIGH_LEVEL);
|
2015-02-15 10:23:21 +00:00
|
|
|
pKeEnterGuardedRegion();
|
2011-09-10 10:48:07 +00:00
|
|
|
CheckApcs(-1, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
CheckApcs(-1, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
2015-02-15 10:23:21 +00:00
|
|
|
pKeLeaveGuardedRegion();
|
2011-09-10 10:48:07 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
2015-02-15 10:23:21 +00:00
|
|
|
pKeEnterGuardedRegion();
|
2011-09-10 10:48:07 +00:00
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
CheckApcs(0, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(-1, -1, TRUE, HIGH_LEVEL);
|
2015-02-15 10:23:21 +00:00
|
|
|
pKeLeaveGuardedRegion();
|
2011-09-10 10:48:07 +00:00
|
|
|
CheckApcs(-1, 0, TRUE, HIGH_LEVEL);
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
CheckApcs(-1, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
2011-09-10 10:48:07 +00:00
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(-1, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
CheckApcs(-1, 0, TRUE, HIGH_LEVEL);
|
2015-02-15 10:23:21 +00:00
|
|
|
pKeEnterGuardedRegion();
|
2011-09-10 10:48:07 +00:00
|
|
|
CheckApcs(-1, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
2015-02-15 10:23:21 +00:00
|
|
|
pKeLeaveGuardedRegion();
|
2011-09-10 10:48:07 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
}
|
2011-07-09 22:02:54 +00:00
|
|
|
|
|
|
|
KeEnterCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-1, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-1, 0, TRUE, HIGH_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, TRUE, HIGH_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLowerIrql(Irql);
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
}
|