From 991243fffdcdfb618fec755748bee08bbf8551f1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 26 Dec 2012 20:34:10 -0800 Subject: [PATCH] Add basic DoState() to tertiary kernel objects. --- Core/HLE/sceKernel.h | 3 +-- Core/HLE/sceKernelAlarm.cpp | 26 +++++++++++++++++++++----- Core/HLE/sceKernelEventFlag.cpp | 7 +++++++ Core/HLE/sceKernelMbx.cpp | 7 +++++++ Core/HLE/sceKernelMsgPipe.cpp | 19 ++++++++++++++----- Core/HLE/sceKernelMutex.cpp | 16 ++++++++++++++++ Core/HLE/sceKernelSemaphore.cpp | 7 +++++++ Core/HLE/sceKernelVTimer.cpp | 12 ++++++++++++ 8 files changed, 85 insertions(+), 12 deletions(-) diff --git a/Core/HLE/sceKernel.h b/Core/HLE/sceKernel.h index cfb1c1cfcb..9ae451eb8e 100644 --- a/Core/HLE/sceKernel.h +++ b/Core/HLE/sceKernel.h @@ -315,8 +315,7 @@ public: virtual void DoState(PointerWrap &p) { - // TODO - //_dbg_assert_msg_(HLE, false, "Bad kernel object"); + _dbg_assert_msg_(HLE, false, "Unable to save state: bad kernel object."); } }; diff --git a/Core/HLE/sceKernelAlarm.cpp b/Core/HLE/sceKernelAlarm.cpp index 4e378b2a49..3a26a7788b 100644 --- a/Core/HLE/sceKernelAlarm.cpp +++ b/Core/HLE/sceKernelAlarm.cpp @@ -37,6 +37,13 @@ struct Alarm : public KernelObject const char *GetTypeName() {return "Alarm";} static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_ALMID; } int GetIDType() const { return SCE_KERNEL_TMID_Alarm; } + + virtual void DoState(PointerWrap &p) + { + p.Do(alm); + p.DoMarker("Alarm"); + } + NativeAlarm alm; }; @@ -47,7 +54,7 @@ class AlarmIntrHandler : public SubIntrHandler public: AlarmIntrHandler(Alarm *alarm) { - this->alarm = alarm; + alarmID = alarm->GetUID(); handlerAddress = alarm->alm.handlerPtr; enabled = true; } @@ -56,26 +63,35 @@ public: { SubIntrHandler::copyArgsToCPU(pend); - currentMIPS->r[MIPS_REG_A0] = alarm->alm.commonPtr; + u32 error; + Alarm *alarm = kernelObjects.Get(alarmID, error); + if (alarm) + currentMIPS->r[MIPS_REG_A0] = alarm->alm.commonPtr; + else + ERROR_LOG(HLE, "sceKernelAlarm: Unable to send interrupt args: alarm deleted?"); } virtual void handleResult(int result) { // A non-zero result means to reschedule. if (result > 0) + { + u32 error; + Alarm *alarm = kernelObjects.Get(alarmID, error); __KernelScheduleAlarm(alarm, (u64) usToCycles(result)); + } else { if (result < 0) WARN_LOG(HLE, "Alarm requested reschedule for negative value %u, ignoring", (unsigned) result); // Delete the alarm if it's not rescheduled. - __ReleaseSubInterruptHandler(PSP_SYSTIMER0_INTR, alarm->GetUID()); - kernelObjects.Destroy(alarm->GetUID()); + kernelObjects.Destroy(alarmID); + __ReleaseSubInterruptHandler(PSP_SYSTIMER0_INTR, alarmID); } } - Alarm *alarm; + SceUID alarmID; }; static int alarmTimer = 0; diff --git a/Core/HLE/sceKernelEventFlag.cpp b/Core/HLE/sceKernelEventFlag.cpp index a28c06c0d6..5a2c625117 100644 --- a/Core/HLE/sceKernelEventFlag.cpp +++ b/Core/HLE/sceKernelEventFlag.cpp @@ -63,6 +63,13 @@ public: } int GetIDType() const { return SCE_KERNEL_TMID_EventFlag; } + virtual void DoState(PointerWrap &p) + { + p.Do(nef); + p.Do(waitingThreads); + p.DoMarker("EventFlag"); + } + NativeEventFlag nef; std::vector waitingThreads; }; diff --git a/Core/HLE/sceKernelMbx.cpp b/Core/HLE/sceKernelMbx.cpp index c8c758a215..080226870e 100644 --- a/Core/HLE/sceKernelMbx.cpp +++ b/Core/HLE/sceKernelMbx.cpp @@ -153,6 +153,13 @@ struct Mbx : public KernelObject return 0; } + virtual void DoState(PointerWrap &p) + { + p.Do(nmb); + p.Do(waitingThreads); + p.DoMarker("Mbx"); + } + NativeMbx nmb; std::vector waitingThreads; diff --git a/Core/HLE/sceKernelMsgPipe.cpp b/Core/HLE/sceKernelMsgPipe.cpp index 1521d5f188..e98786f366 100644 --- a/Core/HLE/sceKernelMsgPipe.cpp +++ b/Core/HLE/sceKernelMsgPipe.cpp @@ -56,11 +56,6 @@ struct MsgPipe : public KernelObject static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_MPPID; } int GetIDType() const { return SCE_KERNEL_TMID_Mpipe; } - NativeMsgPipe nmp; - - std::vector sendWaitingThreads; - std::vector receiveWaitingThreads; - void AddWaitingThread(std::vector &list, SceUID id, u32 addr, u32 size, int waitMode, u32 transferredBytesAddr, bool usePrio) { MsgPipeWaitingThread thread = { id, addr, size, size, waitMode, transferredBytesAddr }; @@ -150,6 +145,20 @@ struct MsgPipe : public KernelObject } } + virtual void DoState(PointerWrap &p) + { + p.Do(nmp); + p.Do(sendWaitingThreads); + p.Do(receiveWaitingThreads); + p.DoArray(buffer, nmp.bufSize); + p.DoMarker("MsgPipe"); + } + + NativeMsgPipe nmp; + + std::vector sendWaitingThreads; + std::vector receiveWaitingThreads; + u8 *buffer; }; diff --git a/Core/HLE/sceKernelMutex.cpp b/Core/HLE/sceKernelMutex.cpp index e3d048e545..b5a78afdfe 100644 --- a/Core/HLE/sceKernelMutex.cpp +++ b/Core/HLE/sceKernelMutex.cpp @@ -62,6 +62,14 @@ struct Mutex : public KernelObject const char *GetTypeName() {return "Mutex";} static u32 GetMissingErrorCode() { return PSP_MUTEX_ERROR_NO_SUCH_MUTEX; } int GetIDType() const { return SCE_KERNEL_TMID_Mutex; } + + virtual void DoState(PointerWrap &p) + { + p.Do(nm); + p.Do(waitingThreads); + p.DoMarker("Mutex"); + } + NativeMutex nm; std::vector waitingThreads; }; @@ -103,6 +111,14 @@ struct LwMutex : public KernelObject const char *GetTypeName() {return "LwMutex";} static u32 GetMissingErrorCode() { return PSP_LWMUTEX_ERROR_NO_SUCH_LWMUTEX; } int GetIDType() const { return SCE_KERNEL_TMID_LwMutex; } + + virtual void DoState(PointerWrap &p) + { + p.Do(nm); + p.Do(waitingThreads); + p.DoMarker("LwMutex"); + } + NativeLwMutex nm; std::vector waitingThreads; }; diff --git a/Core/HLE/sceKernelSemaphore.cpp b/Core/HLE/sceKernelSemaphore.cpp index 2fd575d0d4..54c30ae831 100644 --- a/Core/HLE/sceKernelSemaphore.cpp +++ b/Core/HLE/sceKernelSemaphore.cpp @@ -57,6 +57,13 @@ struct Semaphore : public KernelObject static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_SEMID; } int GetIDType() const { return SCE_KERNEL_TMID_Semaphore; } + virtual void DoState(PointerWrap &p) + { + p.Do(ns); + p.Do(waitingThreads); + p.DoMarker("Semaphore"); + } + NativeSemaphore ns; std::vector waitingThreads; }; diff --git a/Core/HLE/sceKernelVTimer.cpp b/Core/HLE/sceKernelVTimer.cpp index 299e47fd6b..ad3d383141 100644 --- a/Core/HLE/sceKernelVTimer.cpp +++ b/Core/HLE/sceKernelVTimer.cpp @@ -30,6 +30,18 @@ struct VTimer : public KernelObject static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_VTID; } int GetIDType() const { return SCE_KERNEL_TMID_VTimer; } + virtual void DoState(PointerWrap &p) + { + p.Do(size); + p.Do(name); + p.Do(startTime); + p.Do(running); + p.Do(handler); + p.Do(handlerTime); + p.Do(argument); + p.DoMarker("VTimer"); + } + SceSize size; char name[KERNELOBJECT_MAX_NAME_LENGTH+1]; u64 startTime;