diff --git a/Core/HLE/sceKernel.h b/Core/HLE/sceKernel.h index acd2e9595b..3cfdef8f69 100644 --- a/Core/HLE/sceKernel.h +++ b/Core/HLE/sceKernel.h @@ -383,10 +383,23 @@ public: } } + // ONLY use this when you know the handle is valid. + template + T *GetFast(SceUID handle) + { + const SceUID realHandle = handle - handleOffset; + if (realHandle < 0 || realHandle >= maxCount || !occupied[realHandle]) + { + ERROR_LOG(HLE, "Kernel: Bad fast object handle %i (%08x)", handle, handle); + return 0; + } + return static_cast(pool[realHandle]); + } + template T* GetByModuleByEntryAddr(u32 entryAddr) { - for (int i=0; i <4096; i++) + for (int i = 0; i < maxCount; ++i) { T* t = dynamic_cast(pool[i]); diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 525f04680d..4b847effbb 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -595,12 +595,9 @@ void MipsCall::setReturnValue(u64 value) savedV1 = (value >> 32) & 0xFFFFFFFF; } -// TODO: Should move to this wrapper so we can keep the current thread as a SceUID instead -// of a dangerous raw pointer. Thread *__GetCurrentThread() { - u32 error; if (currentThread != 0) - return kernelObjects.Get(currentThread, error); + return kernelObjects.GetFast(currentThread); else return NULL; } @@ -784,9 +781,8 @@ bool __KernelSwitchOffThread(const char *reason) if (current && current->isRunning()) __KernelChangeReadyState(current, threadID, true); - u32 error; // Idle 0 chosen entirely arbitrarily. - Thread *t = kernelObjects.Get(threadIdleID[0], error); + Thread *t = kernelObjects.GetFast(threadIdleID[0]); if (t) { __KernelSwitchContext(t, reason); @@ -1275,9 +1271,9 @@ Thread *__KernelNextThread() { } } - u32 error; + // Assume threadReadyQueue has not become corrupt. if (bestThread != -1) - return kernelObjects.Get(bestThread, error); + return kernelObjects.GetFast(bestThread); else return 0; }