[Kernel/Thread] Added missing paramteter to KeSetAffinityThread
This commit is contained in:
parent
fe9b5b4a8f
commit
2dc6b0b2ad
|
@ -222,13 +222,23 @@ void KeSetCurrentStackPointers(lpvoid_t stack_ptr,
|
||||||
}
|
}
|
||||||
DECLARE_XBOXKRNL_EXPORT1(KeSetCurrentStackPointers, kThreading, kImplemented);
|
DECLARE_XBOXKRNL_EXPORT1(KeSetCurrentStackPointers, kThreading, kImplemented);
|
||||||
|
|
||||||
dword_result_t KeSetAffinityThread(lpvoid_t thread_ptr, dword_t affinity) {
|
dword_result_t KeSetAffinityThread(lpvoid_t thread_ptr, dword_t affinity,
|
||||||
auto thread = XObject::GetNativeObject<XThread>(kernel_state(), thread_ptr);
|
lpdword_t previous_affinity_ptr) {
|
||||||
if (thread) {
|
// Xbox 360 uses additional parameter (in comparation to NT equivalent)
|
||||||
thread->SetAffinity(affinity);
|
// which is used only for returning previous thread affinity. (Based on code
|
||||||
|
// dissasembly)
|
||||||
|
if (!affinity) {
|
||||||
|
return X_STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint32_t)affinity;
|
auto thread = XObject::GetNativeObject<XThread>(kernel_state(), thread_ptr);
|
||||||
|
if (thread) {
|
||||||
|
if (previous_affinity_ptr) {
|
||||||
|
*previous_affinity_ptr = 1 << thread->active_cpu();
|
||||||
|
}
|
||||||
|
thread->SetAffinity(affinity);
|
||||||
|
}
|
||||||
|
return X_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
DECLARE_XBOXKRNL_EXPORT1(KeSetAffinityThread, kThreading, kImplemented);
|
DECLARE_XBOXKRNL_EXPORT1(KeSetAffinityThread, kThreading, kImplemented);
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,7 @@ void XThread::InitializeGuestObject() {
|
||||||
// 0xA88 = APC
|
// 0xA88 = APC
|
||||||
// 0x18 = timer
|
// 0x18 = timer
|
||||||
xe::store_and_swap<uint32_t>(p + 0x09C, 0xFDFFD7FF);
|
xe::store_and_swap<uint32_t>(p + 0x09C, 0xFDFFD7FF);
|
||||||
|
xe::store_and_swap<uint8_t>(p + 0xBF, 0);
|
||||||
xe::store_and_swap<uint32_t>(p + 0x0D0, stack_base_);
|
xe::store_and_swap<uint32_t>(p + 0x0D0, stack_base_);
|
||||||
xe::store_and_swap<uint64_t>(p + 0x130, Clock::QueryGuestSystemTime());
|
xe::store_and_swap<uint64_t>(p + 0x130, Clock::QueryGuestSystemTime());
|
||||||
xe::store_and_swap<uint32_t>(p + 0x144, guest_object() + 0x144);
|
xe::store_and_swap<uint32_t>(p + 0x144, guest_object() + 0x144);
|
||||||
|
@ -346,6 +347,9 @@ X_STATUS XThread::Create() {
|
||||||
// Exports use this to get the kernel.
|
// Exports use this to get the kernel.
|
||||||
thread_state_->context()->kernel_state = kernel_state_;
|
thread_state_->context()->kernel_state = kernel_state_;
|
||||||
|
|
||||||
|
// Initialize the KTHREAD object.
|
||||||
|
InitializeGuestObject();
|
||||||
|
|
||||||
X_KPCR* pcr = memory()->TranslateVirtual<X_KPCR*>(pcr_address_);
|
X_KPCR* pcr = memory()->TranslateVirtual<X_KPCR*>(pcr_address_);
|
||||||
|
|
||||||
pcr->tls_ptr = tls_static_address_;
|
pcr->tls_ptr = tls_static_address_;
|
||||||
|
@ -355,14 +359,12 @@ X_STATUS XThread::Create() {
|
||||||
pcr->stack_base_ptr = stack_base_;
|
pcr->stack_base_ptr = stack_base_;
|
||||||
pcr->stack_end_ptr = stack_limit_;
|
pcr->stack_end_ptr = stack_limit_;
|
||||||
|
|
||||||
|
pcr->dpc_active = 0; // DPC active bool?
|
||||||
|
|
||||||
uint8_t proc_mask =
|
uint8_t proc_mask =
|
||||||
static_cast<uint8_t>(creation_params_.creation_flags >> 24);
|
static_cast<uint8_t>(creation_params_.creation_flags >> 24);
|
||||||
|
// Assign cpu core used by thread on guest side
|
||||||
pcr->current_cpu = GetFakeCpuNumber(proc_mask); // Current CPU(?)
|
SetAffinity(1 << GetFakeCpuNumber(proc_mask));
|
||||||
pcr->dpc_active = 0; // DPC active bool?
|
|
||||||
|
|
||||||
// Initialize the KTHREAD object.
|
|
||||||
InitializeGuestObject();
|
|
||||||
|
|
||||||
// Always retain when starting - the thread owns itself until exited.
|
// Always retain when starting - the thread owns itself until exited.
|
||||||
RetainHandle();
|
RetainHandle();
|
||||||
|
@ -714,7 +716,7 @@ void XThread::SetAffinity(uint32_t affinity) {
|
||||||
XELOGW("Too few processors - scheduling will be wonky");
|
XELOGW("Too few processors - scheduling will be wonky");
|
||||||
}
|
}
|
||||||
SetActiveCpu(GetFakeCpuNumber(affinity));
|
SetActiveCpu(GetFakeCpuNumber(affinity));
|
||||||
affinity_ = affinity;
|
|
||||||
if (!cvars::ignore_thread_affinities) {
|
if (!cvars::ignore_thread_affinities) {
|
||||||
thread_->set_affinity_mask(affinity);
|
thread_->set_affinity_mask(affinity);
|
||||||
}
|
}
|
||||||
|
@ -729,6 +731,12 @@ void XThread::SetActiveCpu(uint32_t cpu_index) {
|
||||||
assert_true(cpu_index < 6);
|
assert_true(cpu_index < 6);
|
||||||
uint8_t* pcr = memory()->TranslateVirtual(pcr_address_);
|
uint8_t* pcr = memory()->TranslateVirtual(pcr_address_);
|
||||||
xe::store_and_swap<uint8_t>(pcr + 0x10C, cpu_index);
|
xe::store_and_swap<uint8_t>(pcr + 0x10C, cpu_index);
|
||||||
|
|
||||||
|
if (is_guest_thread()) {
|
||||||
|
X_KTHREAD* thread_object =
|
||||||
|
memory()->TranslateVirtual<X_KTHREAD*>(guest_object());
|
||||||
|
thread_object->current_cpu = cpu_index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XThread::GetTLSValue(uint32_t slot, uint32_t* value_out) {
|
bool XThread::GetTLSValue(uint32_t slot, uint32_t* value_out) {
|
||||||
|
|
|
@ -88,7 +88,8 @@ struct X_KTHREAD {
|
||||||
char unk_10[0xAC]; // 0x10
|
char unk_10[0xAC]; // 0x10
|
||||||
uint8_t suspend_count; // 0xBC
|
uint8_t suspend_count; // 0xBC
|
||||||
uint8_t unk_BD; // 0xBD
|
uint8_t unk_BD; // 0xBD
|
||||||
uint16_t unk_BE; // 0xBE
|
uint8_t unk_BE; // 0xBE
|
||||||
|
uint8_t current_cpu; // 0xBF
|
||||||
char unk_C0[0x70]; // 0xC0
|
char unk_C0[0x70]; // 0xC0
|
||||||
xe::be<uint64_t> create_time; // 0x130
|
xe::be<uint64_t> create_time; // 0x130
|
||||||
xe::be<uint64_t> exit_time; // 0x138
|
xe::be<uint64_t> exit_time; // 0x138
|
||||||
|
@ -165,7 +166,6 @@ class XThread : public XObject, public cpu::Thread {
|
||||||
int32_t priority() const { return priority_; }
|
int32_t priority() const { return priority_; }
|
||||||
int32_t QueryPriority();
|
int32_t QueryPriority();
|
||||||
void SetPriority(int32_t increment);
|
void SetPriority(int32_t increment);
|
||||||
uint32_t affinity() const { return affinity_; }
|
|
||||||
void SetAffinity(uint32_t affinity);
|
void SetAffinity(uint32_t affinity);
|
||||||
uint32_t active_cpu() const;
|
uint32_t active_cpu() const;
|
||||||
void SetActiveCpu(uint32_t cpu_index);
|
void SetActiveCpu(uint32_t cpu_index);
|
||||||
|
@ -220,7 +220,6 @@ class XThread : public XObject, public cpu::Thread {
|
||||||
bool running_ = false;
|
bool running_ = false;
|
||||||
|
|
||||||
int32_t priority_ = 0;
|
int32_t priority_ = 0;
|
||||||
uint32_t affinity_ = 0;
|
|
||||||
|
|
||||||
xe::global_critical_region global_critical_region_;
|
xe::global_critical_region global_critical_region_;
|
||||||
std::atomic<uint32_t> irql_ = {0};
|
std::atomic<uint32_t> irql_ = {0};
|
||||||
|
|
Loading…
Reference in New Issue