Skip to content

Commit

Permalink
KeSetSystemGroupAffinityThread does not match kernel behavior (#187)
Browse files Browse the repository at this point in the history
* KeSetSystemGroupAffinityThread does not match kernel behavior

Signed-off-by: Alan Jowett <[email protected]>

* PR feedback

Signed-off-by: Alan Jowett <[email protected]>

* Revert _usersim_thread_affinity on failure

Signed-off-by: Alan Jowett <[email protected]>

* PR feedback

Signed-off-by: Alan Jowett <[email protected]>

* Put back catch2 update:

Signed-off-by: Alan Jowett <[email protected]>

---------

Signed-off-by: Alan Jowett <[email protected]>
Co-authored-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan-Jowett and Alan Jowett authored Apr 24, 2024
1 parent 0d370ec commit 646469a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,17 @@ KeSetSystemAffinityThreadEx(KAFFINITY affinity)
{
GROUP_AFFINITY old_affinity;
usersim_get_current_thread_group_affinity(&old_affinity);
// Reject affinities that are not valid for the current group.
// Assume that the affinity mask is contiguous.
KAFFINITY valid_affinity_mask = (1 << KeQueryMaximumProcessorCountEx(old_affinity.Group)) - 1;
if ((affinity & valid_affinity_mask) == 0) {
return 0;
}
_usersim_thread_affinity.Group = old_affinity.Group;
_usersim_thread_affinity.Mask = affinity;
if (KeGetCurrentIrql() < DISPATCH_LEVEL && SetThreadAffinityMask(GetCurrentThread(), affinity) == 0) {
unsigned long error = GetLastError();
KeBugCheckEx(0, error, 0, 0, 0);
_usersim_thread_affinity = old_affinity;
return 0;
}
return (KAFFINITY)old_affinity.Mask;
}
Expand Down

0 comments on commit 646469a

Please sign in to comment.