From 5a7d4dee1e8b592b110d7ea4099daf2bbdd3b334 Mon Sep 17 00:00:00 2001 From: DH Date: Sat, 11 Nov 2023 17:12:08 +0300 Subject: [PATCH] [orbis-kernel] store auth info per process --- orbis-kernel/include/orbis/AuthInfo.hpp | 14 +++++++ orbis-kernel/include/orbis/sys/sysproto.hpp | 3 +- orbis-kernel/include/orbis/thread/Process.hpp | 2 + orbis-kernel/src/sys/sys_sce.cpp | 30 +-------------- rpcsx-os/main.cpp | 38 +++++++++++++++++++ rpcsx-os/ops.cpp | 1 + 6 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 orbis-kernel/include/orbis/AuthInfo.hpp diff --git a/orbis-kernel/include/orbis/AuthInfo.hpp b/orbis-kernel/include/orbis/AuthInfo.hpp new file mode 100644 index 000000000..93cc5a7ed --- /dev/null +++ b/orbis-kernel/include/orbis/AuthInfo.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "orbis-config.hpp" + +namespace orbis { +struct AuthInfo { + uint64_t unk0; + uint64_t caps[4]; + uint64_t attrs[4]; + uint64_t unk[8]; +}; + +static_assert(sizeof(AuthInfo) == 136); +} // namespace orbis diff --git a/orbis-kernel/include/orbis/sys/sysproto.hpp b/orbis-kernel/include/orbis/sys/sysproto.hpp index 0a4eaf669..80dc3fdd3 100644 --- a/orbis-kernel/include/orbis/sys/sysproto.hpp +++ b/orbis-kernel/include/orbis/sys/sysproto.hpp @@ -11,6 +11,7 @@ using cpuwhich_t = sint; using cpulevel_t = sint; using SceKernelModule = ModuleHandle; +struct AuthInfo; struct MemoryProtection; struct ModuleInfo; struct ModuleInfoEx; @@ -676,7 +677,7 @@ SysResult sys_obs_eport_open(Thread *thread /* TODO */); SysResult sys_obs_eport_close(Thread *thread /* TODO */); SysResult sys_is_in_sandbox(Thread *thread /* TODO */); SysResult sys_dmem_container(Thread *thread, uint id); -SysResult sys_get_authinfo(Thread *thread, pid_t pid, ptr info); +SysResult sys_get_authinfo(Thread *thread, pid_t pid, ptr info); SysResult sys_mname(Thread *thread, uint64_t address, uint64_t length, ptr name); SysResult sys_dynlib_dlopen(Thread *thread /* TODO */); diff --git a/orbis-kernel/include/orbis/thread/Process.hpp b/orbis-kernel/include/orbis/thread/Process.hpp index 2f76581c4..13f87c759 100644 --- a/orbis-kernel/include/orbis/thread/Process.hpp +++ b/orbis-kernel/include/orbis/thread/Process.hpp @@ -8,6 +8,7 @@ #include "../thread/types.hpp" #include "ProcessState.hpp" #include "orbis/AppInfo.hpp" +#include "orbis/AuthInfo.hpp" #include "orbis/file.hpp" #include "orbis/module/Module.hpp" #include "orbis/utils/IdMap.hpp" @@ -55,6 +56,7 @@ struct Process final { uint64_t processParamSize = 0; const ProcessOps *ops = nullptr; AppInfo appInfo{}; + AuthInfo authInfo{}; std::uint64_t nextTlsSlot = 1; std::uint64_t lastTlsOffset = 0; diff --git a/orbis-kernel/src/sys/sys_sce.cpp b/orbis-kernel/src/sys/sys_sce.cpp index 83734c65b..c63998e53 100644 --- a/orbis-kernel/src/sys/sys_sce.cpp +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -661,34 +661,8 @@ orbis::SysResult orbis::sys_dmem_container(Thread *thread, uint id) { return {}; } orbis::SysResult orbis::sys_get_authinfo(Thread *thread, pid_t pid, - ptr info) { - struct authinfo { - uint64_t unk0; - uint64_t caps[4]; - uint64_t attrs[4]; - uint64_t unk[8]; - }; - static_assert(sizeof(authinfo) == 136); - - authinfo result{ - .unk0 = 0x3100000000000001, - .caps = - { - 0x2000038000000000, - 0x000000000000FF00, - 0x0000000000000000, - 0x0000000000000000, - }, - .attrs = - { - 0x4000400040000000, - 0x4000000000000000, - 0x0080000000000002, - 0xF0000000FFFF4000, - }, - }; - - return uwrite((ptr)info, result); + ptr info) { + return uwrite(info, thread->tproc->authInfo); } orbis::SysResult orbis::sys_mname(Thread *thread, uint64_t addr, uint64_t len, ptr name) { diff --git a/rpcsx-os/main.cpp b/rpcsx-os/main.cpp index fba2c68ff..62bd9f7e5 100644 --- a/rpcsx-os/main.cpp +++ b/rpcsx-os/main.cpp @@ -780,6 +780,44 @@ int main(int argc, const char *argv[]) { .unk4 = (isSystem ? orbis::slong(0x80000000'00000000) : 0), }; + if (isSystem) { + initProcess->authInfo = { + .unk0 = 0x3100000000000001, + .caps = + { + -1u, + -1u, + -1u, + -1u, + }, + .attrs = + { + 0x4000400040000000, + 0x4000000000000000, + 0x0080000000000002, + 0xF0000000FFFF4000, + }, + }; + } else { + initProcess->authInfo = { + .unk0 = 0x3100000000000001, + .caps = + { + 0x2000038000000000, + 0x000000000000FF00, + 0x0000000000000000, + 0x0000000000000000, + }, + .attrs = + { + 0x4000400040000000, + 0x4000000000000000, + 0x0080000000000002, + 0xF0000000FFFF4000, + }, + }; + } + auto [baseId, mainThread] = initProcess->threadsMap.emplace(); mainThread->tproc = initProcess; mainThread->tid = initProcess->pid + baseId; diff --git a/rpcsx-os/ops.cpp b/rpcsx-os/ops.cpp index bceacc11e..4334cfd21 100644 --- a/rpcsx-os/ops.cpp +++ b/rpcsx-os/ops.cpp @@ -649,6 +649,7 @@ SysResult fork(Thread *thread, slong flags) { process->onSysExit = thread->tproc->onSysExit; process->ops = thread->tproc->ops; process->parentProcess = thread->tproc; + process->authInfo = thread->tproc->authInfo; for (auto [id, mod] : thread->tproc->modulesMap) { if (!process->modulesMap.insert(id, mod)) { std::abort();