A lot of log cleanup. It's quite useful as a forcing function to find missing logs.

This commit is contained in:
Henrik Rydgård
2025-03-05 17:02:46 +01:00
parent 41e3591c8a
commit cb180bf781
4 changed files with 105 additions and 181 deletions
+56 -84
View File
@@ -380,10 +380,10 @@ public:
void GetQuickInfo(char *ptr, int size) override {
snprintf(ptr, size, "pc= %08x sp= %08x %s %s %s %s %s %s (wt=%i wid=%i wv= %08x )",
context.pc, context.r[MIPS_REG_SP],
(nt.status & THREADSTATUS_RUNNING) ? "RUN" : "",
(nt.status & THREADSTATUS_READY) ? "READY" : "",
(nt.status & THREADSTATUS_WAIT) ? "WAIT" : "",
(nt.status & THREADSTATUS_SUSPEND) ? "SUSPEND" : "",
(nt.status & THREADSTATUS_RUNNING) ? "RUN" : "",
(nt.status & THREADSTATUS_READY) ? "READY" : "",
(nt.status & THREADSTATUS_WAIT) ? "WAIT" : "",
(nt.status & THREADSTATUS_SUSPEND) ? "SUSPEND" : "",
(nt.status & THREADSTATUS_DORMANT) ? "DORMANT" : "",
(nt.status & THREADSTATUS_DEAD) ? "DEAD" : "",
(int)nt.waitType,
@@ -1904,7 +1904,7 @@ PSPThread *__KernelCreateThreadObject(SceUID &id, SceUID moduleId, const char *n
return t;
}
SceUID __KernelSetupRootThread(SceUID moduleID, int args, const char *argp, int prio, int stacksize, int attr)
SceUID __KernelSetupRootThread(SceUID moduleID, int args, const char *argp, int prio, int stacksize, int attr)
{
//grab mips regs
SceUID id;
@@ -1985,7 +1985,7 @@ int __KernelCreateThread(const char *threadName, SceUID moduleID, u32 entry, u32
if ((attr & PSP_THREAD_ATTR_KERNEL) == 0) {
if (allowKernel && (attr & PSP_THREAD_ATTR_USER) == 0) {
attr |= PSP_THREAD_ATTR_KERNEL;
} else {
} else {
attr |= PSP_THREAD_ATTR_USER;
}
}
@@ -2663,21 +2663,20 @@ int sceKernelSleepThreadCB() {
return __KernelSleepThread(true);
}
int sceKernelWaitThreadEnd(SceUID threadID, u32 timeoutPtr)
{
DEBUG_LOG(Log::sceKernel, "sceKernelWaitThreadEnd(%i, %08x)", threadID, timeoutPtr);
int sceKernelWaitThreadEnd(SceUID threadID, u32 timeoutPtr) {
if (threadID == 0 || threadID == currentThread)
return SCE_KERNEL_ERROR_ILLEGAL_THID;
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_THID);
if (!__KernelIsDispatchEnabled())
return SCE_KERNEL_ERROR_CAN_NOT_WAIT;
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_CAN_NOT_WAIT);
if (__IsInInterrupt())
return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT;
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_CONTEXT);
u32 error;
PSPThread *t = kernelObjects.Get<PSPThread>(threadID, error);
if (t)
{
if (!t) {
return hleLogError(Log::sceKernel, error, "bad thread ID");
} else {
if (t->nt.status != THREADSTATUS_DORMANT)
{
if (Memory::IsValidAddress(timeoutPtr))
@@ -2687,30 +2686,24 @@ int sceKernelWaitThreadEnd(SceUID threadID, u32 timeoutPtr)
__KernelWaitCurThread(WAITTYPE_THREADEND, threadID, 0, timeoutPtr, false, "thread wait end");
}
return t->nt.exitStatus;
}
else
{
ERROR_LOG(Log::sceKernel, "sceKernelWaitThreadEnd - bad thread %i", threadID);
return error;
return hleLogDebug(Log::sceKernel, t->nt.exitStatus);
}
}
int sceKernelWaitThreadEndCB(SceUID threadID, u32 timeoutPtr)
{
DEBUG_LOG(Log::sceKernel, "sceKernelWaitThreadEndCB(%i, 0x%X)", threadID, timeoutPtr);
int sceKernelWaitThreadEndCB(SceUID threadID, u32 timeoutPtr) {
if (threadID == 0 || threadID == currentThread)
return SCE_KERNEL_ERROR_ILLEGAL_THID;
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_THID);
if (!__KernelIsDispatchEnabled())
return SCE_KERNEL_ERROR_CAN_NOT_WAIT;
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_CAN_NOT_WAIT);
if (__IsInInterrupt())
return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT;
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_CONTEXT);
u32 error;
PSPThread *t = kernelObjects.Get<PSPThread>(threadID, error);
if (t)
{
if (!t) {
return hleLogError(Log::sceKernel, error, "bad thread ID");
} else {
if (t->nt.status != THREADSTATUS_DORMANT)
{
if (Memory::IsValidAddress(timeoutPtr))
@@ -2724,84 +2717,61 @@ int sceKernelWaitThreadEndCB(SceUID threadID, u32 timeoutPtr)
return t->nt.exitStatus;
}
else
{
ERROR_LOG(Log::sceKernel, "sceKernelWaitThreadEndCB - bad thread %i", threadID);
return error;
}
}
int sceKernelReleaseWaitThread(SceUID threadID)
{
DEBUG_LOG(Log::sceKernel, "sceKernelReleaseWaitThread(%i)", threadID);
int sceKernelReleaseWaitThread(SceUID threadID) {
if (__KernelInCallback())
WARN_LOG_REPORT(Log::sceKernel, "UNTESTED sceKernelReleaseWaitThread() might not do the right thing in a callback");
if (threadID == 0 || threadID == currentThread)
return SCE_KERNEL_ERROR_ILLEGAL_THID;
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_THID);
u32 error;
PSPThread *t = kernelObjects.Get<PSPThread>(threadID, error);
if (t)
{
if (!t) {
return hleLogError(Log::sceKernel, error, "bad thread ID");
} else {
if (!t->isWaiting())
return SCE_KERNEL_ERROR_NOT_WAIT;
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_NOT_WAIT);
if (t->nt.waitType == WAITTYPE_HLEDELAY)
{
WARN_LOG_REPORT_ONCE(rwt_delay, Log::sceKernel, "sceKernelReleaseWaitThread(): Refusing to wake HLE-delayed thread, right thing to do?");
return SCE_KERNEL_ERROR_NOT_WAIT;
return hleNoLog(SCE_KERNEL_ERROR_NOT_WAIT);
}
if (t->nt.waitType == WAITTYPE_MODULE)
{
WARN_LOG_REPORT_ONCE(rwt_sm, Log::sceKernel, "sceKernelReleaseWaitThread(): Refusing to wake start_module thread, right thing to do?");
return SCE_KERNEL_ERROR_NOT_WAIT;
return hleNoLog(SCE_KERNEL_ERROR_NOT_WAIT);
}
__KernelResumeThreadFromWait(threadID, SCE_KERNEL_ERROR_RELEASE_WAIT);
hleReSchedule("thread released from wait");
return 0;
}
else
{
ERROR_LOG(Log::sceKernel, "sceKernelReleaseWaitThread - bad thread %i", threadID);
return error;
return hleLogDebug(Log::sceKernel, 0);
}
}
int sceKernelSuspendThread(SceUID threadID)
{
int sceKernelSuspendThread(SceUID threadID) {
// TODO: What about interrupts/callbacks?
if (threadID == 0 || threadID == currentThread)
{
ERROR_LOG(Log::sceKernel, "sceKernelSuspendThread(%d): cannot suspend current thread", threadID);
return SCE_KERNEL_ERROR_ILLEGAL_THID;
if (threadID == 0 || threadID == currentThread) {
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_THID, "cannot suspend current thread");
}
u32 error;
PSPThread *t = kernelObjects.Get<PSPThread>(threadID, error);
if (t)
{
if (t->isStopped())
{
ERROR_LOG(Log::sceKernel, "sceKernelSuspendThread(%d): thread not running", threadID);
return SCE_KERNEL_ERROR_DORMANT;
if (!t) {
return hleLogError(Log::sceKernel, error, "bad thread ID");
} else {
if (t->isStopped()) {
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_DORMANT, "thread not running");
}
if (t->isSuspended())
{
ERROR_LOG(Log::sceKernel, "sceKernelSuspendThread(%d): thread already suspended", threadID);
return SCE_KERNEL_ERROR_SUSPEND;
if (t->isSuspended()) {
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_SUSPEND, "thread already suspended");
}
DEBUG_LOG(Log::sceKernel, "sceKernelSuspendThread(%d)", threadID);
if (t->isReady())
__KernelChangeReadyState(t, threadID, false);
t->nt.status = (t->nt.status & ~THREADSTATUS_READY) | THREADSTATUS_SUSPEND;
return 0;
}
else
{
ERROR_LOG(Log::sceKernel, "sceKernelSuspendThread(%d): bad thread", threadID);
return error;
return hleLogDebug(Log::sceKernel, 0);
}
}
@@ -2814,7 +2784,7 @@ int sceKernelResumeThread(SceUID threadID) {
u32 error;
PSPThread *t = kernelObjects.Get<PSPThread>(threadID, error);
if (!t) {
return hleLogError(Log::sceKernel, error, "bad thread");
return hleLogError(Log::sceKernel, error, "bad thread ID");
} else {
if (!t->isSuspended()) {
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_NOT_SUSPEND, "sceKernelResumeThread(%d): thread not suspended", threadID);
@@ -2973,6 +2943,7 @@ void __KernelReturnFromExtendStack()
if (!thread)
{
ERROR_LOG_REPORT(Log::sceKernel, "__KernelReturnFromExtendStack() - not on a thread?");
hleNoLogVoid();
return;
}
@@ -2995,6 +2966,7 @@ void __KernelReturnFromExtendStack()
currentMIPS->pc = restorePC;
// We retain whatever is in v0/v1, it gets passed on to the caller of sceKernelExtendThreadStack().
hleNoLogVoid();
}
void ActionAfterMipsCall::run(MipsCall &call) {
@@ -3286,15 +3258,13 @@ bool __KernelExecuteMipsCallOnCurrentThread(u32 callId, bool reschedAfter)
return true;
}
void __KernelReturnFromMipsCall()
{
void __KernelReturnFromMipsCall() {
hleSkipDeadbeef();
PSPThread *cur = __GetCurrentThread();
if (cur == NULL)
{
if (!cur) {
ERROR_LOG(Log::sceKernel, "__KernelReturnFromMipsCall(): Bad current thread");
return;
return hleNoLogVoid();
}
u32 callId = cur->currentMipscallId;
@@ -3360,6 +3330,7 @@ void __KernelReturnFromMipsCall()
}
delete call;
hleNoLogVoid();
}
// First arg must be current thread, passed to avoid perf cost of a lookup.
@@ -3389,6 +3360,7 @@ static void __KernelRunCallbackOnThread(SceUID cbId, PSPThread *thread, bool res
PSPCallback *cb = kernelObjects.Get<PSPCallback>(cbId, error);
if (!cb) {
ERROR_LOG(Log::sceKernel, "__KernelRunCallbackOnThread: Bad cbId %i", cbId);
hleNoLogVoid();
return;
}
@@ -3410,6 +3382,7 @@ static void __KernelRunCallbackOnThread(SceUID cbId, PSPThread *thread, bool res
ERROR_LOG(Log::sceKernel, "Something went wrong creating a restore action for a callback.");
__KernelCallAddress(thread, cb->nc.entrypoint, action, args, 3, reschedAfter, cbId);
hleNoLogVoid();
}
void ActionAfterCallback::run(MipsCall &call) {
@@ -3502,8 +3475,7 @@ bool __KernelCheckCallbacks() {
return false;
}
bool __KernelForceCallbacks()
{
bool __KernelForceCallbacks() {
// Let's not check every thread all the time, callbacks are fairly uncommon.
if (readyCallbacksCount == 0) {
return false;
@@ -3522,8 +3494,7 @@ bool __KernelForceCallbacks()
}
// Not wrapped because it has special return logic.
void sceKernelCheckCallback()
{
void sceKernelCheckCallback() {
// Start with yes.
RETURN(1);
@@ -3536,6 +3507,7 @@ void sceKernelCheckCallback()
RETURN(0);
}
hleEatCycles(230);
hleNoLogVoid();
}
bool __KernelInCallback()
@@ -3629,8 +3601,8 @@ int sceKernelRegisterExitCallback(SceUID cbId)
{
WARN_LOG(Log::sceKernel, "sceKernelRegisterExitCallback(%i): invalid callback id", cbId);
if (sceKernelGetCompiledSdkVersion() >= 0x3090500)
return SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT;
return 0;
return hleLogError(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT);
return hleNoLog(0);
}
registeredExitCbId = cbId;
@@ -3657,7 +3629,7 @@ int LoadExecForUser_362A956B()
if (!Memory::IsValidAddress(parameterArea)) {
return hleLogWarning(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_ADDR, "invalid address for parameterArea on userMemory (0x%08X)", parameterArea);
}
u32 size = Memory::Read_U32(parameterArea);
if (size < 12) {
return hleLogWarning(Log::sceKernel, SCE_KERNEL_ERROR_ILLEGAL_SIZE, "invalid parameterArea size %d", size);