From 64089558f1e93e1296fbcf96d11310bec7515432 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Fri, 24 Jul 2015 23:09:33 -0500 Subject: [PATCH] XThread set exit code on exit --- src/xenia/kernel/objects/xthread.cc | 15 ++++++++++++--- src/xenia/kernel/objects/xthread.h | 22 ++++++++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/xenia/kernel/objects/xthread.cc b/src/xenia/kernel/objects/xthread.cc index 008f2947b..0b3828439 100644 --- a/src/xenia/kernel/objects/xthread.cc +++ b/src/xenia/kernel/objects/xthread.cc @@ -321,7 +321,8 @@ X_STATUS XThread::Create() { // Set the thread name based on host ID (for easier debugging) char thread_name[32]; - snprintf(thread_name, xe::countof(thread_name), "XThread%04X (%04X)", handle(), thread_->id()); + snprintf(thread_name, xe::countof(thread_name), "XThread%04X (%04X)", + handle(), thread_->id()); set_name(thread_name); if (creation_params_.creation_flags & 0x60) { @@ -340,8 +341,6 @@ X_STATUS XThread::Exit(int exit_code) { // This may only be called on the thread itself. assert_true(XThread::GetCurrentThread() == this); - // TODO(benvanik): set exit code in thread state block - // TODO(benvanik); dispatch events? waiters? etc? RundownAPCs(); @@ -351,6 +350,11 @@ X_STATUS XThread::Exit(int exit_code) { current_thread_tls = nullptr; xe::Profiler::ThreadExit(); + // Set exit code + X_KTHREAD* thread = guest_object(); + thread->header.signal_state = 1; + thread->exit_status = exit_code; + running_ = false; Release(); ReleaseHandle(); @@ -363,6 +367,11 @@ X_STATUS XThread::Exit(int exit_code) { X_STATUS XThread::Terminate(int exit_code) { // TODO: Inform the profiler that this thread is exiting. + // Set exit code + X_KTHREAD* thread = guest_object(); + thread->header.signal_state = 1; + thread->exit_status = exit_code; + running_ = false; Release(); ReleaseHandle(); diff --git a/src/xenia/kernel/objects/xthread.h b/src/xenia/kernel/objects/xthread.h index 153e36ee0..d052b53a0 100644 --- a/src/xenia/kernel/objects/xthread.h +++ b/src/xenia/kernel/objects/xthread.h @@ -82,14 +82,20 @@ struct X_KPCR { }; struct X_KTHREAD { - X_DISPATCH_HEADER header; // 0x0 - char unk_10[0xAC]; // 0x10 - uint8_t suspend_count; // 0xBC - char unk_BD[0x8F]; // 0xBD - xe::be thread_id; // 0x14C - char unk_150[0x10]; // 0x150 - xe::be last_error; // 0x160 - char unk_164[0x94C]; // 0x164 + X_DISPATCH_HEADER header; // 0x0 + char unk_10[0xAC]; // 0x10 + uint8_t suspend_count; // 0xBC + uint8_t unk_BD; // 0xBD + uint16_t unk_BE; // 0xBE + char unk_C0[0x70]; // 0xC0 + xe::be create_time; // 0x130 + xe::be exit_time; // 0x138 + xe::be exit_status; // 0x140 + char unk_144[0x8]; // 0x144 + xe::be thread_id; // 0x14C + char unk_150[0x10]; // 0x150 + xe::be last_error; // 0x160 + char unk_164[0x94C]; // 0x164 // This struct is actually quite long... so uh, not filling this out! };