Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeSetSystemGroupAffinityThread does not match kernel behavior #187

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I believe the affinity mask is guaranteed to be 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