diff --git a/orbis-kernel/include/orbis/thread/Process.hpp b/orbis-kernel/include/orbis/thread/Process.hpp index 13f87c759..9f2758f73 100644 --- a/orbis-kernel/include/orbis/thread/Process.hpp +++ b/orbis-kernel/include/orbis/thread/Process.hpp @@ -57,6 +57,10 @@ struct Process final { const ProcessOps *ops = nullptr; AppInfo appInfo{}; AuthInfo authInfo{}; + kstring cwd; + kstring root = "/"; + sint memoryContainer{1}; + bool isInSandbox = false; 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 9fe3536bc..65ba47ccd 100644 --- a/orbis-kernel/src/sys/sys_sce.cpp +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -82,7 +82,7 @@ orbis::SysResult orbis::sys_regmgr_call(Thread *thread, uint32_t op, return uwrite((ptr)value, 0u); } - return{}; + return {}; } if (op == 4) { @@ -1028,7 +1028,8 @@ orbis::SysResult orbis::sys_suspend_system(Thread *thread /* TODO */) { orbis::SysResult orbis::sys_ipmimgr_call(Thread *thread, uint op, uint kid, ptr result, ptr params, uint64_t paramsSz) { - // ORBIS_LOG_TODO(__FUNCTION__, thread->tid, op, kid, result, params, paramsSz); + // ORBIS_LOG_TODO(__FUNCTION__, thread->tid, op, kid, result, params, + // paramsSz); switch (op) { case 0: diff --git a/orbis-kernel/src/sys/sys_vfs.cpp b/orbis-kernel/src/sys/sys_vfs.cpp index f1c54ec06..515ea66e8 100644 --- a/orbis-kernel/src/sys/sys_vfs.cpp +++ b/orbis-kernel/src/sys/sys_vfs.cpp @@ -1,6 +1,7 @@ #include "stat.hpp" #include "sys/sysproto.hpp" #include "utils/Logs.hpp" +#include orbis::SysResult orbis::sys_sync(Thread *thread) { return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_quotactl(Thread *thread, ptr path, sint cmd, @@ -23,10 +24,14 @@ orbis::SysResult orbis::sys_fchdir(Thread *thread, sint fd) { return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_chdir(Thread *thread, ptr path) { - return ErrorCode::NOSYS; + ORBIS_LOG_WARNING(__FUNCTION__, path); + thread->tproc->cwd = std::filesystem::path(path).lexically_normal().string(); + return {}; } orbis::SysResult orbis::sys_chroot(Thread *thread, ptr path) { - return ErrorCode::NOSYS; + ORBIS_LOG_WARNING(__FUNCTION__, path); + thread->tproc->root = path; + return {}; } orbis::SysResult orbis::sys_open(Thread *thread, ptr path, sint flags, sint mode) { diff --git a/rpcsx-os/ops.cpp b/rpcsx-os/ops.cpp index ff6a2657b..9ccd60067 100644 --- a/rpcsx-os/ops.cpp +++ b/rpcsx-os/ops.cpp @@ -157,6 +157,21 @@ loadPrx(orbis::Thread *thread, std::string_view path, bool relocate) { expectedName); } +std::string getAbsolutePath(std::string path, Thread *thread) { + if (!path.starts_with('/')) { + path = "/" + std::string(thread->tproc->cwd) + "/" + path; + } + + path = std::filesystem::path(path).lexically_normal().string(); + + if (!path.starts_with("/dev") && + !path.starts_with("/system")) { // fixme: implement devfs mount + path = std::string(thread->tproc->root) + "/" + path; + } + + return std::filesystem::path(path).lexically_normal().string(); +} + orbis::SysResult mmap(orbis::Thread *thread, orbis::caddr_t addr, orbis::size_t len, orbis::sint prot, orbis::sint flags, orbis::sint fd, orbis::off_t pos) { @@ -280,30 +295,33 @@ query_memory_protection(orbis::Thread *thread, orbis::ptr address, orbis::SysResult open(orbis::Thread *thread, orbis::ptr path, orbis::sint flags, orbis::sint mode, orbis::Ref *file) { - return rx::vfs::open(path, flags, mode, file, thread); + return rx::vfs::open(getAbsolutePath(path, thread), flags, mode, file, + thread); } orbis::SysResult shm_open(orbis::Thread *thread, const char *path, orbis::sint flags, orbis::sint mode, orbis::Ref *file) { auto dev = static_cast(orbis::g_context.shmDevice.get()); - return dev->open(file, path, flags, mode, thread); + return dev->open(file, getAbsolutePath(path, thread).c_str(), flags, mode, + thread); } orbis::SysResult unlink(orbis::Thread *thread, orbis::ptr path) { - return rx::vfs::unlink(path, thread); + return rx::vfs::unlink(getAbsolutePath(path, thread), thread); } orbis::SysResult mkdir(Thread *thread, ptr path, sint mode) { ORBIS_LOG_TODO(__FUNCTION__, path, mode); - return rx::vfs::mkdir(path, mode, thread); + return rx::vfs::mkdir(getAbsolutePath(path, thread), mode, thread); } orbis::SysResult rmdir(Thread *thread, ptr path) { ORBIS_LOG_TODO(__FUNCTION__, path); - return rx::vfs::rmdir(path, thread); + return rx::vfs::rmdir(getAbsolutePath(path, thread), thread); } orbis::SysResult rename(Thread *thread, ptr from, ptr to) { ORBIS_LOG_TODO(__FUNCTION__, from, to); - return rx::vfs::rename(from, to, thread); + return rx::vfs::rename(getAbsolutePath(from, thread), + getAbsolutePath(to, thread), thread); } orbis::SysResult blockpool_open(orbis::Thread *thread, @@ -341,7 +359,7 @@ orbis::SysResult socket(orbis::Thread *thread, orbis::ptr name, orbis::SysResult shm_unlink(orbis::Thread *thread, const char *path) { auto dev = static_cast(orbis::g_context.shmDevice.get()); - return dev->unlink(path, false, thread); + return dev->unlink(getAbsolutePath(path, thread).c_str(), false, thread); } orbis::SysResult dynlib_get_obj_member(orbis::Thread *thread, @@ -433,15 +451,17 @@ orbis::SysResult dynlib_load_prx(orbis::Thread *thread, return errorCode; } + auto path = getAbsolutePath(_name, thread); + { orbis::Ref file; - if (auto result = rx::vfs::open(_name, 0, 0, &file, thread); + if (auto result = rx::vfs::open(path, 0, 0, &file, thread); result.isError()) { return result; } } - auto [result, module] = loadPrx(thread, _name, true); + auto [result, module] = loadPrx(thread, path, true); if (result.isError()) { return result; } @@ -580,15 +600,15 @@ SysResult thr_set_name(orbis::Thread *thread, orbis::slong id, orbis::SysResult unmount(orbis::Thread *thread, orbis::ptr path, orbis::sint flags) { // TODO: support other that nullfs - return rx::vfs::unlink(path, thread); + return rx::vfs::unlink(getAbsolutePath(path, thread), thread); } orbis::SysResult nmount(orbis::Thread *thread, orbis::ptr iovp, orbis::uint iovcnt, orbis::sint flags) { ORBIS_LOG_ERROR(__FUNCTION__, iovp, iovcnt, flags); - std::string_view fstype; - std::string_view fspath; - std::string_view target; + std::string fstype; + std::string fspath; + std::string target; for (auto it = iovp; it < iovp + iovcnt; it += 2) { IoVec a; @@ -600,11 +620,11 @@ orbis::SysResult nmount(orbis::Thread *thread, orbis::ptr iovp, std::string_view value((char *)b.base, b.len - 1); if (key == "fstype") { - fstype = value; + fstype = getAbsolutePath(std::string(value), thread); } else if (key == "fspath") { - fspath = value; + fspath = getAbsolutePath(std::string(value), thread); } else if (key == "target") { - target = value; + target = getAbsolutePath(std::string(value), thread); } std::fprintf(stderr, "%s: '%s':'%s'\n", __FUNCTION__, key.data(), @@ -771,7 +791,8 @@ SysResult execve(Thread *thread, ptr fname, ptr> argv, { orbis::Ref file; - auto result = rx::vfs::open(fname, kOpenFlagReadOnly, 0, &file, thread); + auto result = rx::vfs::open(getAbsolutePath(fname, thread), + kOpenFlagReadOnly, 0, &file, thread); if (result.isError()) { return result; }