diff --git a/src/xenia/kernel/xthread.cc b/src/xenia/kernel/xthread.cc index e2c4ecedc..657c0fb37 100644 --- a/src/xenia/kernel/xthread.cc +++ b/src/xenia/kernel/xthread.cc @@ -117,6 +117,8 @@ XThread* XThread::GetCurrentThread() { return thread; } +XThread* XThread::TryGetCurrentThread() { return current_xthread_tls_; } + uint32_t XThread::GetCurrentThreadHandle() { XThread* thread = XThread::GetCurrentThread(); return thread->handle(); diff --git a/src/xenia/kernel/xthread.h b/src/xenia/kernel/xthread.h index 2c1e75856..31ec31398 100644 --- a/src/xenia/kernel/xthread.h +++ b/src/xenia/kernel/xthread.h @@ -408,6 +408,11 @@ class XThread : public XObject, public cpu::Thread { static bool IsInThread(XThread* other); static bool IsInThread(); static XThread* GetCurrentThread(); + // Null-safe variant of GetCurrentThread: returns nullptr (instead of + // asserting) when the calling OS thread is not a guest XThread. Used by + // additive instrumentation that can fire from boot code before any XThread + // exists. Read-only accessor; no behaviour change. + static XThread* TryGetCurrentThread(); static uint32_t GetCurrentThreadHandle(); static uint32_t GetCurrentThreadId();