Skip to content

Commit

Permalink
Merge pull request #12986 from sum2012/kernel_unkown3
Browse files Browse the repository at this point in the history
Thread: Default to kernel threads from kernel. by @unknownbrackets
  • Loading branch information
hrydgard authored May 30, 2020
2 parents 2f7a456 + 9900a76 commit 288fe3a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 12 additions & 1 deletion Core/HLE/sceKernelModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
#include "GPU/GPUState.h"

enum {
PSP_THREAD_ATTR_USER = 0x80000000
PSP_THREAD_ATTR_KERNEL = 0x00001000,
PSP_THREAD_ATTR_USER = 0x80000000,
};

enum {
Expand Down Expand Up @@ -1608,6 +1609,16 @@ u32 __KernelGetModuleGP(SceUID uid) {
}
}

bool KernelModuleIsKernelMode(SceUID uid) {
u32 error;
PSPModule *module = kernelObjects.Get<PSPModule>(uid, error);
if (module) {
return (module->nm.attribute & 0x1000) != 0;
} else {
return false;
}
}

void __KernelLoadReset() {
// Wipe kernel here, loadexec should reset the entire system
if (__KernelIsRunning()) {
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/sceKernelModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void __KernelModuleDoState(PointerWrap &p);
void __KernelModuleShutdown();

u32 __KernelGetModuleGP(SceUID module);
bool KernelModuleIsKernelMode(SceUID module);
bool __KernelLoadGEDump(const std::string &base_filename, std::string *error_string);
bool __KernelLoadExec(const char *filename, u32 paramPtr, std::string *error_string);
void __KernelGPUReplay();
Expand Down
15 changes: 10 additions & 5 deletions Core/HLE/sceKernelThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1959,9 +1959,13 @@ int __KernelCreateThread(const char *threadName, SceUID moduleID, u32 entry, u32
// Some are USB/VSH specific, probably removes when they are from the wrong module?
attr &= ~PSP_THREAD_ATTR_USER_ERASE;

// We're assuming all threads created are user threads.
if ((attr & PSP_THREAD_ATTR_KERNEL) == 0)
attr |= PSP_THREAD_ATTR_USER;
if ((attr & PSP_THREAD_ATTR_KERNEL) == 0) {
if (allowKernel && (attr & PSP_THREAD_ATTR_USER) == 0) {
attr |= PSP_THREAD_ATTR_KERNEL;
} else {
attr |= PSP_THREAD_ATTR_USER;
}
}

SceUID id = __KernelCreateThreadInternal(threadName, moduleID, entry, prio, stacksize, attr);
if ((u32)id == SCE_KERNEL_ERROR_NO_MEMORY)
Expand All @@ -1986,8 +1990,9 @@ int __KernelCreateThread(const char *threadName, SceUID moduleID, u32 entry, u32

int sceKernelCreateThread(const char *threadName, u32 entry, u32 prio, int stacksize, u32 attr, u32 optionAddr) {
PSPThread *cur = __GetCurrentThread();
bool allowKernel = cur ? (cur->nt.attr & PSP_THREAD_ATTR_KERNEL) != 0 : false;
return __KernelCreateThread(threadName, __KernelGetCurThreadModuleId(), entry, prio, stacksize, attr, optionAddr, allowKernel);
SceUID module = __KernelGetCurThreadModuleId();
bool allowKernel = KernelModuleIsKernelMode(module) || hleIsKernelMode() || (cur ? (cur->nt.attr & PSP_THREAD_ATTR_KERNEL) != 0 : false);
return __KernelCreateThread(threadName, module, entry, prio, stacksize, attr, optionAddr, allowKernel);
}

int __KernelStartThread(SceUID threadToStartID, int argSize, u32 argBlockPtr, bool forceArgs) {
Expand Down

0 comments on commit 288fe3a

Please sign in to comment.