[Xboxkrnl] Return error code from KeSetAffinityThread on null thread
If the guest-supplied thread pointer doesn't resolve to an XThread, we previously returned STATUS_SUCCESS without setting the affinity or writing previous_affinity_ptr, leaving callers believing the call succeeded. Real NT kernel would crash on a bad pointer, but that's not easy for us to replicate so return STATUS_INVALID_HANDLE instead and log the pointer value so the condition is visible rather than silent.
This commit is contained in:
@@ -331,12 +331,17 @@ dword_result_t KeSetAffinityThread_entry(lpvoid_t thread_ptr, dword_t affinity,
|
|||||||
return X_STATUS_INVALID_PARAMETER;
|
return X_STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
auto thread = XObject::GetNativeObject<XThread>(kernel_state(), thread_ptr);
|
auto thread = XObject::GetNativeObject<XThread>(kernel_state(), thread_ptr);
|
||||||
if (thread) {
|
if (!thread) {
|
||||||
if (previous_affinity_ptr) {
|
XELOGW(
|
||||||
*previous_affinity_ptr = uint32_t(1) << thread->active_cpu();
|
"KeSetAffinityThread: guest thread pointer {:08X} did not resolve to "
|
||||||
}
|
"an XThread; returning STATUS_INVALID_HANDLE",
|
||||||
thread->SetAffinity(affinity);
|
thread_ptr.guest_address());
|
||||||
|
return X_STATUS_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
if (previous_affinity_ptr) {
|
||||||
|
*previous_affinity_ptr = uint32_t(1) << thread->active_cpu();
|
||||||
|
}
|
||||||
|
thread->SetAffinity(affinity);
|
||||||
return X_STATUS_SUCCESS;
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
DECLARE_XBOXKRNL_EXPORT1(KeSetAffinityThread, kThreading, kImplemented);
|
DECLARE_XBOXKRNL_EXPORT1(KeSetAffinityThread, kThreading, kImplemented);
|
||||||
|
|||||||
Reference in New Issue
Block a user