diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index 99073cb919..d8534b01aa 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -216,6 +216,9 @@ int __CtrlReadBuffer(u32 ctrlDataPtr, u32 nBufs, bool negative, bool peek) if (nBufs > NUM_CTRL_BUFFERS) return SCE_KERNEL_ERROR_INVALID_SIZE; + if (!peek && !__KernelIsDispatchEnabled()) + return SCE_KERNEL_ERROR_CAN_NOT_WAIT; + u32 resetRead = ctrlBufRead; u32 availBufs; diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index c112222eaf..5fb0f03b03 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -626,6 +626,8 @@ u32 sceDisplayWaitVblankStartMulti(int vblanks) { return SCE_KERNEL_ERROR_INVALID_VALUE; } VERBOSE_LOG(HLE, "sceDisplayWaitVblankStartMulti(%d)", vblanks); + if (!__KernelIsDispatchEnabled()) + return SCE_KERNEL_ERROR_CAN_NOT_WAIT; vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread(), vblanks)); __KernelWaitCurThread(WAITTYPE_VBLANK, 0, 0, 0, false, "vblank start multi waited"); return 0; @@ -657,6 +659,8 @@ u32 sceDisplayWaitVblankStartMultiCB(int vblanks) { return SCE_KERNEL_ERROR_INVALID_VALUE; } VERBOSE_LOG(HLE,"sceDisplayWaitVblankStartMultiCB(%d)", vblanks); + if (!__KernelIsDispatchEnabled()) + return SCE_KERNEL_ERROR_CAN_NOT_WAIT; vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread(), vblanks)); __KernelWaitCurThread(WAITTYPE_VBLANK, 0, 0, 0, true, "vblank start multi waited"); return 0; @@ -749,10 +753,10 @@ const HLEFunction sceDisplay[] = { {0xEEDA2E54,WrapU_UUUI,"sceDisplayGetFrameBuf"}, {0x36CDFADE,WrapU_V, "sceDisplayWaitVblank", HLE_NOT_DISPATCH_SUSPENDED}, {0x984C27E7,WrapU_V, "sceDisplayWaitVblankStart", HLE_NOT_DISPATCH_SUSPENDED}, - {0x40f1469c,WrapU_I, "sceDisplayWaitVblankStartMulti", HLE_NOT_DISPATCH_SUSPENDED}, + {0x40f1469c,WrapU_I, "sceDisplayWaitVblankStartMulti"}, {0x8EB9EC49,WrapU_V, "sceDisplayWaitVblankCB", HLE_NOT_DISPATCH_SUSPENDED}, {0x46F186C3,WrapU_V, "sceDisplayWaitVblankStartCB", HLE_NOT_DISPATCH_SUSPENDED}, - {0x77ed8b3a,WrapU_I,"sceDisplayWaitVblankStartMultiCB", HLE_NOT_DISPATCH_SUSPENDED}, + {0x77ed8b3a,WrapU_I,"sceDisplayWaitVblankStartMultiCB"}, {0xdba6c4c4,WrapF_V,"sceDisplayGetFramePerSec"}, {0x773dd3a3,WrapU_V,"sceDisplayGetCurrentHcount"}, {0x210eab3a,WrapU_V,"sceDisplayGetAccumulatedHcount"}, diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index a1663778b8..1012d15ba3 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -769,8 +769,8 @@ const HLEFunction ThreadManForUser[] = {0x8125221D,WrapI_CUU, "sceKernelCreateMbx"}, {0x86255ADA,WrapI_I, "sceKernelDeleteMbx"}, {0xE9B3061E,WrapI_IU, "sceKernelSendMbx"}, - {0x18260574,WrapI_IUU, "sceKernelReceiveMbx"}, - {0xF3986382,WrapI_IUU, "sceKernelReceiveMbxCB"}, + {0x18260574,WrapI_IUU, "sceKernelReceiveMbx", HLE_NOT_DISPATCH_SUSPENDED}, + {0xF3986382,WrapI_IUU, "sceKernelReceiveMbxCB", HLE_NOT_DISPATCH_SUSPENDED}, {0x0D81716A,WrapI_IU, "sceKernelPollMbx"}, {0x87D4DD36,WrapI_IU, "sceKernelCancelReceiveMbx"}, {0xA8E8C846,WrapI_IU, "sceKernelReferMbxStatus"}, @@ -788,8 +788,8 @@ const HLEFunction ThreadManForUser[] = {0x56C039B5,WrapI_CIUUU, "sceKernelCreateVpl"}, {0x89B3D48C,WrapI_I, "sceKernelDeleteVpl"}, - {0xBED27435,WrapI_IUUU, "sceKernelAllocateVpl"}, - {0xEC0A693F,WrapI_IUUU, "sceKernelAllocateVplCB"}, + {0xBED27435,WrapI_IUUU, "sceKernelAllocateVpl", HLE_NOT_DISPATCH_SUSPENDED}, + {0xEC0A693F,WrapI_IUUU, "sceKernelAllocateVplCB", HLE_NOT_DISPATCH_SUSPENDED}, {0xAF36D708,WrapI_IUU, "sceKernelTryAllocateVpl"}, {0xB736E9FF,WrapI_IU, "sceKernelFreeVpl"}, {0x1D371B8A,WrapI_IU, "sceKernelCancelVpl"}, @@ -797,8 +797,8 @@ const HLEFunction ThreadManForUser[] = {0xC07BB470,WrapI_CUUUUU, "sceKernelCreateFpl"}, {0xED1410E0,WrapI_I, "sceKernelDeleteFpl"}, - {0xD979E9BF,WrapI_IUU, "sceKernelAllocateFpl"}, - {0xE7282CB6,WrapI_IUU, "sceKernelAllocateFplCB"}, + {0xD979E9BF,WrapI_IUU, "sceKernelAllocateFpl", HLE_NOT_DISPATCH_SUSPENDED}, + {0xE7282CB6,WrapI_IUU, "sceKernelAllocateFplCB", HLE_NOT_DISPATCH_SUSPENDED}, {0x623AE665,WrapI_IU, "sceKernelTryAllocateFpl"}, {0xF6414A71,WrapI_IU, "sceKernelFreeFpl"}, {0xA8AA591F,WrapI_IU, "sceKernelCancelFpl"}, diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index b983e14c3f..cbda9f753d 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -1731,6 +1731,10 @@ int sceKernelAllocateTls(SceUID uid) { // TODO: Allocate downward if PSP_TLS_ATTR_HIGHMEM? DEBUG_LOG(HLE, "sceKernelAllocateTls(%08x)", uid); + + if (!__KernelIsDispatchEnabled()) + return 0; + u32 error; TLS *tls = kernelObjects.Get(uid, error); if (tls) diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 3bea2c32ee..c8070ca40d 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -1512,9 +1512,9 @@ const HLEFunction ModuleMgrForUser[] = { {0x977DE386,&WrapU_CUU,"sceKernelLoadModule"}, {0xb7f46618,&WrapU_UUU,"sceKernelLoadModuleByID"}, - {0x50F0C1EC,&WrapV_UUUUU,"sceKernelStartModule"}, + {0x50F0C1EC,&WrapV_UUUUU,"sceKernelStartModule", HLE_NOT_DISPATCH_SUSPENDED}, {0xD675EBB8,&sceKernelExitGame,"sceKernelSelfStopUnloadModule"}, //HACK - {0xd1ff982a,&WrapU_UUUUU,"sceKernelStopModule"}, + {0xd1ff982a,&WrapU_UUUUU,"sceKernelStopModule", HLE_NOT_DISPATCH_SUSPENDED}, {0x2e0911aa,WrapU_U,"sceKernelUnloadModule"}, {0x710F61B5,0,"sceKernelLoadModuleMs"}, {0xF9275D98,0,"sceKernelLoadModuleBufferUsbWlan"}, ///??? diff --git a/Core/HLE/sceKernelMsgPipe.cpp b/Core/HLE/sceKernelMsgPipe.cpp index f9dabf406a..a4062d2669 100644 --- a/Core/HLE/sceKernelMsgPipe.cpp +++ b/Core/HLE/sceKernelMsgPipe.cpp @@ -427,11 +427,8 @@ int sceKernelDeleteMsgPipe(SceUID uid) return kernelObjects.Destroy(uid); } -int __KernelSendMsgPipe(MsgPipe *m, u32 sendBufAddr, u32 sendSize, int waitMode, u32 resultAddr, u32 timeoutPtr, bool cbEnabled, bool poll) +int __KernelValidateSendMsgPipe(SceUID uid, u32 sendBufAddr, u32 sendSize, int waitMode, u32 resultAddr) { - u32 curSendAddr = sendBufAddr; - SceUID uid = m->GetUID(); - if (sendSize & 0x80000000) { ERROR_LOG(HLE, "__KernelSendMsgPipe(%d): illegal size %d", uid, sendSize); @@ -450,6 +447,20 @@ int __KernelSendMsgPipe(MsgPipe *m, u32 sendBufAddr, u32 sendSize, int waitMode, return SCE_KERNEL_ERROR_ILLEGAL_MODE; } + if (!__KernelIsDispatchEnabled()) + { + WARN_LOG(HLE, "__KernelSendMsgPipe(%d): dispatch disabled", uid, waitMode); + return SCE_KERNEL_ERROR_CAN_NOT_WAIT; + } + + return 0; +} + +int __KernelSendMsgPipe(MsgPipe *m, u32 sendBufAddr, u32 sendSize, int waitMode, u32 resultAddr, u32 timeoutPtr, bool cbEnabled, bool poll) +{ + u32 curSendAddr = sendBufAddr; + SceUID uid = m->GetUID(); + // If the buffer size is 0, nothing is buffered and all operations wait. if (m->nmp.bufSize == 0) { @@ -551,7 +562,10 @@ int __KernelSendMsgPipe(MsgPipe *m, u32 sendBufAddr, u32 sendSize, int waitMode, int sceKernelSendMsgPipe(SceUID uid, u32 sendBufAddr, u32 sendSize, u32 waitMode, u32 resultAddr, u32 timeoutPtr) { - u32 error; + u32 error = __KernelValidateSendMsgPipe(uid, sendBufAddr, sendSize, waitMode, resultAddr); + if (error != 0) { + return error; + } MsgPipe *m = kernelObjects.Get(uid, error); if (!m) { ERROR_LOG(HLE, "sceKernelSendMsgPipe(%i) - ERROR %08x", uid, error); @@ -564,7 +578,10 @@ int sceKernelSendMsgPipe(SceUID uid, u32 sendBufAddr, u32 sendSize, u32 waitMode int sceKernelSendMsgPipeCB(SceUID uid, u32 sendBufAddr, u32 sendSize, u32 waitMode, u32 resultAddr, u32 timeoutPtr) { - u32 error; + u32 error = __KernelValidateSendMsgPipe(uid, sendBufAddr, sendSize, waitMode, resultAddr); + if (error != 0) { + return error; + } MsgPipe *m = kernelObjects.Get(uid, error); if (!m) { ERROR_LOG(HLE, "sceKernelSendMsgPipeCB(%i) - ERROR %08x", uid, error); @@ -579,7 +596,10 @@ int sceKernelSendMsgPipeCB(SceUID uid, u32 sendBufAddr, u32 sendSize, u32 waitMo int sceKernelTrySendMsgPipe(SceUID uid, u32 sendBufAddr, u32 sendSize, u32 waitMode, u32 resultAddr) { - u32 error; + u32 error = __KernelValidateSendMsgPipe(uid, sendBufAddr, sendSize, waitMode, resultAddr); + if (error != 0) { + return error; + } MsgPipe *m = kernelObjects.Get(uid, error); if (!m) { ERROR_LOG(HLE, "sceKernelTrySendMsgPipe(%i) - ERROR %08x", uid, error); @@ -590,11 +610,8 @@ int sceKernelTrySendMsgPipe(SceUID uid, u32 sendBufAddr, u32 sendSize, u32 waitM return __KernelSendMsgPipe(m, sendBufAddr, sendSize, waitMode, resultAddr, 0, false, true); } -int __KernelReceiveMsgPipe(MsgPipe *m, u32 receiveBufAddr, u32 receiveSize, int waitMode, u32 resultAddr, u32 timeoutPtr, bool cbEnabled, bool poll) +int __KernelValidateReceiveMsgPipe(SceUID uid, u32 receiveBufAddr, u32 receiveSize, int waitMode, u32 resultAddr) { - u32 curReceiveAddr = receiveBufAddr; - SceUID uid = m->GetUID(); - if (receiveSize & 0x80000000) { ERROR_LOG(HLE, "__KernelReceiveMsgPipe(%d): illegal size %d", uid, receiveSize); @@ -613,6 +630,20 @@ int __KernelReceiveMsgPipe(MsgPipe *m, u32 receiveBufAddr, u32 receiveSize, int return SCE_KERNEL_ERROR_ILLEGAL_MODE; } + if (!__KernelIsDispatchEnabled()) + { + WARN_LOG(HLE, "__KernelReceiveMsgPipe(%d): dispatch disabled", uid, waitMode); + return SCE_KERNEL_ERROR_CAN_NOT_WAIT; + } + + return 0; +} + +int __KernelReceiveMsgPipe(MsgPipe *m, u32 receiveBufAddr, u32 receiveSize, int waitMode, u32 resultAddr, u32 timeoutPtr, bool cbEnabled, bool poll) +{ + u32 curReceiveAddr = receiveBufAddr; + SceUID uid = m->GetUID(); + // MsgPipe buffer size is 0, receiving directly from waiting send threads if (m->nmp.bufSize == 0) { @@ -712,7 +743,10 @@ int __KernelReceiveMsgPipe(MsgPipe *m, u32 receiveBufAddr, u32 receiveSize, int int sceKernelReceiveMsgPipe(SceUID uid, u32 receiveBufAddr, u32 receiveSize, u32 waitMode, u32 resultAddr, u32 timeoutPtr) { - u32 error; + u32 error = __KernelValidateReceiveMsgPipe(uid, receiveBufAddr, receiveSize, waitMode, resultAddr); + if (error != 0) { + return error; + } MsgPipe *m = kernelObjects.Get(uid, error); if (!m) { ERROR_LOG(HLE, "sceKernelReceiveMsgPipe(%i) - ERROR %08x", uid, error); @@ -725,7 +759,10 @@ int sceKernelReceiveMsgPipe(SceUID uid, u32 receiveBufAddr, u32 receiveSize, u32 int sceKernelReceiveMsgPipeCB(SceUID uid, u32 receiveBufAddr, u32 receiveSize, u32 waitMode, u32 resultAddr, u32 timeoutPtr) { - u32 error; + u32 error = __KernelValidateReceiveMsgPipe(uid, receiveBufAddr, receiveSize, waitMode, resultAddr); + if (error != 0) { + return error; + } MsgPipe *m = kernelObjects.Get(uid, error); if (!m) { ERROR_LOG(HLE, "sceKernelReceiveMsgPipeCB(%i) - ERROR %08x", uid, error); @@ -740,7 +777,10 @@ int sceKernelReceiveMsgPipeCB(SceUID uid, u32 receiveBufAddr, u32 receiveSize, u int sceKernelTryReceiveMsgPipe(SceUID uid, u32 receiveBufAddr, u32 receiveSize, u32 waitMode, u32 resultAddr) { - u32 error; + u32 error = __KernelValidateReceiveMsgPipe(uid, receiveBufAddr, receiveSize, waitMode, resultAddr); + if (error != 0) { + return error; + } MsgPipe *m = kernelObjects.Get(uid, error); if (!m) { ERROR_LOG(HLE, "sceKernelTryReceiveMsgPipe(%i) - ERROR %08x", uid, error); diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 5e9237e775..12508d7798 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -2541,6 +2541,9 @@ int sceKernelWaitThreadEnd(SceUID threadID, u32 timeoutPtr) if (threadID == 0 || threadID == currentThread) return SCE_KERNEL_ERROR_ILLEGAL_THID; + if (!__KernelIsDispatchEnabled()) + return SCE_KERNEL_ERROR_CAN_NOT_WAIT; + u32 error; Thread *t = kernelObjects.Get(threadID, error); if (t) @@ -2567,6 +2570,9 @@ int sceKernelWaitThreadEndCB(SceUID threadID, u32 timeoutPtr) if (threadID == 0 || threadID == currentThread) return SCE_KERNEL_ERROR_ILLEGAL_THID; + if (!__KernelIsDispatchEnabled()) + return SCE_KERNEL_ERROR_CAN_NOT_WAIT; + u32 error; Thread *t = kernelObjects.Get(threadID, error); if (t)