From 39c2dc3dbb764d2772645a356fe5aecb81322411 Mon Sep 17 00:00:00 2001 From: DH Date: Thu, 13 Jul 2023 22:34:49 +0300 Subject: [PATCH] [rpcsx-os] Temporary pread implementation Trace open/close --- rpcsx-os/ops.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/rpcsx-os/ops.cpp b/rpcsx-os/ops.cpp index 708749e80..a88d03b27 100644 --- a/rpcsx-os/ops.cpp +++ b/rpcsx-os/ops.cpp @@ -6,6 +6,7 @@ #include "orbis/thread/Process.hpp" #include "orbis/thread/Thread.hpp" #include "orbis/umtx.hpp" +#include "orbis/utils/Logs.hpp" #include "orbis/utils/Rc.hpp" #include "thread.hpp" #include "vfs.hpp" @@ -113,14 +114,16 @@ orbis::SysResult virtual_query(orbis::Thread *thread, orbis::SysResult open(orbis::Thread *thread, orbis::ptr path, orbis::sint flags, orbis::sint mode) { - std::printf("sys_open(%s)\n", path); orbis::Ref instance; auto result = rx::vfs::open(path, flags, mode, &instance); if (result.isError()) { + ORBIS_LOG_WARNING("sys_open: failed to open", path, result); return result; } - thread->retval[0] = thread->tproc->fileDescriptors.insert(instance); + auto fd = thread->tproc->fileDescriptors.insert(instance); + thread->retval[0] = fd; + ORBIS_LOG_WARNING("sys_open", path, fd); return {}; } @@ -129,6 +132,7 @@ orbis::SysResult close(orbis::Thread *thread, orbis::sint fd) { return ErrorCode::BADF; } + ORBIS_LOG_WARNING("sys_close", fd); return {}; } @@ -314,7 +318,24 @@ orbis::SysResult read(orbis::Thread *thread, orbis::sint fd, orbis::SysResult pread(orbis::Thread *thread, orbis::sint fd, orbis::ptr data, orbis::ulong size, orbis::ulong offset) { - return ErrorCode::NOTSUP; + Ref handle = + static_cast(thread->tproc->fileDescriptors.get(fd)); + if (handle == nullptr) { + return ErrorCode::BADF; + } + + auto prevPos = handle->lseek(handle.get(), 0, SEEK_CUR); + handle->lseek(handle.get(), offset, SEEK_SET); + auto result = handle->read(handle.get(), data, size); + handle->lseek(handle.get(), prevPos, SEEK_SET); + + if (result < 0) { + // TODO + return ErrorCode::IO; + } + + thread->retval[0] = result; + return {}; } orbis::SysResult pwrite(orbis::Thread *thread, orbis::sint fd, orbis::ptr data, orbis::ulong size,