diff --git a/orbis-kernel/src/sys/sys_sce.cpp b/orbis-kernel/src/sys/sys_sce.cpp index ecb42eb5f..831fba678 100644 --- a/orbis-kernel/src/sys/sys_sce.cpp +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -460,7 +460,7 @@ orbis::SysResult orbis::sys_osem_close(Thread *thread, sint id) { } orbis::SysResult orbis::sys_osem_wait(Thread *thread, sint id, sint need, ptr pTimeout) { - ORBIS_LOG_NOTICE(__FUNCTION__, thread, id, need, pTimeout); + ORBIS_LOG_TRACE(__FUNCTION__, thread, id, need, pTimeout); Ref sem = thread->tproc->semMap.get(id); if (need < 1 || need > sem->maxValue) return ErrorCode::INVAL; @@ -510,7 +510,7 @@ orbis::SysResult orbis::sys_osem_wait(Thread *thread, sint id, sint need, } if (timedout) { - return ErrorCode::TIMEDOUT; + return SysResult::notAnError(ErrorCode::TIMEDOUT); } return {}; } @@ -863,8 +863,8 @@ struct mdbg_property { orbis::SysResult orbis::sys_mdbg_service(Thread *thread, uint32_t op, ptr arg0, ptr arg1) { - ORBIS_LOG_NOTICE("sys_mdbg_service", thread->tid, op, arg0, arg1); - thread->where(); + // ORBIS_LOG_NOTICE("sys_mdbg_service", thread->tid, op, arg0, arg1); + // thread->where(); switch (op) { case 1: { diff --git a/orbis-kernel/src/sys/sys_time.cpp b/orbis-kernel/src/sys/sys_time.cpp index 4a3a665c3..cd671b692 100644 --- a/orbis-kernel/src/sys/sys_time.cpp +++ b/orbis-kernel/src/sys/sys_time.cpp @@ -82,16 +82,24 @@ orbis::SysResult orbis::sys_clock_gettime(Thread *, clockid_t clock_id, result = getHostClock(CLOCK_PROCESS_CPUTIME_ID); break; case ClockId::Network: - ORBIS_LOG_ERROR("Unimplemented ClockId::Network\n"); + // TODO + // ORBIS_LOG_ERROR("Unimplemented ClockId::Network"); + result = getHostClock(CLOCK_PROCESS_CPUTIME_ID); break; case ClockId::DebugNetwork: - ORBIS_LOG_ERROR("Unimplemented ClockId::DebugNetwork\n"); + // TODO + // ORBIS_LOG_ERROR("Unimplemented ClockId::DebugNetwork"); + result = getHostClock(CLOCK_PROCESS_CPUTIME_ID); break; case ClockId::AdNetwork: - ORBIS_LOG_ERROR("Unimplemented ClockId::AdNetwork\n"); + // TODO + // ORBIS_LOG_ERROR("Unimplemented ClockId::AdNetwork"); + result = getHostClock(CLOCK_PROCESS_CPUTIME_ID); break; case ClockId::RawNetwork: - ORBIS_LOG_ERROR("Unimplemented ClockId::RawNetwork\n"); + // TODO + // ORBIS_LOG_ERROR("Unimplemented ClockId::RawNetwork"); + result = getHostClock(CLOCK_PROCESS_CPUTIME_ID); break; default: diff --git a/orbis-kernel/src/utils/SharedCV.cpp b/orbis-kernel/src/utils/SharedCV.cpp index 37d9efac7..5482cc22e 100644 --- a/orbis-kernel/src/utils/SharedCV.cpp +++ b/orbis-kernel/src/utils/SharedCV.cpp @@ -8,46 +8,56 @@ namespace orbis::utils { void shared_cv::impl_wait(shared_mutex &mutex, unsigned _val, std::uint64_t usec_timeout) noexcept { // Not supposed to fail - if (!_val) + if (!_val) { std::abort(); + } // Wait with timeout struct timespec timeout {}; timeout.tv_nsec = (usec_timeout % 1000'000) * 1000; timeout.tv_sec = (usec_timeout / 1000'000); -again: - auto result = syscall(SYS_futex, &m_value, FUTEX_WAIT, _val, - usec_timeout + 1 ? &timeout : nullptr, 0, 0); - if (result < 0) - result = errno; - // Cleanup - const auto old = atomic_fetch_op(m_value, [&](unsigned &value) { - // Remove waiter if no signals - if (!(value & ~c_waiter_mask) && result != EAGAIN) - value -= 1; + while (true) { + auto result = syscall(SYS_futex, &m_value, FUTEX_WAIT, _val, + usec_timeout + 1 ? &timeout : nullptr, 0, 0); + if (result < 0) { + result = errno; + } - // Try to remove signal - if (value & c_signal_mask) - value -= c_signal_one; - if (value & c_locked_mask) - value -= c_locked_mask; - }); + // Cleanup + const auto old = atomic_fetch_op(m_value, [&](unsigned &value) { + // Remove waiter if no signals + if (!(value & ~c_waiter_mask) && result != EAGAIN && result != EINTR) { + value -= 1; + } - // Lock is already acquired - if (old & c_locked_mask) { - return; + // Try to remove signal + if (value & c_signal_mask) { + value -= c_signal_one; + } + + if (value & c_locked_mask) { + value -= c_locked_mask; + } + }); + + // Lock is already acquired + if (old & c_locked_mask) { + return; + } + + // Wait directly (waiter has been added) + if (old & c_signal_mask) { + mutex.impl_wait(); + return; + } + + // Possibly spurious wakeup + if (result != EAGAIN && result != EINTR) { + break; + } } - // Wait directly (waiter has been added) - if (old & c_signal_mask) { - mutex.impl_wait(); - return; - } - - // Possibly spurious wakeup - if (result == EAGAIN) - goto again; mutex.lock(); } diff --git a/rpcsx-os/io-device.cpp b/rpcsx-os/io-device.cpp index a0eed2852..84d902c89 100644 --- a/rpcsx-os/io-device.cpp +++ b/rpcsx-os/io-device.cpp @@ -574,7 +574,7 @@ orbis::ErrorCode HostFsDevice::mkdir(const char *path, int mode, } orbis::ErrorCode HostFsDevice::rmdir(const char *path, orbis::Thread *thread) { std::error_code ec; - std::filesystem::remove(hostPath + "/" + path, ec); + std::filesystem::remove_all(hostPath + "/" + path, ec); return convertErrorCode(ec); } orbis::ErrorCode HostFsDevice::rename(const char *from, const char *to, diff --git a/rpcsx-os/iodev/aout.cpp b/rpcsx-os/iodev/aout.cpp index 9613be818..53e84e279 100644 --- a/rpcsx-os/iodev/aout.cpp +++ b/rpcsx-os/iodev/aout.cpp @@ -1,7 +1,10 @@ #include "io-device.hpp" #include "orbis/KernelAllocator.hpp" #include "orbis/file.hpp" +#include "orbis/uio.hpp" #include "orbis/utils/Logs.hpp" +#include +#include struct AoutFile : orbis::File {}; @@ -9,11 +12,21 @@ static orbis::ErrorCode aout_ioctl(orbis::File *file, std::uint64_t request, void *argp, orbis::Thread *thread) { ORBIS_LOG_FATAL("Unhandled aout ioctl", request); + if (request == 0xc004500a) { + std::this_thread::sleep_for(std::chrono::days(1)); + } + return {}; +} + +static orbis::ErrorCode aout_write(orbis::File *file, orbis::Uio *uio, + orbis::Thread *) { + uio->resid = 0; return {}; } static const orbis::FileOps fileOps = { .ioctl = aout_ioctl, + .write = aout_write, }; struct AoutDevice : IoDevice { diff --git a/rpcsx-os/iodev/gbase.cpp b/rpcsx-os/iodev/gbase.cpp index 3ea134c35..c893e784c 100644 --- a/rpcsx-os/iodev/gbase.cpp +++ b/rpcsx-os/iodev/gbase.cpp @@ -2,6 +2,7 @@ #include "orbis/KernelAllocator.hpp" #include "orbis/file.hpp" #include "orbis/utils/Logs.hpp" +#include "orbis/thread/Thread.hpp" struct GbaseFile : orbis::File {}; @@ -9,6 +10,7 @@ static orbis::ErrorCode gbase_ioctl(orbis::File *file, std::uint64_t request, void *argp, orbis::Thread *thread) { ORBIS_LOG_FATAL("Unhandled gbase ioctl", request); + thread->where(); return {}; } diff --git a/rpcsx-os/iodev/gc.cpp b/rpcsx-os/iodev/gc.cpp index 54d8f0fc9..552b00eaa 100644 --- a/rpcsx-os/iodev/gc.cpp +++ b/rpcsx-os/iodev/gc.cpp @@ -53,8 +53,8 @@ static orbis::ErrorCode gc_ioctl(orbis::File *file, std::uint64_t request, auto args = reinterpret_cast(argp); - flockfile(stderr); - ORBIS_LOG_ERROR("gc ioctl 0xc0108102", args->arg0, args->count, args->cmds); + // flockfile(stderr); + // ORBIS_LOG_ERROR("gc ioctl 0xc0108102", args->arg0, args->count, args->cmds); for (unsigned i = 0; i < args->count; ++i) { auto cmd = args->cmds + (i * 2); @@ -75,7 +75,7 @@ static orbis::ErrorCode gc_ioctl(orbis::File *file, std::uint64_t request, rx::bridge.sendCommandBuffer(thread->tproc->pid, cmdId, address, size); } - funlockfile(stderr); + // funlockfile(stderr); break; } @@ -88,7 +88,7 @@ static orbis::ErrorCode gc_ioctl(orbis::File *file, std::uint64_t request, auto args = reinterpret_cast(argp); - ORBIS_LOG_ERROR("gc ioctl 0xc0088101", args->arg0, args->arg1); + // ORBIS_LOG_ERROR("gc ioctl 0xc0088101", args->arg0, args->arg1); break; } @@ -257,9 +257,22 @@ static orbis::ErrorCode gc_ioctl(orbis::File *file, std::uint64_t request, break; } + case 0xc0048113: { + // get client number + *(std::uint32_t *)argp = 0; + break; + } + + case 0xc0048115: { + // is game closed + *(std::uint32_t *)argp = 0; + break; + } + default: ORBIS_LOG_FATAL("Unhandled gc ioctl", request); std::fflush(stdout); + thread->where(); // __builtin_trap(); break; } diff --git a/rpcsx-os/ops.cpp b/rpcsx-os/ops.cpp index e71abcf00..806fbf384 100644 --- a/rpcsx-os/ops.cpp +++ b/rpcsx-os/ops.cpp @@ -641,6 +641,7 @@ orbis::SysResult nmount(orbis::Thread *thread, orbis::ptr iovp, orbis::SysResult exit(orbis::Thread *thread, orbis::sint status) { std::printf("Requested exit with status %d\n", status); + thread->tproc->event.emit(orbis::kNoteExit, status); std::exit(status); } @@ -705,6 +706,7 @@ SysResult fork(Thread *thread, slong flags) { kfree(flag, sizeof(*flag)); + thread->tproc->event.emit(orbis::kNoteFork, childPid); thread->retval[0] = childPid; thread->retval[1] = 0; return {}; @@ -791,6 +793,20 @@ SysResult execve(Thread *thread, ptr fname, ptr> argv, std::string path = getAbsolutePath(fname, thread); ORBIS_LOG_ERROR(__FUNCTION__, path); + { + auto name = path; + if (auto slashP = name.rfind('/'); slashP != std::string::npos) { + name = name.substr(slashP + 1); + } + + if (name.size() > 15) { + name.resize(15); + } + + pthread_setname_np(pthread_self(), name.c_str()); + } + + std::printf("pid: %u\n", ::getpid()); { orbis::Ref file; auto result = rx::vfs::open(path, kOpenFlagReadOnly, 0, &file, thread); @@ -812,16 +828,7 @@ SysResult execve(Thread *thread, ptr fname, ptr> argv, thread->tproc->processParam = executableModule->processParam; thread->tproc->processParamSize = executableModule->processParamSize; - auto name = path; - if (auto slashP = name.rfind('/'); slashP != std::string::npos) { - name = name.substr(slashP + 1); - } - - if (name.size() > 15) { - name.resize(15); - } - - pthread_setname_np(pthread_self(), name.c_str()); + thread->tproc->event.emit(orbis::kNoteExec); ORBIS_LOG_ERROR(__FUNCTION__, "done"); std::thread([&] {