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
|
|
|
|
* PROGRAMMER: Thomas Faber <thfabba@gmx.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kmt_test.h>
|
|
|
|
|
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); \
|
|
|
|
ok_eq_bool(KeAreAllApcsDisabled(), AllApcsDisabled); \
|
|
|
|
ok_eq_int(Thread->SpecialApcDisable, SpecialApcsDisabled); \
|
|
|
|
ok_irql(Irql); \
|
2011-07-09 22:02:54 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
START_TEST(KeApc)
|
|
|
|
{
|
|
|
|
KIRQL Irql;
|
2011-07-22 12:01:48 +00:00
|
|
|
PKTHREAD 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 */
|
|
|
|
KeEnterGuardedRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeEnterGuardedRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, -2, TRUE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeEnterGuardedRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, -3, TRUE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveGuardedRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, -2, TRUE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveGuardedRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveGuardedRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
|
|
|
/* mix them */
|
|
|
|
KeEnterGuardedRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeEnterCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-1, -1, TRUE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveCriticalRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveGuardedRegion();
|
2011-07-22 12:01:48 +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
|
|
|
KeEnterGuardedRegion();
|
2011-07-22 12:01:48 +00:00
|
|
|
CheckApcs(-1, -1, TRUE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
KeLeaveGuardedRegion();
|
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);
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
2011-09-10 10:48:07 +00:00
|
|
|
KeLeaveGuardedRegion();
|
|
|
|
CheckApcs(0, 1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-22 12:01:48 +00:00
|
|
|
|
2011-09-10 10:48:07 +00:00
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(1, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
KeLeaveGuardedRegion();
|
|
|
|
CheckApcs(1, 1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(0, 1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
|
|
|
}
|
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 */
|
|
|
|
if (!KmtIsCheckedBuild)
|
|
|
|
{
|
|
|
|
KeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeLeaveGuardedRegion();
|
|
|
|
}
|
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
|
|
|
|
2011-09-10 10:48:07 +00:00
|
|
|
if (!KmtIsCheckedBuild)
|
|
|
|
{
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
CheckApcs(0, 0, TRUE, HIGH_LEVEL);
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(-1, 0, TRUE, HIGH_LEVEL);
|
|
|
|
KeEnterGuardedRegion();
|
|
|
|
CheckApcs(-1, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
CheckApcs(-1, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeLeaveGuardedRegion();
|
|
|
|
CheckApcs(0, 0, FALSE, PASSIVE_LEVEL);
|
2011-07-09 22:02:54 +00:00
|
|
|
|
2011-09-10 10:48:07 +00:00
|
|
|
KeEnterGuardedRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
CheckApcs(0, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
CheckApcs(-1, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeLeaveGuardedRegion();
|
|
|
|
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);
|
|
|
|
KeEnterGuardedRegion();
|
|
|
|
CheckApcs(-1, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
CheckApcs(0, -1, TRUE, HIGH_LEVEL);
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
CheckApcs(0, -1, TRUE, PASSIVE_LEVEL);
|
|
|
|
KeLeaveGuardedRegion();
|
|
|
|
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
|
|
|
}
|