From 4d22c216882fd251969a90c4af8dc656c894615f Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Sat, 31 Oct 2015 10:28:53 -0500 Subject: [PATCH 1/2] ExCreateThread: Flag 0x80 indicates we should return the thread pointer, not handle. --- src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc index 344409672..ab9f35d97 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc @@ -139,7 +139,11 @@ SHIM_CALL ExCreateThread_shim(PPCContext* ppc_context, if (XSUCCEEDED(result)) { if (handle_ptr) { - SHIM_SET_MEM_32(handle_ptr, thread->handle()); + if (creation_flags & 0x80) { + SHIM_SET_MEM_32(handle_ptr, thread->guest_object()); + } else { + SHIM_SET_MEM_32(handle_ptr, thread->handle()); + } } if (thread_id_ptr) { SHIM_SET_MEM_32(thread_id_ptr, thread->thread_id()); From cee0e582c278076251d6ec39e2f4fa1f10cc654c Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Sat, 31 Oct 2015 10:31:35 -0500 Subject: [PATCH 2/2] Remove workarounds for handles passed into Ke* functions. --- .../kernel/xboxkrnl/xboxkrnl_threading.cc | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc index ab9f35d97..7df0bd74e 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_threading.cc @@ -269,18 +269,8 @@ SHIM_CALL KeSetBasePriorityThread_shim(PPCContext* ppc_context, XELOGD("KeSetBasePriorityThread(%.8X, %.8X)", thread_ptr, increment); int32_t prev_priority = 0; - - object_ref thread; - if (thread_ptr < 0x1000) { - // They passed in a handle (for some reason) - thread = kernel_state->object_table()->LookupObject(thread_ptr); - - // Log it in case this is the source of any problems in the future - XELOGD("KeSetBasePriorityThread - Interpreting thread ptr as handle!"); - } else { - thread = XObject::GetNativeObject(kernel_state, - SHIM_MEM_ADDR(thread_ptr)); - } + auto thread = XObject::GetNativeObject(kernel_state, + SHIM_MEM_ADDR(thread_ptr)); if (thread) { prev_priority = thread->QueryPriority(); @@ -856,17 +846,8 @@ SHIM_CALL KeWaitForSingleObject_shim(PPCContext* ppc_context, XELOGD("KeWaitForSingleObject(%.8X, %.8X, %.8X, %.1X, %.8X)", object_ptr, wait_reason, processor_mode, alertable, timeout_ptr); - object_ref object; - if (object_ptr < 0x1000) { - // They passed in a handle (for some reason) - object = kernel_state->object_table()->LookupObject(object_ptr); - - // Log it in case this is the source of any problems in the future - XELOGD("KeWaitForSingleObject - Interpreting object ptr as handle!"); - } else { - object = XObject::GetNativeObject(kernel_state, - SHIM_MEM_ADDR(object_ptr)); - } + auto object = XObject::GetNativeObject(kernel_state, + SHIM_MEM_ADDR(object_ptr)); if (!object) { // The only kind-of failure code.