From f48b73082863be3ea5ed5bc5ad0d84bcc16faa26 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 00:14:14 -0700 Subject: [PATCH 01/12] Wrap sceKernelCreateFpl and fix refer status. Just initial changes to make it test properly. --- Core/HLE/sceKernel.cpp | 68 ++++++++++++++++++------------------ Core/HLE/sceKernelMemory.cpp | 35 +++++++++++-------- Core/HLE/sceKernelMemory.h | 2 +- 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 702679e25d..dcadc4bd48 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -758,44 +758,44 @@ const HLEFunction ThreadManForUser[] = {0x72F3C145,0,"sceKernelReleaseThreadEventHandler"}, {0x369EEB6B,0,"sceKernelReferThreadEventHandlerStatus"}, - {0x349d6d6c,sceKernelCheckCallback, "sceKernelCheckCallback"}, - {0xE81CAF8F,WrapI_CUU, "sceKernelCreateCallback"}, - {0xEDBA5844,WrapI_I, "sceKernelDeleteCallback"}, - {0xC11BA8C4,WrapI_II, "sceKernelNotifyCallback"}, - {0xBA4051D6,WrapI_I, "sceKernelCancelCallback"}, - {0x2A3D44FF,WrapI_I, "sceKernelGetCallbackCount"}, - {0x730ED8BC,WrapI_IU, "sceKernelReferCallbackStatus"}, + {0x349d6d6c,sceKernelCheckCallback, "sceKernelCheckCallback"}, + {0xE81CAF8F,WrapI_CUU, "sceKernelCreateCallback"}, + {0xEDBA5844,WrapI_I, "sceKernelDeleteCallback"}, + {0xC11BA8C4,WrapI_II, "sceKernelNotifyCallback"}, + {0xBA4051D6,WrapI_I, "sceKernelCancelCallback"}, + {0x2A3D44FF,WrapI_I, "sceKernelGetCallbackCount"}, + {0x730ED8BC,WrapI_IU, "sceKernelReferCallbackStatus"}, - {0x8125221D,WrapI_CUU, "sceKernelCreateMbx"}, - {0x86255ADA,WrapI_I, "sceKernelDeleteMbx"}, - {0xE9B3061E,WrapI_IU, "sceKernelSendMbx"}, - {0x18260574,WrapI_IUU, "sceKernelReceiveMbx"}, - {0xF3986382,WrapI_IUU, "sceKernelReceiveMbxCB"}, - {0x0D81716A,WrapI_IU, "sceKernelPollMbx"}, - {0x87D4DD36,WrapI_IU, "sceKernelCancelReceiveMbx"}, - {0xA8E8C846,WrapI_IU, "sceKernelReferMbxStatus"}, + {0x8125221D,WrapI_CUU, "sceKernelCreateMbx"}, + {0x86255ADA,WrapI_I, "sceKernelDeleteMbx"}, + {0xE9B3061E,WrapI_IU, "sceKernelSendMbx"}, + {0x18260574,WrapI_IUU, "sceKernelReceiveMbx"}, + {0xF3986382,WrapI_IUU, "sceKernelReceiveMbxCB"}, + {0x0D81716A,WrapI_IU, "sceKernelPollMbx"}, + {0x87D4DD36,WrapI_IU, "sceKernelCancelReceiveMbx"}, + {0xA8E8C846,WrapI_IU, "sceKernelReferMbxStatus"}, - {0x7C0DC2A0,WrapI_CIUUU, "sceKernelCreateMsgPipe"}, - {0xF0B7DA1C,WrapI_I, "sceKernelDeleteMsgPipe"}, - {0x876DBFAD,WrapI_IUUUUU, "sceKernelSendMsgPipe"}, - {0x7C41F2C2,WrapI_IUUUUU, "sceKernelSendMsgPipeCB"}, - {0x884C9F90,WrapI_IUUUU, "sceKernelTrySendMsgPipe"}, - {0x74829B76,WrapI_IUUUUU, "sceKernelReceiveMsgPipe"}, - {0xFBFA697D,WrapI_IUUUUU, "sceKernelReceiveMsgPipeCB"}, - {0xDF52098F,WrapI_IUUUU, "sceKernelTryReceiveMsgPipe"}, - {0x349B864D,WrapI_IUU, "sceKernelCancelMsgPipe"}, - {0x33BE4024,WrapI_IU, "sceKernelReferMsgPipeStatus"}, + {0x7C0DC2A0,WrapI_CIUUU, "sceKernelCreateMsgPipe"}, + {0xF0B7DA1C,WrapI_I, "sceKernelDeleteMsgPipe"}, + {0x876DBFAD,WrapI_IUUUUU, "sceKernelSendMsgPipe"}, + {0x7C41F2C2,WrapI_IUUUUU, "sceKernelSendMsgPipeCB"}, + {0x884C9F90,WrapI_IUUUU, "sceKernelTrySendMsgPipe"}, + {0x74829B76,WrapI_IUUUUU, "sceKernelReceiveMsgPipe"}, + {0xFBFA697D,WrapI_IUUUUU, "sceKernelReceiveMsgPipeCB"}, + {0xDF52098F,WrapI_IUUUU, "sceKernelTryReceiveMsgPipe"}, + {0x349B864D,WrapI_IUU, "sceKernelCancelMsgPipe"}, + {0x33BE4024,WrapI_IU, "sceKernelReferMsgPipeStatus"}, - {0x56C039B5,WrapI_CIUUU,"sceKernelCreateVpl"}, - {0x89B3D48C,WrapI_I,"sceKernelDeleteVpl"}, - {0xBED27435,WrapI_IUUU,"sceKernelAllocateVpl"}, - {0xEC0A693F,WrapI_IUUU,"sceKernelAllocateVplCB"}, - {0xAF36D708,WrapI_IUU,"sceKernelTryAllocateVpl"}, - {0xB736E9FF,WrapI_IU,"sceKernelFreeVpl"}, - {0x1D371B8A,WrapI_IU,"sceKernelCancelVpl"}, - {0x39810265,WrapI_IU,"sceKernelReferVplStatus"}, + {0x56C039B5,WrapI_CIUUU, "sceKernelCreateVpl"}, + {0x89B3D48C,WrapI_I, "sceKernelDeleteVpl"}, + {0xBED27435,WrapI_IUUU, "sceKernelAllocateVpl"}, + {0xEC0A693F,WrapI_IUUU, "sceKernelAllocateVplCB"}, + {0xAF36D708,WrapI_IUU, "sceKernelTryAllocateVpl"}, + {0xB736E9FF,WrapI_IU, "sceKernelFreeVpl"}, + {0x1D371B8A,WrapI_IU, "sceKernelCancelVpl"}, + {0x39810265,WrapI_IU, "sceKernelReferVplStatus"}, - {0xC07BB470,sceKernelCreateFpl,"sceKernelCreateFpl"}, + {0xC07BB470,WrapI_CUUUUU, "sceKernelCreateFpl"}, {0xED1410E0,sceKernelDeleteFpl,"sceKernelDeleteFpl"}, {0xD979E9BF,sceKernelAllocateFpl,"sceKernelAllocateFpl"}, {0xE7282CB6,sceKernelAllocateFplCB,"sceKernelAllocateFplCB"}, diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index e1a6571ca6..259db5daa9 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -51,7 +51,6 @@ struct NativeFPL { u32_le size; char name[KERNELOBJECT_MAX_NAME_LENGTH+1]; - SceUID_le mpid; u32_le attr; s32_le blocksize; @@ -195,15 +194,13 @@ void __KernelMemoryShutdown() kernelMemory.Shutdown(); } -//sceKernelCreateFpl(const char *name, SceUID mpid, SceUint attr, SceSize blocksize, int numBlocks, optparam) -void sceKernelCreateFpl() +int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 numBlocks, u32 optPtr) { - const char *name = Memory::GetCharPointer(PARAM(0)); - - u32 mpid = PARAM(1); - u32 attr = PARAM(2); - u32 blockSize = PARAM(3); - u32 numBlocks = PARAM(4); + if (!name) + { + WARN_LOG_REPORT(HLE, "%08x=sceKernelCreateFpl(): invalid name", SCE_KERNEL_ERROR_NO_MEMORY); + return SCE_KERNEL_ERROR_NO_MEMORY; + } u32 totalSize = blockSize * numBlocks; @@ -214,20 +211,21 @@ void sceKernelCreateFpl() { DEBUG_LOG(HLE,"sceKernelCreateFpl(\"%s\", partition=%i, attr=%i, bsize=%i, nb=%i) FAILED - out of ram", name, mpid, attr, blockSize, numBlocks); - RETURN(SCE_KERNEL_ERROR_NO_MEMORY); - return; + return SCE_KERNEL_ERROR_NO_MEMORY; } FPL *fpl = new FPL; SceUID id = kernelObjects.Create(fpl); - strncpy(fpl->nf.name, name, 32); - fpl->nf.size = sizeof(fpl->nf); - fpl->nf.mpid = mpid; // partition + strncpy(fpl->nf.name, name, KERNELOBJECT_MAX_NAME_LENGTH); + fpl->nf.name[KERNELOBJECT_MAX_NAME_LENGTH] = 0; fpl->nf.attr = attr; + fpl->nf.size = sizeof(fpl->nf); fpl->nf.blocksize = blockSize; fpl->nf.numBlocks = numBlocks; + fpl->nf.numFreeBlocks = numBlocks; fpl->nf.numWaitThreads = 0; + fpl->blocks = new bool[fpl->nf.numBlocks]; memset(fpl->blocks, 0, fpl->nf.numBlocks * sizeof(bool)); fpl->address = address; @@ -235,7 +233,7 @@ void sceKernelCreateFpl() DEBUG_LOG(HLE,"%i=sceKernelCreateFpl(\"%s\", partition=%i, attr=%i, bsize=%i, nb=%i)", id, name, mpid, attr, blockSize, numBlocks); - RETURN(id); + return id; } void sceKernelDeleteFpl() @@ -392,6 +390,13 @@ void sceKernelReferFplStatus() FPL *fpl = kernelObjects.Get(id, error); if (fpl) { + // Refresh free block count. + fpl->nf.numFreeBlocks = 0; + for (int i = 0; i < (int)fpl->nf.numBlocks; ++i) + { + if (!fpl->blocks[i]) + ++fpl->nf.numFreeBlocks; + } Memory::WriteStruct(statusAddr, &fpl->nf); RETURN(0); } diff --git a/Core/HLE/sceKernelMemory.h b/Core/HLE/sceKernelMemory.h index b2524ecee6..0eeac818c8 100644 --- a/Core/HLE/sceKernelMemory.h +++ b/Core/HLE/sceKernelMemory.h @@ -46,7 +46,7 @@ int sceKernelFreeVpl(SceUID uid, u32 addr); int sceKernelCancelVpl(SceUID uid, u32 numWaitThreadsPtr); int sceKernelReferVplStatus(SceUID uid, u32 infoPtr); -void sceKernelCreateFpl(); +int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blocksize, u32 numBlocks, u32 optPtr); void sceKernelDeleteFpl(); void sceKernelAllocateFpl(); void sceKernelAllocateFplCB(); From 0969261e3e2040afae29af7766987b1594298136 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 01:39:21 -0700 Subject: [PATCH 02/12] Fix error handling in sceKernelCreateFpl(). --- Core/HLE/sceKernelMemory.cpp | 44 ++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index 259db5daa9..913df1697b 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -194,6 +194,14 @@ void __KernelMemoryShutdown() kernelMemory.Shutdown(); } +enum SceKernelFplAttr +{ + PSP_FPL_ATTR_FIFO = 0x0000, + PSP_FPL_ATTR_PRIORITY = 0x0100, + PSP_FPL_ATTR_HIGHMEM = 0x4000, + PSP_FPL_ATTR_KNOWN = PSP_FPL_ATTR_FIFO | PSP_FPL_ATTR_PRIORITY | PSP_FPL_ATTR_HIGHMEM, +}; + int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 numBlocks, u32 optPtr) { if (!name) @@ -201,15 +209,41 @@ int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 WARN_LOG_REPORT(HLE, "%08x=sceKernelCreateFpl(): invalid name", SCE_KERNEL_ERROR_NO_MEMORY); return SCE_KERNEL_ERROR_NO_MEMORY; } + if (mpid < 1 || mpid > 9 || mpid == 7) + { + WARN_LOG_REPORT(HLE, "%08x=sceKernelCreateFpl(): invalid partition %d", SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, mpid); + return SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT; + } + // We only support user right now. + if (mpid != 2 && mpid != 6) + { + WARN_LOG_REPORT(HLE, "%08x=sceKernelCreateFpl(): invalid partition %d", SCE_KERNEL_ERROR_ILLEGAL_PERM, mpid); + return SCE_KERNEL_ERROR_ILLEGAL_PERM; + } + if (((attr & ~PSP_FPL_ATTR_KNOWN) & ~0xFF) != 0) + { + WARN_LOG_REPORT(HLE, "%08x=sceKernelCreateFpl(): invalid attr parameter: %08x", SCE_KERNEL_ERROR_ILLEGAL_ATTR, attr); + return SCE_KERNEL_ERROR_ILLEGAL_ATTR; + } + // There's probably a simpler way to get this same basic formula... + // This is based on results from a PSP. + bool illegalMemSize = blockSize == 0 || numBlocks == 0; + if (!illegalMemSize && (u64) blockSize > ((0x100000000ULL / (u64) numBlocks) - 4ULL)) + illegalMemSize = true; + if (!illegalMemSize && (u64) numBlocks >= 0x100000000ULL / (((u64) blockSize + 3ULL) & ~3ULL)) + illegalMemSize = true; + if (illegalMemSize) + { + WARN_LOG_REPORT(HLE, "%08x=sceKernelCreateFpl(): invalid blockSize/count", SCE_KERNEL_ERROR_ILLEGAL_MEMSIZE); + return SCE_KERNEL_ERROR_ILLEGAL_MEMSIZE; + } u32 totalSize = blockSize * numBlocks; - - bool atEnd = false; // attr can change this I think - + bool atEnd = (attr & PSP_FPL_ATTR_HIGHMEM) != 0; u32 address = userMemory.Alloc(totalSize, atEnd, "FPL"); if (address == (u32)-1) { - DEBUG_LOG(HLE,"sceKernelCreateFpl(\"%s\", partition=%i, attr=%i, bsize=%i, nb=%i) FAILED - out of ram", + DEBUG_LOG(HLE, "sceKernelCreateFpl(\"%s\", partition=%i, attr=%08x, bsize=%i, nb=%i) FAILED - out of ram", name, mpid, attr, blockSize, numBlocks); return SCE_KERNEL_ERROR_NO_MEMORY; } @@ -230,7 +264,7 @@ int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 memset(fpl->blocks, 0, fpl->nf.numBlocks * sizeof(bool)); fpl->address = address; - DEBUG_LOG(HLE,"%i=sceKernelCreateFpl(\"%s\", partition=%i, attr=%i, bsize=%i, nb=%i)", + DEBUG_LOG(HLE, "%i=sceKernelCreateFpl(\"%s\", partition=%i, attr=%08x, bsize=%i, nb=%i)", id, name, mpid, attr, blockSize, numBlocks); return id; From 107b464ace0cb935e49ed44b73a35d81cbc83331 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 12:03:40 -0700 Subject: [PATCH 03/12] Handle the fpl alignment option as well. --- Core/HLE/sceKernelMemory.cpp | 42 ++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index 913df1697b..ea8eb6a600 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -104,12 +104,14 @@ struct FPL : public KernelObject blocks = new bool[nf.numBlocks]; p.DoArray(blocks, nf.numBlocks); p.Do(address); + p.Do(alignedSize); p.DoMarker("FPL"); } NativeFPL nf; bool *blocks; u32 address; + int alignedSize; }; struct VplWaitingThread @@ -238,7 +240,27 @@ int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 return SCE_KERNEL_ERROR_ILLEGAL_MEMSIZE; } - u32 totalSize = blockSize * numBlocks; + int alignment = 4; + if (optPtr != 0) + { + u32 size = Memory::Read_U32(optPtr); + if (size > 8) + WARN_LOG_REPORT(HLE, "sceKernelCreateFpl(): unsupported extra options, size = %d", size); + if (size >= 4) + alignment = Memory::Read_U32(optPtr + 4); + // Must be a power of 2 to be valid. + if ((alignment & (alignment - 1)) != 0) + { + WARN_LOG_REPORT(HLE, "%08x=sceKernelCreateFpl(): invalid alignment %d", SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, alignment); + return SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT; + } + } + + if (alignment < 4) + alignment = 4; + + int alignedSize = ((int)blockSize + alignment - 1) & ~(alignment - 1); + u32 totalSize = alignedSize * numBlocks; bool atEnd = (attr & PSP_FPL_ATTR_HIGHMEM) != 0; u32 address = userMemory.Alloc(totalSize, atEnd, "FPL"); if (address == (u32)-1) @@ -263,6 +285,7 @@ int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 fpl->blocks = new bool[fpl->nf.numBlocks]; memset(fpl->blocks, 0, fpl->nf.numBlocks * sizeof(bool)); fpl->address = address; + fpl->alignedSize = alignedSize; DEBUG_LOG(HLE, "%i=sceKernelCreateFpl(\"%s\", partition=%i, attr=%08x, bsize=%i, nb=%i)", id, name, mpid, attr, blockSize, numBlocks); @@ -299,7 +322,7 @@ void sceKernelAllocateFpl() int blockNum = fpl->allocateBlock(); if (blockNum >= 0) { - u32 blockPtr = fpl->address + fpl->nf.blocksize * blockNum; + u32 blockPtr = fpl->address + fpl->alignedSize * blockNum; Memory::Write_U32(blockPtr, blockPtrAddr); RETURN(0); } else { @@ -330,7 +353,7 @@ void sceKernelAllocateFplCB() int blockNum = fpl->allocateBlock(); if (blockNum >= 0) { - u32 blockPtr = fpl->address + fpl->nf.blocksize * blockNum; + u32 blockPtr = fpl->address + fpl->alignedSize * blockNum; Memory::Write_U32(blockPtr, blockPtrAddr); RETURN(0); } else { @@ -360,7 +383,7 @@ void sceKernelTryAllocateFpl() int blockNum = fpl->allocateBlock(); if (blockNum >= 0) { - u32 blockPtr = fpl->address + fpl->nf.blocksize * blockNum; + u32 blockPtr = fpl->address + fpl->alignedSize * blockNum; Memory::Write_U32(blockPtr, blockPtrAddr); RETURN(0); } else { @@ -383,7 +406,7 @@ void sceKernelFreeFpl() u32 error; FPL *fpl = kernelObjects.Get(id, error); if (fpl) { - int blockNum = (blockAddr - fpl->address) / fpl->nf.blocksize; + int blockNum = (blockAddr - fpl->address) / fpl->alignedSize; if (blockNum < 0 || blockNum >= fpl->nf.numBlocks) { RETURN(SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCK); } else { @@ -1021,7 +1044,7 @@ SceUID sceKernelCreateVpl(const char *name, int partition, u32 attr, u32 vplSize u32 memBlockPtr = userMemory.Alloc(allocSize, (attr & PSP_VPL_ATTR_HIGHMEM) != 0, "VPL"); if (memBlockPtr == (u32)-1) { - ERROR_LOG(HLE, "sceKernelCreateVpl: Failed to allocate %i bytes of pool data", vplSize); + ERROR_LOG(HLE, "sceKernelCreateVpl(): Failed to allocate %i bytes of pool data", vplSize); return SCE_KERNEL_ERROR_NO_MEMORY; } @@ -1043,6 +1066,13 @@ SceUID sceKernelCreateVpl(const char *name, int partition, u32 attr, u32 vplSize DEBUG_LOG(HLE, "%x=sceKernelCreateVpl(\"%s\", block=%i, attr=%i, size=%i)", id, name, partition, vpl->nv.attr, vpl->nv.poolSize); + if (optPtr != 0) + { + u32 size = Memory::Read_U32(optPtr); + if (size > 4) + WARN_LOG_REPORT(HLE, "sceKernelCreateVpl(): unsupported options parameter, size = %d", size); + } + return id; } From a2471b810c1681a9ec7bbbc9011aaf76c26d4f11 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 12:44:25 -0700 Subject: [PATCH 04/12] Implement basic fpl waiting. --- Core/HLE/sceKernelMemory.cpp | 175 ++++++++++++++++++++++++++++++++--- 1 file changed, 164 insertions(+), 11 deletions(-) diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index ea8eb6a600..fe74c4af8c 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -36,6 +36,7 @@ BlockAllocator userMemory(256); BlockAllocator kernelMemory(256); static int vplWaitTimer = -1; +static int fplWaitTimer = -1; static bool tlsUsedIndexes[TLS_NUM_INDEXES]; // STATE END ////////////////////////////////////////////////////////////////////////// @@ -47,6 +48,12 @@ int flags_ = 0; int sdkVersion_; int compilerVersion_; +struct FplWaitingThread +{ + SceUID threadID; + u32 addrPtr; +}; + struct NativeFPL { u32_le size; @@ -105,6 +112,8 @@ struct FPL : public KernelObject p.DoArray(blocks, nf.numBlocks); p.Do(address); p.Do(alignedSize); + FplWaitingThread dv = {0}; + p.Do(waitingThreads, dv); p.DoMarker("FPL"); } @@ -112,6 +121,7 @@ struct FPL : public KernelObject bool *blocks; u32 address; int alignedSize; + std::vector waitingThreads; }; struct VplWaitingThread @@ -157,6 +167,7 @@ struct VPL : public KernelObject }; void __KernelVplTimeout(u64 userdata, int cyclesLate); +void __KernelFplTimeout(u64 userdata, int cyclesLate); void __KernelMemoryInit() { @@ -165,6 +176,7 @@ void __KernelMemoryInit() INFO_LOG(HLE, "Kernel and user memory pools initialized"); vplWaitTimer = CoreTiming::RegisterEvent("VplTimeout", __KernelVplTimeout); + fplWaitTimer = CoreTiming::RegisterEvent("FplTimeout", __KernelFplTimeout); flags_ = 0; sdkVersion_ = 0; @@ -179,6 +191,8 @@ void __KernelMemoryDoState(PointerWrap &p) p.Do(vplWaitTimer); CoreTiming::RestoreRegisterEvent(vplWaitTimer, "VplTimeout", __KernelVplTimeout); + p.Do(fplWaitTimer); + CoreTiming::RestoreRegisterEvent(fplWaitTimer, "FplTimeout", __KernelFplTimeout); p.Do(flags_); p.Do(sdkVersion_); p.Do(compilerVersion_); @@ -204,6 +218,70 @@ enum SceKernelFplAttr PSP_FPL_ATTR_KNOWN = PSP_FPL_ATTR_FIFO | PSP_FPL_ATTR_PRIORITY | PSP_FPL_ATTR_HIGHMEM, }; +bool __KernelUnlockFplForThread(FPL *fpl, FplWaitingThread &threadInfo, u32 &error, int result, bool &wokeThreads) +{ + const SceUID threadID = threadInfo.threadID; + SceUID waitID = __KernelGetWaitID(threadID, WAITTYPE_FPL, error); + u32 timeoutPtr = __KernelGetWaitTimeoutPtr(threadID, error); + + // The waitID may be different after a timeout. + if (waitID != fpl->GetUID()) + return true; + + // If result is an error code, we're just letting it go. + if (result == 0) + { + int blockNum = fpl->allocateBlock(); + if (blockNum >= 0) + { + u32 blockPtr = fpl->address + fpl->alignedSize * blockNum; + Memory::Write_U32(blockPtr, threadInfo.addrPtr); + } + else + return false; + } + + if (timeoutPtr != 0 && fplWaitTimer != -1) + { + // Remove any event for this thread. + s64 cyclesLeft = CoreTiming::UnscheduleEvent(fplWaitTimer, threadID); + Memory::Write_U32((u32) cyclesToUs(cyclesLeft), timeoutPtr); + } + + __KernelResumeThreadFromWait(threadID, result); + wokeThreads = true; + return true; +} + +void __KernelFplRemoveThread(FPL *fpl, SceUID threadID) +{ + for (size_t i = 0; i < fpl->waitingThreads.size(); i++) + { + FplWaitingThread *t = &fpl->waitingThreads[i]; + if (t->threadID == threadID) + { + fpl->waitingThreads.erase(fpl->waitingThreads.begin() + i); + break; + } + } +} + +bool __FplThreadSortPriority(FplWaitingThread thread1, FplWaitingThread thread2) +{ + return __KernelThreadSortPriority(thread1.threadID, thread2.threadID); +} + +bool __KernelClearFplThreads(FPL *fpl, int reason) +{ + u32 error; + bool wokeThreads = false; + for (auto iter = fpl->waitingThreads.begin(), end = fpl->waitingThreads.end(); iter != end; ++iter) + __KernelUnlockFplForThread(fpl, *iter, error, reason, wokeThreads); + fpl->waitingThreads.clear(); + + return wokeThreads; +} + int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 numBlocks, u32 optPtr) { if (!name) @@ -300,6 +378,10 @@ void sceKernelDeleteFpl() FPL *fpl = kernelObjects.Get(id, error); if (fpl) { + bool wokeThreads = __KernelClearFplThreads(fpl, SCE_KERNEL_ERROR_WAIT_DELETE); + if (wokeThreads) + hleReSchedule("fpl deleted"); + userMemory.Free(fpl->address); DEBUG_LOG(HLE,"sceKernelDeleteFpl(%i)", id); RETURN(kernelObjects.Destroy(id)); @@ -310,6 +392,47 @@ void sceKernelDeleteFpl() } } +void __KernelFplTimeout(u64 userdata, int cyclesLate) +{ + SceUID threadID = (SceUID) userdata; + + u32 error; + u32 timeoutPtr = __KernelGetWaitTimeoutPtr(threadID, error); + if (timeoutPtr != 0) + Memory::Write_U32(0, timeoutPtr); + + SceUID uid = __KernelGetWaitID(threadID, WAITTYPE_FPL, error); + FPL *fpl = kernelObjects.Get(uid, error); + if (fpl) + { + // This thread isn't waiting anymore, but we'll remove it from waitingThreads later. + // The reason is, if it times out, but while it was waiting on is DELETED prior to it + // actually running, it will get a DELETE result instead of a TIMEOUT. + // So, we need to remember it or we won't be able to mark it DELETE instead later. + __KernelResumeThreadFromWait(threadID, SCE_KERNEL_ERROR_WAIT_TIMEOUT); + } +} + +void __KernelSetFplTimeout(u32 timeoutPtr) +{ + if (timeoutPtr == 0 || fplWaitTimer == -1) + return; + + int micro = (int) Memory::Read_U32(timeoutPtr); + + // TODO: test for fpls. + // This happens to be how the hardware seems to time things. + if (micro <= 5) + micro = 10; + // Yes, this 7 is reproducible. 6 is (a lot) longer than 7. + else if (micro == 7) + micro = 15; + else if (micro <= 215) + micro = 250; + + CoreTiming::ScheduleEvent(usToCycles(micro), fplWaitTimer, __KernelGetCurThread()); +} + void sceKernelAllocateFpl() { SceUID id = PARAM(0); @@ -326,9 +449,14 @@ void sceKernelAllocateFpl() Memory::Write_U32(blockPtr, blockPtrAddr); RETURN(0); } else { - // TODO: Should block! - ERROR_LOG_REPORT(HLE, "sceKernelAllocateFpl: should block"); - RETURN(0); + SceUID threadID = __KernelGetCurThread(); + __KernelFplRemoveThread(fpl, threadID); + FplWaitingThread waiting = {threadID, blockPtrAddr}; + fpl->waitingThreads.push_back(waiting); + + __KernelSetFplTimeout(timeOut); + __KernelWaitCurThread(WAITTYPE_FPL, id, 0, timeOut, false, "fpl waited"); + return; } DEBUG_LOG(HLE,"sceKernelAllocateFpl(%i, %08x, %i)", id, blockPtrAddr, timeOut); @@ -357,9 +485,14 @@ void sceKernelAllocateFplCB() Memory::Write_U32(blockPtr, blockPtrAddr); RETURN(0); } else { - // TODO: Should block and process callbacks! - ERROR_LOG_REPORT(HLE, "sceKernelAllocateFplCB: should block"); - __KernelCheckCallbacks(); + SceUID threadID = __KernelGetCurThread(); + __KernelFplRemoveThread(fpl, threadID); + FplWaitingThread waiting = {threadID, blockPtrAddr}; + fpl->waitingThreads.push_back(waiting); + + __KernelSetFplTimeout(timeOut); + __KernelWaitCurThread(WAITTYPE_FPL, id, 0, timeOut, true, "fpl waited"); + return; } DEBUG_LOG(HLE,"sceKernelAllocateFpl(%i, %08x, %i)", id, PARAM(1), timeOut); @@ -410,10 +543,25 @@ void sceKernelFreeFpl() if (blockNum < 0 || blockNum >= fpl->nf.numBlocks) { RETURN(SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCK); } else { - if (fpl->freeBlock(blockNum)) { - // TODO: If there are waiting threads, wake them up - } RETURN(0); + if (fpl->freeBlock(blockNum)) { + if ((fpl->nf.attr & PSP_FPL_ATTR_PRIORITY) != 0) + std::stable_sort(fpl->waitingThreads.begin(), fpl->waitingThreads.end(), __FplThreadSortPriority); + + bool wokeThreads = false; +retry: + for (auto iter = fpl->waitingThreads.begin(), end = fpl->waitingThreads.end(); iter != end; ++iter) + { + if (__KernelUnlockFplForThread(fpl, *iter, error, 0, wokeThreads)) + { + fpl->waitingThreads.erase(iter); + goto retry; + } + } + + if (wokeThreads) + hleReSchedule("fpl freed"); + } } } else @@ -430,7 +578,11 @@ void sceKernelCancelFpl() FPL *fpl = kernelObjects.Get(id, error); if (fpl) { + // TODO: numWaitThreads param? RETURN(0); + bool wokeThreads = __KernelClearFplThreads(fpl, SCE_KERNEL_ERROR_WAIT_CANCEL); + if (wokeThreads) + hleReSchedule("fpl canceled"); } else { @@ -448,6 +600,7 @@ void sceKernelReferFplStatus() if (fpl) { // Refresh free block count. + fpl->nf.numWaitThreads = (int) fpl->waitingThreads.size(); fpl->nf.numFreeBlocks = 0; for (int i = 0; i < (int)fpl->nf.numBlocks; ++i) { @@ -1072,6 +1225,8 @@ SceUID sceKernelCreateVpl(const char *name, int partition, u32 attr, u32 vplSize if (size > 4) WARN_LOG_REPORT(HLE, "sceKernelCreateVpl(): unsupported options parameter, size = %d", size); } + if (attr & PSP_VPL_ATTR_SMALLEST) + WARN_LOG_REPORT(HLE, "sceKernelCreateVpl(): unsupported SMALLEST wake priority attr"); return id; } @@ -1202,8 +1357,6 @@ int sceKernelAllocateVplCB(SceUID uid, u32 size, u32 addrPtr, u32 timeoutPtr) { if (vpl) { - vpl->nv.numWaitThreads++; - SceUID threadID = __KernelGetCurThread(); __KernelVplRemoveThread(vpl, threadID); VplWaitingThread waiting = {threadID, addrPtr}; From fb95f07c5d7220a66cd7eb055910c3e005dec09d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 12:49:49 -0700 Subject: [PATCH 05/12] Implement cancel and delete for fpls. --- Core/HLE/sceKernel.cpp | 4 ++-- Core/HLE/sceKernelMemory.cpp | 35 +++++++++++++++++++++-------------- Core/HLE/sceKernelMemory.h | 4 ++-- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index dcadc4bd48..7dd0c4b7c9 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -796,12 +796,12 @@ const HLEFunction ThreadManForUser[] = {0x39810265,WrapI_IU, "sceKernelReferVplStatus"}, {0xC07BB470,WrapI_CUUUUU, "sceKernelCreateFpl"}, - {0xED1410E0,sceKernelDeleteFpl,"sceKernelDeleteFpl"}, + {0xED1410E0,WrapI_I, "sceKernelDeleteFpl"}, {0xD979E9BF,sceKernelAllocateFpl,"sceKernelAllocateFpl"}, {0xE7282CB6,sceKernelAllocateFplCB,"sceKernelAllocateFplCB"}, {0x623AE665,sceKernelTryAllocateFpl,"sceKernelTryAllocateFpl"}, {0xF6414A71,sceKernelFreeFpl,"sceKernelFreeFpl"}, - {0xA8AA591F,sceKernelCancelFpl,"sceKernelCancelFpl"}, + {0xA8AA591F,WrapI_IU, "sceKernelCancelFpl"}, {0xD8199E4C,sceKernelReferFplStatus,"sceKernelReferFplStatus"}, {0x20fff560,WrapU_CU,"sceKernelCreateVTimer"}, diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index fe74c4af8c..b1a1533a6b 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -371,24 +371,25 @@ int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 return id; } -void sceKernelDeleteFpl() +int sceKernelDeleteFpl(SceUID uid) { - SceUID id = PARAM(0); u32 error; - FPL *fpl = kernelObjects.Get(id, error); + FPL *fpl = kernelObjects.Get(uid, error); if (fpl) { + DEBUG_LOG(HLE, "sceKernelDeleteFpl(%i)", uid); + bool wokeThreads = __KernelClearFplThreads(fpl, SCE_KERNEL_ERROR_WAIT_DELETE); if (wokeThreads) hleReSchedule("fpl deleted"); userMemory.Free(fpl->address); - DEBUG_LOG(HLE,"sceKernelDeleteFpl(%i)", id); - RETURN(kernelObjects.Destroy(id)); + return kernelObjects.Destroy(uid); } else { - RETURN(error); + DEBUG_LOG(HLE, "sceKernelDeleteFpl(%i): invalid fpl", uid); + return error; } } @@ -570,23 +571,26 @@ retry: } } -void sceKernelCancelFpl() +int sceKernelCancelFpl(SceUID uid, u32 numWaitThreadsPtr) { - SceUID id = PARAM(0); - DEBUG_LOG(HLE,"UNIMPL: sceKernelCancelFpl(%i)", id); u32 error; - FPL *fpl = kernelObjects.Get(id, error); + FPL *fpl = kernelObjects.Get(uid, error); if (fpl) { - // TODO: numWaitThreads param? - RETURN(0); + DEBUG_LOG(HLE, "sceKernelCancelFpl(%i, %08x)", uid, numWaitThreadsPtr); + fpl->nf.numWaitThreads = (int) fpl->waitingThreads.size(); + if (Memory::IsValidAddress(numWaitThreadsPtr)) + Memory::Write_U32(fpl->nf.numWaitThreads, numWaitThreadsPtr); + bool wokeThreads = __KernelClearFplThreads(fpl, SCE_KERNEL_ERROR_WAIT_CANCEL); if (wokeThreads) hleReSchedule("fpl canceled"); + return 0; } else { - RETURN(error); + DEBUG_LOG(HLE, "sceKernelCancelFpl(%i, %08x): invalid fpl", uid, numWaitThreadsPtr); + return error; } } @@ -1423,11 +1427,11 @@ retry: int sceKernelCancelVpl(SceUID uid, u32 numWaitThreadsPtr) { - DEBUG_LOG(HLE, "sceKernelCancelVpl(%i, %08x)", uid, numWaitThreadsPtr); u32 error; VPL *vpl = kernelObjects.Get(uid, error); if (vpl) { + DEBUG_LOG(HLE, "sceKernelCancelVpl(%i, %08x)", uid, numWaitThreadsPtr); vpl->nv.numWaitThreads = (int) vpl->waitingThreads.size(); if (Memory::IsValidAddress(numWaitThreadsPtr)) Memory::Write_U32(vpl->nv.numWaitThreads, numWaitThreadsPtr); @@ -1439,7 +1443,10 @@ int sceKernelCancelVpl(SceUID uid, u32 numWaitThreadsPtr) return 0; } else + { + DEBUG_LOG(HLE, "sceKernelCancelVpl(%i, %08x): invalid vpl", uid, numWaitThreadsPtr); return error; + } } int sceKernelReferVplStatus(SceUID uid, u32 infoPtr) diff --git a/Core/HLE/sceKernelMemory.h b/Core/HLE/sceKernelMemory.h index 0eeac818c8..1ad510e64e 100644 --- a/Core/HLE/sceKernelMemory.h +++ b/Core/HLE/sceKernelMemory.h @@ -47,12 +47,12 @@ int sceKernelCancelVpl(SceUID uid, u32 numWaitThreadsPtr); int sceKernelReferVplStatus(SceUID uid, u32 infoPtr); int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blocksize, u32 numBlocks, u32 optPtr); -void sceKernelDeleteFpl(); +int sceKernelDeleteFpl(SceUID uid); void sceKernelAllocateFpl(); void sceKernelAllocateFplCB(); void sceKernelTryAllocateFpl(); void sceKernelFreeFpl(); -void sceKernelCancelFpl(); +int sceKernelCancelFpl(SceUID uid, u32 numWaitThreadsPtr); void sceKernelReferFplStatus(); int sceKernelGetCompiledSdkVersion(); From a947c958296051c32383dfd02a92a253affcaed6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 12:56:35 -0700 Subject: [PATCH 06/12] Clean up sceKernelReferFplStatus(). --- Core/HLE/sceKernel.cpp | 2 +- Core/HLE/sceKernelMemory.cpp | 18 +++++++++--------- Core/HLE/sceKernelMemory.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 7dd0c4b7c9..f393223d33 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -802,7 +802,7 @@ const HLEFunction ThreadManForUser[] = {0x623AE665,sceKernelTryAllocateFpl,"sceKernelTryAllocateFpl"}, {0xF6414A71,sceKernelFreeFpl,"sceKernelFreeFpl"}, {0xA8AA591F,WrapI_IU, "sceKernelCancelFpl"}, - {0xD8199E4C,sceKernelReferFplStatus,"sceKernelReferFplStatus"}, + {0xD8199E4C,WrapI_IU, "sceKernelReferFplStatus"}, {0x20fff560,WrapU_CU,"sceKernelCreateVTimer"}, {0x328F9E52,WrapU_U,"sceKernelDeleteVTimer"}, diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index b1a1533a6b..f469c10da0 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -594,16 +594,14 @@ int sceKernelCancelFpl(SceUID uid, u32 numWaitThreadsPtr) } } -void sceKernelReferFplStatus() +int sceKernelReferFplStatus(SceUID uid, u32 statusPtr) { - SceUID id = PARAM(0); - u32 statusAddr = PARAM(1); - DEBUG_LOG(HLE,"sceKernelReferFplStatus(%i, %08x)", id, statusAddr); u32 error; - FPL *fpl = kernelObjects.Get(id, error); + FPL *fpl = kernelObjects.Get(uid, error); if (fpl) { - // Refresh free block count. + DEBUG_LOG(HLE, "sceKernelReferFplStatus(%i, %08x)", uid, statusPtr); + // Refresh waiting threads and free block count. fpl->nf.numWaitThreads = (int) fpl->waitingThreads.size(); fpl->nf.numFreeBlocks = 0; for (int i = 0; i < (int)fpl->nf.numBlocks; ++i) @@ -611,12 +609,14 @@ void sceKernelReferFplStatus() if (!fpl->blocks[i]) ++fpl->nf.numFreeBlocks; } - Memory::WriteStruct(statusAddr, &fpl->nf); - RETURN(0); + if (Memory::Read_U32(statusPtr) != 0) + Memory::WriteStruct(statusPtr, &fpl->nf); + return 0; } else { - RETURN(error); + DEBUG_LOG(HLE, "sceKernelReferFplStatus(%i, %08x): invalid fpl", uid, statusPtr); + return error; } } diff --git a/Core/HLE/sceKernelMemory.h b/Core/HLE/sceKernelMemory.h index 1ad510e64e..b2fba15895 100644 --- a/Core/HLE/sceKernelMemory.h +++ b/Core/HLE/sceKernelMemory.h @@ -53,7 +53,7 @@ void sceKernelAllocateFplCB(); void sceKernelTryAllocateFpl(); void sceKernelFreeFpl(); int sceKernelCancelFpl(SceUID uid, u32 numWaitThreadsPtr); -void sceKernelReferFplStatus(); +int sceKernelReferFplStatus(SceUID uid, u32 statusPtr); int sceKernelGetCompiledSdkVersion(); From 8d750d65e82da15a5bfb391b7feed0846e04c9cc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 13:14:29 -0700 Subject: [PATCH 07/12] Properly remove timed out fpl waits from status. --- Core/HLE/sceKernelMemory.cpp | 54 ++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index f469c10da0..42510d8ad8 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -282,6 +282,25 @@ bool __KernelClearFplThreads(FPL *fpl, int reason) return wokeThreads; } +void __KernelSortFplThreads(FPL *fpl) +{ + // Remove any that are no longer waiting. + u32 error; + SceUID uid = fpl->GetUID(); + for (size_t i = 0; i < fpl->waitingThreads.size(); i++) + { + SceUID waitID = __KernelGetWaitID(fpl->waitingThreads[i].threadID, WAITTYPE_FPL, error); + if (waitID != uid) + { + fpl->waitingThreads.erase(fpl->waitingThreads.begin() + i); + --i; + } + } + + if ((fpl->nf.attr & PSP_FPL_ATTR_PRIORITY) != 0) + std::stable_sort(fpl->waitingThreads.begin(), fpl->waitingThreads.end(), __FplThreadSortPriority); +} + int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 numBlocks, u32 optPtr) { if (!name) @@ -546,8 +565,7 @@ void sceKernelFreeFpl() } else { RETURN(0); if (fpl->freeBlock(blockNum)) { - if ((fpl->nf.attr & PSP_FPL_ATTR_PRIORITY) != 0) - std::stable_sort(fpl->waitingThreads.begin(), fpl->waitingThreads.end(), __FplThreadSortPriority); + __KernelSortFplThreads(fpl); bool wokeThreads = false; retry: @@ -602,6 +620,7 @@ int sceKernelReferFplStatus(SceUID uid, u32 statusPtr) { DEBUG_LOG(HLE, "sceKernelReferFplStatus(%i, %08x)", uid, statusPtr); // Refresh waiting threads and free block count. + __KernelSortFplThreads(fpl); fpl->nf.numWaitThreads = (int) fpl->waitingThreads.size(); fpl->nf.numFreeBlocks = 0; for (int i = 0; i < (int)fpl->nf.numBlocks; ++i) @@ -1156,6 +1175,25 @@ bool __KernelClearVplThreads(VPL *vpl, int reason) return wokeThreads; } +void __KernelSortFplThreads(VPL *vpl) +{ + // Remove any that are no longer waiting. + u32 error; + SceUID uid = vpl->GetUID(); + for (size_t i = 0; i < vpl->waitingThreads.size(); i++) + { + SceUID waitID = __KernelGetWaitID(vpl->waitingThreads[i].threadID, WAITTYPE_VPL, error); + if (waitID != uid) + { + vpl->waitingThreads.erase(vpl->waitingThreads.begin() + i); + --i; + } + } + + if ((vpl->nv.attr & PSP_VPL_ATTR_PRIORITY) != 0) + std::stable_sort(vpl->waitingThreads.begin(), vpl->waitingThreads.end(), __VplThreadSortPriority); +} + SceUID sceKernelCreateVpl(const char *name, int partition, u32 attr, u32 vplSize, u32 optPtr) { if (!name) @@ -1396,8 +1434,7 @@ int sceKernelFreeVpl(SceUID uid, u32 addr) { if (vpl->alloc.FreeExact(addr)) { - if ((vpl->nv.attr & PSP_VPL_ATTR_PRIORITY) != 0) - std::stable_sort(vpl->waitingThreads.begin(), vpl->waitingThreads.end(), __VplThreadSortPriority); + __KernelSortFplThreads(vpl); bool wokeThreads = false; retry: @@ -1457,14 +1494,7 @@ int sceKernelReferVplStatus(SceUID uid, u32 infoPtr) { DEBUG_LOG(HLE, "sceKernelReferVplStatus(%i, %08x)", uid, infoPtr); - for (auto iter = vpl->waitingThreads.begin(); iter != vpl->waitingThreads.end(); ++iter) - { - SceUID waitID = __KernelGetWaitID(iter->threadID, WAITTYPE_VPL, error); - // The thread is no longer waiting for this, clean it up. - if (waitID != uid) - vpl->waitingThreads.erase(iter--); - } - + __KernelSortFplThreads(vpl); vpl->nv.numWaitThreads = (int) vpl->waitingThreads.size(); vpl->nv.freeSize = vpl->alloc.GetTotalFreeBytes(); if (Memory::IsValidAddress(infoPtr) && Memory::Read_U32(infoPtr)) From 61e240f48274476fd54fe4bd5d6ccb7ee13448cb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 13:35:53 -0700 Subject: [PATCH 08/12] Allocate fpl blocks in a ring, like the PSP. --- Core/HLE/sceKernelMemory.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index 42510d8ad8..a1fea46033 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -69,7 +69,7 @@ struct NativeFPL //FPL - Fixed Length Dynamic Memory Pool - every item has the same length struct FPL : public KernelObject { - FPL() : blocks(NULL) {} + FPL() : blocks(NULL), nextBlock(0) {} ~FPL() { if (blocks != NULL) { delete [] blocks; @@ -83,8 +83,10 @@ struct FPL : public KernelObject int findFreeBlock() { for (int i = 0; i < nf.numBlocks; i++) { - if (!blocks[i]) - return i; + int b = nextBlock++ % nf.numBlocks; + if (!blocks[b]) { + return b; + } } return -1; } @@ -112,6 +114,7 @@ struct FPL : public KernelObject p.DoArray(blocks, nf.numBlocks); p.Do(address); p.Do(alignedSize); + p.Do(nextBlock); FplWaitingThread dv = {0}; p.Do(waitingThreads, dv); p.DoMarker("FPL"); @@ -121,6 +124,7 @@ struct FPL : public KernelObject bool *blocks; u32 address; int alignedSize; + int nextBlock; std::vector waitingThreads; }; From 6c6aa1b8ee2555fa102ed0ad0a9b0d5f132e8277 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 13:45:38 -0700 Subject: [PATCH 09/12] Wrap sceKernelAllocateFpl() and friends. --- Core/HLE/sceKernel.cpp | 6 ++-- Core/HLE/sceKernelMemory.cpp | 57 +++++++++++++++--------------------- Core/HLE/sceKernelMemory.h | 6 ++-- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index f393223d33..4cf1849fa3 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -797,9 +797,9 @@ const HLEFunction ThreadManForUser[] = {0xC07BB470,WrapI_CUUUUU, "sceKernelCreateFpl"}, {0xED1410E0,WrapI_I, "sceKernelDeleteFpl"}, - {0xD979E9BF,sceKernelAllocateFpl,"sceKernelAllocateFpl"}, - {0xE7282CB6,sceKernelAllocateFplCB,"sceKernelAllocateFplCB"}, - {0x623AE665,sceKernelTryAllocateFpl,"sceKernelTryAllocateFpl"}, + {0xD979E9BF,WrapI_IUU, "sceKernelAllocateFpl"}, + {0xE7282CB6,WrapI_IUU, "sceKernelAllocateFplCB"}, + {0x623AE665,WrapI_IU, "sceKernelTryAllocateFpl"}, {0xF6414A71,sceKernelFreeFpl,"sceKernelFreeFpl"}, {0xA8AA591F,WrapI_IU, "sceKernelCancelFpl"}, {0xD8199E4C,WrapI_IU, "sceKernelReferFplStatus"}, diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index a1fea46033..ba1a57c070 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -457,100 +457,89 @@ void __KernelSetFplTimeout(u32 timeoutPtr) CoreTiming::ScheduleEvent(usToCycles(micro), fplWaitTimer, __KernelGetCurThread()); } -void sceKernelAllocateFpl() +int sceKernelAllocateFpl(SceUID uid, u32 blockPtrAddr, u32 timeoutPtr) { - SceUID id = PARAM(0); u32 error; - FPL *fpl = kernelObjects.Get(id, error); + FPL *fpl = kernelObjects.Get(uid, error); if (fpl) { - u32 blockPtrAddr = PARAM(1); - int timeOut = PARAM(2); + DEBUG_LOG(HLE, "sceKernelAllocateFpl(%i, %08x, %08x)", uid, blockPtrAddr, timeoutPtr); int blockNum = fpl->allocateBlock(); if (blockNum >= 0) { u32 blockPtr = fpl->address + fpl->alignedSize * blockNum; Memory::Write_U32(blockPtr, blockPtrAddr); - RETURN(0); } else { SceUID threadID = __KernelGetCurThread(); __KernelFplRemoveThread(fpl, threadID); FplWaitingThread waiting = {threadID, blockPtrAddr}; fpl->waitingThreads.push_back(waiting); - __KernelSetFplTimeout(timeOut); - __KernelWaitCurThread(WAITTYPE_FPL, id, 0, timeOut, false, "fpl waited"); - return; + __KernelSetFplTimeout(timeoutPtr); + __KernelWaitCurThread(WAITTYPE_FPL, uid, 0, timeoutPtr, false, "fpl waited"); } - DEBUG_LOG(HLE,"sceKernelAllocateFpl(%i, %08x, %i)", id, blockPtrAddr, timeOut); - RETURN(0); + return 0; } else { - DEBUG_LOG(HLE,"ERROR: sceKernelAllocateFpl(%i)", id); - RETURN(error); + DEBUG_LOG(HLE, "sceKernelAllocateFpl(%i, %08x, %08x): invalid fpl", uid, blockPtrAddr, timeoutPtr); + return error; } } -void sceKernelAllocateFplCB() +int sceKernelAllocateFplCB(SceUID uid, u32 blockPtrAddr, u32 timeoutPtr) { - SceUID id = PARAM(0); u32 error; - FPL *fpl = kernelObjects.Get(id, error); + FPL *fpl = kernelObjects.Get(uid, error); if (fpl) { - u32 blockPtrAddr = PARAM(1); - int timeOut = PARAM(2); + DEBUG_LOG(HLE, "sceKernelAllocateFplCB(%i, %08x, %08x)", uid, blockPtrAddr, timeoutPtr); int blockNum = fpl->allocateBlock(); if (blockNum >= 0) { u32 blockPtr = fpl->address + fpl->alignedSize * blockNum; Memory::Write_U32(blockPtr, blockPtrAddr); - RETURN(0); } else { SceUID threadID = __KernelGetCurThread(); __KernelFplRemoveThread(fpl, threadID); FplWaitingThread waiting = {threadID, blockPtrAddr}; fpl->waitingThreads.push_back(waiting); - __KernelSetFplTimeout(timeOut); - __KernelWaitCurThread(WAITTYPE_FPL, id, 0, timeOut, true, "fpl waited"); - return; + __KernelSetFplTimeout(timeoutPtr); + __KernelWaitCurThread(WAITTYPE_FPL, uid, 0, timeoutPtr, true, "fpl waited"); } - DEBUG_LOG(HLE,"sceKernelAllocateFpl(%i, %08x, %i)", id, PARAM(1), timeOut); + return 0; } else { - DEBUG_LOG(HLE,"ERROR: sceKernelAllocateFplCB(%i)", id); - RETURN(error); + DEBUG_LOG(HLE, "sceKernelAllocateFplCB(%i, %08x, %08x): invalid fpl", uid, blockPtrAddr, timeoutPtr); + return error; } } -void sceKernelTryAllocateFpl() +int sceKernelTryAllocateFpl(SceUID uid, u32 blockPtrAddr) { - SceUID id = PARAM(0); u32 error; - FPL *fpl = kernelObjects.Get(id, error); + FPL *fpl = kernelObjects.Get(uid, error); if (fpl) { - u32 blockPtrAddr = PARAM(1); - DEBUG_LOG(HLE,"sceKernelTryAllocateFpl(%i, %08x)", id, PARAM(1)); + DEBUG_LOG(HLE, "sceKernelTryAllocateFpl(%i, %08x)", uid, blockPtrAddr); int blockNum = fpl->allocateBlock(); if (blockNum >= 0) { u32 blockPtr = fpl->address + fpl->alignedSize * blockNum; Memory::Write_U32(blockPtr, blockPtrAddr); - RETURN(0); + return 0; } else { - RETURN(SCE_KERNEL_ERROR_NO_MEMORY); + return SCE_KERNEL_ERROR_NO_MEMORY; } } else { - DEBUG_LOG(HLE,"sceKernelTryAllocateFpl(%i) - bad UID", id); - RETURN(error); + DEBUG_LOG(HLE, "sceKernelTryAllocateFpl(%i, %08x): invalid fpl", uid, blockPtrAddr); + return error; } } diff --git a/Core/HLE/sceKernelMemory.h b/Core/HLE/sceKernelMemory.h index b2fba15895..6499df129d 100644 --- a/Core/HLE/sceKernelMemory.h +++ b/Core/HLE/sceKernelMemory.h @@ -48,9 +48,9 @@ int sceKernelReferVplStatus(SceUID uid, u32 infoPtr); int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blocksize, u32 numBlocks, u32 optPtr); int sceKernelDeleteFpl(SceUID uid); -void sceKernelAllocateFpl(); -void sceKernelAllocateFplCB(); -void sceKernelTryAllocateFpl(); +int sceKernelAllocateFpl(SceUID uid, u32 blockPtrAddr, u32 timeoutPtr); +int sceKernelAllocateFplCB(SceUID uid, u32 blockPtrAddr, u32 timeoutPtr); +int sceKernelTryAllocateFpl(SceUID uid, u32 blockPtrAddr); void sceKernelFreeFpl(); int sceKernelCancelFpl(SceUID uid, u32 numWaitThreadsPtr); int sceKernelReferFplStatus(SceUID uid, u32 statusPtr); From 18832f3ca71626046891efc3d91be56f93f19eb9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 15:13:39 -0700 Subject: [PATCH 10/12] Wrap sceKernelFreeFpl() and use better errors. --- Core/HLE/sceKernel.cpp | 2 +- Core/HLE/sceKernelMemory.cpp | 25 ++++++++++++++++--------- Core/HLE/sceKernelMemory.h | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 4cf1849fa3..1d31eca439 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -800,7 +800,7 @@ const HLEFunction ThreadManForUser[] = {0xD979E9BF,WrapI_IUU, "sceKernelAllocateFpl"}, {0xE7282CB6,WrapI_IUU, "sceKernelAllocateFplCB"}, {0x623AE665,WrapI_IU, "sceKernelTryAllocateFpl"}, - {0xF6414A71,sceKernelFreeFpl,"sceKernelFreeFpl"}, + {0xF6414A71,WrapI_IU, "sceKernelFreeFpl"}, {0xA8AA591F,WrapI_IU, "sceKernelCancelFpl"}, {0xD8199E4C,WrapI_IU, "sceKernelReferFplStatus"}, diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index ba1a57c070..c7683f1a21 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -543,21 +543,23 @@ int sceKernelTryAllocateFpl(SceUID uid, u32 blockPtrAddr) } } -void sceKernelFreeFpl() +int sceKernelFreeFpl(SceUID uid, u32 blockPtr) { - SceUID id = PARAM(0); - u32 blockAddr = PARAM(1); + if (blockPtr > PSP_GetUserMemoryEnd()) { + WARN_LOG(HLE, "%08x=sceKernelFreeFpl(%i, %08x): invalid address", SCE_KERNEL_ERROR_ILLEGAL_ADDR, uid, blockPtr); + return SCE_KERNEL_ERROR_ILLEGAL_ADDR; + } - DEBUG_LOG(HLE,"sceKernelFreeFpl(%i, %08x)", id, blockAddr); u32 error; - FPL *fpl = kernelObjects.Get(id, error); + FPL *fpl = kernelObjects.Get(uid, error); if (fpl) { - int blockNum = (blockAddr - fpl->address) / fpl->alignedSize; + int blockNum = (blockPtr - fpl->address) / fpl->alignedSize; if (blockNum < 0 || blockNum >= fpl->nf.numBlocks) { - RETURN(SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCK); + DEBUG_LOG(HLE, "sceKernelFreeFpl(%i, %08x): bad block ptr", uid, blockPtr); + return SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCK; } else { - RETURN(0); if (fpl->freeBlock(blockNum)) { + DEBUG_LOG(HLE, "sceKernelFreeFpl(%i, %08x)", uid, blockPtr); __KernelSortFplThreads(fpl); bool wokeThreads = false; @@ -573,12 +575,17 @@ retry: if (wokeThreads) hleReSchedule("fpl freed"); + return 0; + } else { + DEBUG_LOG(HLE, "sceKernelFreeFpl(%i, %08x): already free", uid, blockPtr); + return SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCK; } } } else { - RETURN(error); + DEBUG_LOG(HLE, "sceKernelFreeFpl(%i, %08x): invalid fpl", uid, blockPtr); + return error; } } diff --git a/Core/HLE/sceKernelMemory.h b/Core/HLE/sceKernelMemory.h index 6499df129d..d9ab052f46 100644 --- a/Core/HLE/sceKernelMemory.h +++ b/Core/HLE/sceKernelMemory.h @@ -51,7 +51,7 @@ int sceKernelDeleteFpl(SceUID uid); int sceKernelAllocateFpl(SceUID uid, u32 blockPtrAddr, u32 timeoutPtr); int sceKernelAllocateFplCB(SceUID uid, u32 blockPtrAddr, u32 timeoutPtr); int sceKernelTryAllocateFpl(SceUID uid, u32 blockPtrAddr); -void sceKernelFreeFpl(); +int sceKernelFreeFpl(SceUID uid, u32 blockPtr); int sceKernelCancelFpl(SceUID uid, u32 numWaitThreadsPtr); int sceKernelReferFplStatus(SceUID uid, u32 statusPtr); From d547d2b3914163ef9069fedd7e0e50b77d2e4521 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 15:37:14 -0700 Subject: [PATCH 11/12] Implement sceKernelCancelMutex(). --- Core/HLE/sceKernel.cpp | 16 +++++----- Core/HLE/sceKernelMutex.cpp | 64 ++++++++++++++++++++++++++++++++++++- Core/HLE/sceKernelMutex.h | 1 + 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 1d31eca439..17d5798005 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -685,14 +685,14 @@ const HLEFunction ThreadManForUser[] = //{0x31327F19,0, "_sceKernelLockLwMutexCB"}, //{0xBEED3A47,0, "_sceKernelUnlockLwMutex"}, - {0xf8170fbe,&WrapI_I, "sceKernelDeleteMutex"}, - {0xB011B11F,&WrapI_IIU, "sceKernelLockMutex", HLE_NOT_DISPATCH_SUSPENDED}, - {0x5bf4dd27,&WrapI_IIU, "sceKernelLockMutexCB", HLE_NOT_DISPATCH_SUSPENDED}, - {0x6b30100f,&WrapI_II, "sceKernelUnlockMutex"}, - {0xb7d098c6,&WrapI_CUIU, "sceKernelCreateMutex"}, - {0x0DDCD2C9,&WrapI_II, "sceKernelTryLockMutex"}, - {0xA9C2CB9A,&WrapI_IU, "sceKernelReferMutexStatus"}, - {0x87D9223C,0, "sceKernelCancelMutex"}, + {0xf8170fbe,WrapI_I, "sceKernelDeleteMutex"}, + {0xB011B11F,WrapI_IIU, "sceKernelLockMutex", HLE_NOT_DISPATCH_SUSPENDED}, + {0x5bf4dd27,WrapI_IIU, "sceKernelLockMutexCB", HLE_NOT_DISPATCH_SUSPENDED}, + {0x6b30100f,WrapI_II, "sceKernelUnlockMutex"}, + {0xb7d098c6,WrapI_CUIU, "sceKernelCreateMutex"}, + {0x0DDCD2C9,WrapI_II, "sceKernelTryLockMutex"}, + {0xA9C2CB9A,WrapI_IU, "sceKernelReferMutexStatus"}, + {0x87D9223C,WrapI_IIU, "sceKernelCancelMutex"}, {0xFCCFAD26,WrapI_I,"sceKernelCancelWakeupThread"}, {0x1AF94D03,0,"sceKernelDonateWakeupThread"}, diff --git a/Core/HLE/sceKernelMutex.cpp b/Core/HLE/sceKernelMutex.cpp index 7e901017e2..1b1ebcb6d9 100644 --- a/Core/HLE/sceKernelMutex.cpp +++ b/Core/HLE/sceKernelMutex.cpp @@ -405,11 +405,11 @@ int sceKernelCreateMutex(const char *name, u32 attr, int initialCount, u32 optio int sceKernelDeleteMutex(SceUID id) { - DEBUG_LOG(HLE,"sceKernelDeleteMutex(%i)", id); u32 error; Mutex *mutex = kernelObjects.Get(id, error); if (mutex) { + DEBUG_LOG(HLE, "sceKernelDeleteMutex(%i)", id); bool wokeThreads = false; std::vector::iterator iter, end; for (iter = mutex->waitingThreads.begin(), end = mutex->waitingThreads.end(); iter != end; ++iter) @@ -425,7 +425,10 @@ int sceKernelDeleteMutex(SceUID id) return kernelObjects.Destroy(id); } else + { + DEBUG_LOG(HLE, "sceKernelDeleteMutex(%i): invalid mutex", id); return error; + } } bool __KernelLockMutexCheck(Mutex *mutex, int count, u32 &error) @@ -567,6 +570,65 @@ void __KernelWaitMutex(Mutex *mutex, u32 timeoutPtr) CoreTiming::ScheduleEvent(usToCycles(micro), mutexWaitTimer, __KernelGetCurThread()); } +int sceKernelCancelMutex(SceUID uid, int count, u32 numWaitThreadsPtr) +{ + u32 error; + Mutex *mutex = kernelObjects.Get(uid, error); + if (mutex) + { + bool lockable = count <= 0 || __KernelLockMutexCheck(mutex, count, error); + if (!lockable) + { + // May still be okay. As long as the count/etc. are valid. + if (error != 0 && error != PSP_MUTEX_ERROR_LOCK_OVERFLOW && error != PSP_MUTEX_ERROR_ALREADY_LOCKED) + { + DEBUG_LOG(HLE, "sceKernelCancelMutex(%i, %d, %08x): invalid count", uid, count, numWaitThreadsPtr); + return error; + } + } + + DEBUG_LOG(HLE, "sceKernelCancelMutex(%i, %d, %08x)", uid, count, numWaitThreadsPtr); + + // Remove threads no longer waiting on this first (so the numWaitThreads value is correct.) + for (auto iter = mutex->waitingThreads.begin(); iter != mutex->waitingThreads.end(); ++iter) + { + SceUID waitID = __KernelGetWaitID(*iter, WAITTYPE_MUTEX, error); + // The thread is no longer waiting for this, clean it up. + if (waitID != uid) + mutex->waitingThreads.erase(iter--); + } + + if (Memory::IsValidAddress(numWaitThreadsPtr)) + Memory::Write_U32((u32)mutex->waitingThreads.size(), numWaitThreadsPtr); + + bool wokeThreads = false; + for (auto iter = mutex->waitingThreads.begin(), end = mutex->waitingThreads.end(); iter != end; ++iter) + wokeThreads |= __KernelUnlockMutexForThread(mutex, *iter, error, SCE_KERNEL_ERROR_WAIT_CANCEL); + + if (mutex->nm.lockThread != -1) + __KernelMutexEraseLock(mutex); + mutex->waitingThreads.clear(); + + if (count <= 0) + { + mutex->nm.lockLevel = 0; + mutex->nm.lockThread = -1; + } + else + __KernelMutexAcquireLock(mutex, count); + + if (wokeThreads) + hleReSchedule("mutex canceled"); + + return 0; + } + else + { + DEBUG_LOG(HLE, "sceKernelCancelMutex(%i, %d, %08x)", uid, count, numWaitThreadsPtr); + return error; + } +} + // int sceKernelLockMutex(SceUID id, int count, int *timeout) int sceKernelLockMutex(SceUID id, int count, u32 timeoutPtr) { diff --git a/Core/HLE/sceKernelMutex.h b/Core/HLE/sceKernelMutex.h index 9e7bf57973..69e63e0709 100644 --- a/Core/HLE/sceKernelMutex.h +++ b/Core/HLE/sceKernelMutex.h @@ -17,6 +17,7 @@ #pragma once +int sceKernelCancelMutex(SceUID uid, int count, u32 numWaitThreadsPtr); int sceKernelCreateMutex(const char *name, u32 attr, int initialCount, u32 optionsPtr); int sceKernelDeleteMutex(SceUID id); int sceKernelLockMutex(SceUID id, int count, u32 timeoutPtr); From 354dbfec6cd2663ccb4bc11180a6c81918c460fc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 25 Aug 2013 16:43:47 -0700 Subject: [PATCH 12/12] Improve some reporting of options structs. --- Core/HLE/sceKernelEventFlag.cpp | 6 +++++- Core/HLE/sceKernelMbx.cpp | 6 +++++- Core/HLE/sceKernelMemory.cpp | 8 ++++++-- Core/HLE/sceKernelMsgPipe.cpp | 6 +++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Core/HLE/sceKernelEventFlag.cpp b/Core/HLE/sceKernelEventFlag.cpp index f1a81ea92b..a281879d9a 100644 --- a/Core/HLE/sceKernelEventFlag.cpp +++ b/Core/HLE/sceKernelEventFlag.cpp @@ -324,7 +324,11 @@ int sceKernelCreateEventFlag(const char *name, u32 flag_attr, u32 flag_initPatte DEBUG_LOG(HLE, "%i=sceKernelCreateEventFlag(\"%s\", %08x, %08x, %08x)", id, e->nef.name, e->nef.attr, e->nef.currentPattern, optPtr); if (optPtr != 0) - WARN_LOG_REPORT(HLE, "sceKernelCreateEventFlag(%s) unsupported options parameter: %08x", name, optPtr); + { + u32 size = Memory::Read_U32(optPtr); + if (size > 4) + WARN_LOG_REPORT(HLE, "sceKernelCreateEventFlag(%s) unsupported options parameter, size = %d", name, size); + } if ((flag_attr & ~PSP_EVENT_WAITMULTIPLE) != 0) WARN_LOG_REPORT(HLE, "sceKernelCreateEventFlag(%s) unsupported attr parameter: %08x", name, flag_attr); diff --git a/Core/HLE/sceKernelMbx.cpp b/Core/HLE/sceKernelMbx.cpp index 6321420931..86bc38fe7c 100644 --- a/Core/HLE/sceKernelMbx.cpp +++ b/Core/HLE/sceKernelMbx.cpp @@ -316,7 +316,11 @@ SceUID sceKernelCreateMbx(const char *name, u32 attr, u32 optAddr) DEBUG_LOG(HLE, "%i=sceKernelCreateMbx(%s, %08x, %08x)", id, name, attr, optAddr); if (optAddr != 0) - WARN_LOG_REPORT(HLE, "sceKernelCreateMbx(%s) unsupported options parameter: %08x", name, optAddr); + { + u32 size = Memory::Read_U32(optAddr); + if (size > 4) + WARN_LOG_REPORT(HLE, "sceKernelCreateMbx(%s) unsupported options parameter, size = %d", name, size); + } if ((attr & ~SCE_KERNEL_MBA_ATTR_KNOWN) != 0) WARN_LOG_REPORT(HLE, "sceKernelCreateMbx(%s) unsupported attr parameter: %08x", name, attr); diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index c7683f1a21..b983e14c3f 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -1700,9 +1700,13 @@ SceUID sceKernelCreateTls(const char *name, u32 partition, u32 attr, u32 blockSi // TODO: just alignment? if (optionsPtr != 0) - WARN_LOG(HLE, "sceKernelCreateTls(%s) unsupported options parameter: %08x", name, optionsPtr); + { + u32 size = Memory::Read_U32(optionsPtr); + if (size > 4) + WARN_LOG_REPORT(HLE, "sceKernelCreateTls(%s) unsupported options parameter, size = %d", name, size); + } if ((attr & PSP_TLS_ATTR_PRIORITY) != 0) - WARN_LOG(HLE, "sceKernelCreateTls(%s) unsupported attr parameter: %08x", name, attr); + WARN_LOG_REPORT(HLE, "sceKernelCreateTls(%s) unsupported attr parameter: %08x", name, attr); return id; } diff --git a/Core/HLE/sceKernelMsgPipe.cpp b/Core/HLE/sceKernelMsgPipe.cpp index 7915e94502..f9dabf406a 100644 --- a/Core/HLE/sceKernelMsgPipe.cpp +++ b/Core/HLE/sceKernelMsgPipe.cpp @@ -399,7 +399,11 @@ int sceKernelCreateMsgPipe(const char *name, int partition, u32 attr, u32 size, DEBUG_LOG(HLE, "%d=sceKernelCreateMsgPipe(%s, part=%d, attr=%08x, size=%d, opt=%08x)", id, name, partition, attr, size, optionsPtr); if (optionsPtr != 0) - WARN_LOG_REPORT(HLE, "sceKernelCreateMsgPipe(%s) unsupported options parameter: %08x", name, optionsPtr); + { + u32 size = Memory::Read_U32(optionsPtr); + if (size > 4) + WARN_LOG_REPORT(HLE, "sceKernelCreateMsgPipe(%s) unsupported options parameter, size = %d", name, size); + } return id; }