diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 64ceb0058c..b9d1028b48 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -820,7 +820,7 @@ const HLEFunction ThreadManForUser[] = {0X87D4DD36, &WrapI_IU, "sceKernelCancelReceiveMbx", 'i', "ix" }, {0XA8E8C846, &WrapI_IU, "sceKernelReferMbxStatus", 'i', "ip" }, - {0X7C0DC2A0, &WrapI_CIUUU, "sceKernelCreateMsgPipe", 'i', "sixxx" }, + {0X7C0DC2A0, &WrapI_CIUUU, "sceKernelCreateMsgPipe", 'i', "sixxp" }, {0XF0B7DA1C, &WrapI_I, "sceKernelDeleteMsgPipe", 'i', "i" }, {0X876DBFAD, &WrapI_IUUUUU, "sceKernelSendMsgPipe", 'i', "ixxxxx" }, {0X7C41F2C2, &WrapI_IUUUUU, "sceKernelSendMsgPipeCB", 'i', "ixxxxx" }, diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index c3fd130d02..7e54e45b96 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -504,7 +504,7 @@ void __KernelMemoryShutdown() MemBlockInfoShutdown(); } -static BlockAllocator *BlockAllocatorFromID(int id) { +BlockAllocator *BlockAllocatorFromID(int id) { switch (id) { case 1: case 3: @@ -529,7 +529,7 @@ static BlockAllocator *BlockAllocatorFromID(int id) { return nullptr; } -static int BlockAllocatorToID(const BlockAllocator *alloc) { +int BlockAllocatorToID(const BlockAllocator *alloc) { if (alloc == &kernelMemory) return 1; if (alloc == &userMemory) @@ -539,7 +539,7 @@ static int BlockAllocatorToID(const BlockAllocator *alloc) { return 0; } -static BlockAllocator *BlockAllocatorFromAddr(u32 addr) { +BlockAllocator *BlockAllocatorFromAddr(u32 addr) { addr &= 0x3FFFFFFF; if (Memory::IsKernelAndNotVolatileAddress(addr)) return &kernelMemory; diff --git a/Core/HLE/sceKernelMemory.h b/Core/HLE/sceKernelMemory.h index 29d7356d00..b217974170 100644 --- a/Core/HLE/sceKernelMemory.h +++ b/Core/HLE/sceKernelMemory.h @@ -40,6 +40,10 @@ KernelObject *__KernelMemoryVPLObject(); KernelObject *__KernelMemoryPMBObject(); KernelObject *__KernelTlsplObject(); +BlockAllocator *BlockAllocatorFromID(int id); +int BlockAllocatorToID(const BlockAllocator *alloc); +BlockAllocator *BlockAllocatorFromAddr(u32 addr); + SceUID sceKernelCreateVpl(const char *name, int partition, u32 attr, u32 vplSize, u32 optPtr); int sceKernelDeleteVpl(SceUID uid); int sceKernelAllocateVpl(SceUID uid, u32 size, u32 addrPtr, u32 timeoutPtr); diff --git a/Core/HLE/sceKernelMsgPipe.cpp b/Core/HLE/sceKernelMsgPipe.cpp index b16e8060e2..0ff34c6290 100644 --- a/Core/HLE/sceKernelMsgPipe.cpp +++ b/Core/HLE/sceKernelMsgPipe.cpp @@ -140,10 +140,13 @@ struct MsgPipe : public KernelObject int GetIDType() const override { return SCE_KERNEL_TMID_Mpipe; } MsgPipe() : buffer(0) {} - ~MsgPipe() - { - if (buffer != 0) - userMemory.Free(buffer); + ~MsgPipe() { + if (buffer != 0) { + BlockAllocator *alloc = BlockAllocatorFromAddr(buffer); + _assert_msg_(alloc != nullptr, "Should always have a valid allocator/address"); + if (alloc) + alloc->Free(buffer); + } } u32 GetUsedSize() @@ -667,41 +670,26 @@ void __KernelMsgPipeDoState(PointerWrap &p) CoreTiming::RestoreRegisterEvent(waitTimer, "MsgPipeTimeout", __KernelMsgPipeTimeout); } -int sceKernelCreateMsgPipe(const char *name, int partition, u32 attr, u32 size, u32 optionsPtr) -{ +int sceKernelCreateMsgPipe(const char *name, int partition, u32 attr, u32 size, u32 optionsPtr) { if (!name) - { - WARN_LOG_REPORT(SCEKERNEL, "%08x=sceKernelCreateMsgPipe(): invalid name", SCE_KERNEL_ERROR_NO_MEMORY); - return SCE_KERNEL_ERROR_NO_MEMORY; - } + return hleLogWarning(SCEKERNEL, SCE_KERNEL_ERROR_NO_MEMORY, "invalid name"); if (partition < 1 || partition > 9 || partition == 7) - { - WARN_LOG_REPORT(SCEKERNEL, "%08x=sceKernelCreateMsgPipe(): invalid partition %d", SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, partition); - return SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT; - } - // We only support user right now. - if (partition != 2 && partition != 6) - { - WARN_LOG_REPORT(SCEKERNEL, "%08x=sceKernelCreateMsgPipe(): invalid partition %d", SCE_KERNEL_ERROR_ILLEGAL_PERM, partition); - return SCE_KERNEL_ERROR_ILLEGAL_PERM; - } + return hleLogWarning(SCEKERNEL, SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, "invalid partition %d", partition); + + BlockAllocator *allocator = BlockAllocatorFromID(partition); + if (allocator == nullptr) + return hleLogWarning(SCEKERNEL, SCE_KERNEL_ERROR_ILLEGAL_PERM, "invalid partition %d", partition); + if ((attr & ~SCE_KERNEL_MPA_KNOWN) >= 0x100) - { - WARN_LOG_REPORT(SCEKERNEL, "%08x=sceKernelCreateEventFlag(%s): invalid attr parameter: %08x", SCE_KERNEL_ERROR_ILLEGAL_ATTR, name, attr); - return SCE_KERNEL_ERROR_ILLEGAL_ATTR; - } + return hleLogWarning(SCEKERNEL, SCE_KERNEL_ERROR_ILLEGAL_ATTR, "invalid attr parameter: %08x", attr); u32 memBlockPtr = 0; - if (size != 0) - { + if (size != 0) { // We ignore the upalign to 256. u32 allocSize = size; - memBlockPtr = userMemory.Alloc(allocSize, (attr & SCE_KERNEL_MPA_HIGHMEM) != 0, "MsgPipe"); + memBlockPtr = allocator->Alloc(allocSize, (attr & SCE_KERNEL_MPA_HIGHMEM) != 0, "MsgPipe"); if (memBlockPtr == (u32)-1) - { - ERROR_LOG(SCEKERNEL, "%08x=sceKernelCreateEventFlag(%s): Failed to allocate %i bytes for buffer", SCE_KERNEL_ERROR_NO_MEMORY, name, size); - return SCE_KERNEL_ERROR_NO_MEMORY; - } + return hleLogError(SCEKERNEL, SCE_KERNEL_ERROR_NO_MEMORY, "failed to allocate %i bytes for buffer", size); } MsgPipe *m = new MsgPipe();