diff --git a/orbis-kernel/src/sys/sys_thr.cpp b/orbis-kernel/src/sys/sys_thr.cpp index a7b1dbc3a..be47310ca 100644 --- a/orbis-kernel/src/sys/sys_thr.cpp +++ b/orbis-kernel/src/sys/sys_thr.cpp @@ -20,8 +20,7 @@ orbis::SysResult orbis::sys_thr_new(Thread *thread, ptr param, } orbis::SysResult orbis::sys_thr_self(Thread *thread, ptr id) { - uwrite(id, (slong)thread->tid); - return {}; + return uwrite(id, (slong)thread->tid); } orbis::SysResult orbis::sys_thr_exit(Thread *thread, ptr state) { diff --git a/orbis-kernel/src/sysvec.cpp b/orbis-kernel/src/sysvec.cpp index 155b1d245..5bc1a3648 100644 --- a/orbis-kernel/src/sysvec.cpp +++ b/orbis-kernel/src/sysvec.cpp @@ -43,11 +43,11 @@ void orbis::syscall_entry(Thread *thread) { std::abort(); } - error = - int(uread(args + regcnt, - ptr(readRegister(thread->context, RegisterId::rsp) + - sizeof(uint64_t)), - (sysent.narg - regcnt) * sizeof(uint64_t))); + error = int( + ureadRaw(args + regcnt, + ptr(readRegister(thread->context, RegisterId::rsp) + + sizeof(uint64_t)), + (sysent.narg - regcnt) * sizeof(uint64_t))); } if (error == 0) { diff --git a/rpcsx-os/ops.cpp b/rpcsx-os/ops.cpp index cc42d733e..9d3f582f0 100644 --- a/rpcsx-os/ops.cpp +++ b/rpcsx-os/ops.cpp @@ -433,8 +433,11 @@ SysResult thr_create(orbis::Thread *thread, orbis::ptr ctxt, } SysResult thr_new(orbis::Thread *thread, orbis::ptr param, orbis::sint param_size) { - return {}; // FIXME: remove when we ready for MT - auto _param = uread(param); + thr_param _param; + auto result = uread(_param, param); + if (result != ErrorCode{}) { + return result; + } auto proc = thread->tproc; auto [baseId, childThread] = proc->threadsMap.emplace(); @@ -445,14 +448,19 @@ SysResult thr_new(orbis::Thread *thread, orbis::ptr param, childThread->stackEnd = _param.stack_base + _param.stack_size; childThread->fsBase = reinterpret_cast(_param.tls_base); - uwrite(_param.parent_tid, slong(childThread->tid)); + result = uwrite(_param.parent_tid, slong(childThread->tid)); + + if (result != ErrorCode{}) { + return result; + } // FIXME: implement scheduler std::printf("Starting child thread %lu\n", (long)(proc->pid + baseId)); std::thread{[=, childThread = Ref(childThread)] { - uwrite(_param.child_tid, slong(childThread->tid)); + static_cast( + uwrite(_param.child_tid, slong(childThread->tid))); // TODO: verify auto context = new ucontext_t{}; context->uc_mcontext.gregs[REG_RDI] = diff --git a/rpcsx-os/orbis-kernel-config/orbis-config.hpp b/rpcsx-os/orbis-kernel-config/orbis-config.hpp index 10fe0fa9e..b1c7e276d 100644 --- a/rpcsx-os/orbis-kernel-config/orbis-config.hpp +++ b/rpcsx-os/orbis-kernel-config/orbis-config.hpp @@ -40,14 +40,14 @@ template using cptr = T *const; using caddr_t = ptr; -[[nodiscard]] inline ErrorCode uread(void *kernelAddress, - ptr userAddress, size_t size) { +[[nodiscard]] inline ErrorCode +ureadRaw(void *kernelAddress, ptr userAddress, size_t size) { std::memcpy(kernelAddress, userAddress, size); return {}; } -[[nodiscard]] inline ErrorCode uwrite(ptr userAddress, - const void *kernelAddress, size_t size) { +[[nodiscard]] inline ErrorCode +uwriteRaw(ptr userAddress, const void *kernelAddress, size_t size) { std::memcpy(userAddress, kernelAddress, size); return {}; } @@ -64,28 +64,28 @@ using caddr_t = ptr; return {}; } -template [[deprecated]] T uread(ptr pointer) { - T result; - uread(&result, pointer, sizeof(T)); +template [[deprecated]] T uread(ptr pointer) { + T result{}; + ureadRaw(&result, pointer, sizeof(T)); return result; } template [[nodiscard]] ErrorCode uread(T &result, ptr pointer) { - return uread(&result, pointer, sizeof(T)); + return ureadRaw(&result, pointer, sizeof(T)); } template [[nodiscard]] ErrorCode uwrite(ptr pointer, T data) { - return uwrite(pointer, &data, sizeof(T)); + return uwriteRaw(pointer, &data, sizeof(T)); } template [[nodiscard]] ErrorCode uread(T *result, ptr pointer, std::size_t count) { - return uread(&result, pointer, sizeof(T) * count); + return ureadRaw(&result, pointer, sizeof(T) * count); } template [[nodiscard]] ErrorCode uwrite(ptr pointer, T *data, std::size_t count) { - return uwrite(pointer, &data, sizeof(T) * count); + return uwriteRaw(pointer, &data, sizeof(T) * count); } inline uint64_t readRegister(void *context, RegisterId id) {