Skip to content

Commit

Permalink
Add KfRaiseIrql
Browse files Browse the repository at this point in the history
The DDK just defines KeRaiseIrql as inline wrapper around KfRaiseIrql
so we need to expose KfRaiseIrql when linking.

Addresses part of #69

Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Aug 2, 2023
1 parent 8696ab5 commit efc4be8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions inc/usersim/ke.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ extern "C"
VOID
KeRaiseIrql(_In_ KIRQL new_irql, _Out_ PKIRQL old_irql);

USERSIM_API
_IRQL_requires_max_(HIGH_LEVEL) _IRQL_raises_(new_irql) _IRQL_saves_ KIRQL
KfRaiseIrql(_In_ KIRQL new_irql);

USERSIM_API
KIRQL
KeRaiseIrqlToDpcLevel();
Expand Down
12 changes: 10 additions & 2 deletions src/ke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,18 @@ KeGetCurrentIrql() { return _usersim_current_irql; }
VOID
KeRaiseIrql(_In_ KIRQL new_irql, _Out_ PKIRQL old_irql)
{
*old_irql = KeGetCurrentIrql();
*old_irql = KfRaiseIrql(new_irql);
}

KIRQL
KfRaiseIrql(_In_ KIRQL new_irql)
{
KIRQL old_irql = KeGetCurrentIrql();
_usersim_current_irql = new_irql;
BOOL result = SetThreadPriority(GetCurrentThread(), new_irql);
ASSERT(result);

if (new_irql >= DISPATCH_LEVEL && *old_irql < DISPATCH_LEVEL) {
if (new_irql >= DISPATCH_LEVEL && old_irql < DISPATCH_LEVEL) {
PROCESSOR_NUMBER processor;
uint32_t processor_index = KeGetCurrentProcessorNumberEx(&processor);

Expand All @@ -85,6 +91,8 @@ KeRaiseIrql(_In_ KIRQL new_irql, _Out_ PKIRQL old_irql)

_usersim_dispatch_locks[processor_index].lock();
}

return old_irql;
}

KIRQL
Expand Down
17 changes: 17 additions & 0 deletions tests/ke_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ TEST_CASE("irql", "[ke]")
REQUIRE(KeGetCurrentIrql() == PASSIVE_LEVEL);
}

TEST_CASE("KfRaiseIrql", "[ke]")
{
REQUIRE(KeGetCurrentIrql() == PASSIVE_LEVEL);

KIRQL old_irql;
old_irql = KfRaiseIrql(DISPATCH_LEVEL);
REQUIRE(old_irql == PASSIVE_LEVEL);
REQUIRE(KeGetCurrentIrql() == DISPATCH_LEVEL);

old_irql = KfRaiseIrql(DISPATCH_LEVEL);
REQUIRE(old_irql == DISPATCH_LEVEL);
REQUIRE(KeGetCurrentIrql() == DISPATCH_LEVEL);

KeLowerIrql(PASSIVE_LEVEL);
REQUIRE(KeGetCurrentIrql() == PASSIVE_LEVEL);
}

TEST_CASE("spin lock", "[ke]")
{
KSPIN_LOCK lock;
Expand Down

0 comments on commit efc4be8

Please sign in to comment.