diff --git a/kernel/orbis/src/ipmi.cpp b/kernel/orbis/src/ipmi.cpp index 3c3c77b0c..4f0ad4e9a 100644 --- a/kernel/orbis/src/ipmi.cpp +++ b/kernel/orbis/src/ipmi.cpp @@ -321,7 +321,7 @@ orbis::SysResult orbis::sysIpmiSendConnectResult(Thread *thread, if (client == nullptr) { ORBIS_LOG_FATAL(__FUNCTION__); - std::abort(); + rx::die("client is null"); } sint status; diff --git a/kernel/orbis/src/module.cpp b/kernel/orbis/src/module.cpp index bc97d13f2..50ca5a66f 100644 --- a/kernel/orbis/src/module.cpp +++ b/kernel/orbis/src/module.cpp @@ -178,10 +178,7 @@ static orbis::SysResult doPltRelocation(orbis::Process *process, } } - std::fprintf(stderr, "unimplemented relocation type %u\n", - (unsigned)rel.relType); - std::abort(); - return {}; + rx::die("unimplemented relocation type {}", rel.relType); } static orbis::SysResult doRelocation(orbis::Process *process, @@ -359,10 +356,7 @@ static orbis::SysResult doRelocation(orbis::Process *process, } } - std::fprintf(stderr, "unimplemented relocation type %u\n", - (unsigned)rel.relType); - std::abort(); - return {}; + rx::die("unimplemented relocation type {}", rel.relType); } orbis::SysResult orbis::Module::relocate(Process *process) { diff --git a/kernel/orbis/src/sysvec.cpp b/kernel/orbis/src/sysvec.cpp index 2ca2cb292..60e89ee32 100644 --- a/kernel/orbis/src/sysvec.cpp +++ b/kernel/orbis/src/sysvec.cpp @@ -1,5 +1,6 @@ #include "orbis-config.hpp" #include "rx/EnumBitSet.hpp" +#include "rx/die.hpp" #include "rx/format.hpp" #include "sys/syscall.hpp" #include "sys/sysentry.hpp" @@ -54,9 +55,10 @@ void orbis::syscall_entry(Thread *thread) { std::memcpy(args, regsptr, std::min(regcnt, sysent.narg) * sizeof(uint64_t)); if (sysent.narg > regcnt) { - if (sysent.narg > std::ssize(args)) { - std::abort(); - } + rx::dieIf(sysent.narg > std::ssize(args), + "syscall {} uses unexpected number of " + "arguments, narg = {}", + syscall_num, sysent.narg); error = int( ureadRaw(args + regcnt, diff --git a/kernel/orbis/src/umtx.cpp b/kernel/orbis/src/umtx.cpp index cd8352653..460b3f339 100644 --- a/kernel/orbis/src/umtx.cpp +++ b/kernel/orbis/src/umtx.cpp @@ -140,14 +140,14 @@ uint UmtxChain::notify_all(const UmtxKey &key) { orbis::ErrorCode orbis::umtx_lock_umtx(Thread *thread, ptr umtx, ulong id, std::uint64_t ut) { ORBIS_LOG_TODO(__FUNCTION__, thread->tid, umtx, id, ut); - std::abort(); + rx::die("unimplemented umtx lock"); return ErrorCode::NOSYS; } orbis::ErrorCode orbis::umtx_unlock_umtx(Thread *thread, ptr umtx, ulong id) { ORBIS_LOG_TODO(__FUNCTION__, thread->tid, umtx, id); - std::abort(); + rx::die("unimplemented umtx unlock"); return ErrorCode::NOSYS; } diff --git a/rpcsx/AudioOut.cpp b/rpcsx/AudioOut.cpp index b769d2053..8ab3deae2 100644 --- a/rpcsx/AudioOut.cpp +++ b/rpcsx/AudioOut.cpp @@ -16,8 +16,7 @@ AudioOut::AudioOut() { if (sox_init() != SOX_SUCCESS) { - ORBIS_LOG_FATAL("Failed to initialize sox"); - std::abort(); + rx::die("Failed to initialize sox"); } } @@ -49,34 +48,29 @@ void AudioOut::channelEntry(AudioOutChannelInfo info) { int controlFd = ::open(control_shm_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (controlFd == -1) { - perror("shm_open"); - std::abort(); + rx::die("shm_open failed, errc {}", std::errc{errno}); } struct stat controlStat; if (::fstat(controlFd, &controlStat)) { - perror("fstat"); - std::abort(); + rx::die("fstat failed, errc {}", std::errc{errno}); } auto controlPtr = reinterpret_cast( ::mmap(nullptr, controlStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, controlFd, 0)); if (controlPtr == MAP_FAILED) { - perror("mmap"); - std::abort(); + rx::die("mmap failed, errc {}", std::errc{errno}); } int bufferFd = ::open(audio_shm_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (bufferFd == -1) { - perror("open"); - std::abort(); + rx::die("buffer shm open failed, errc {}", std::errc{errno}); } struct stat bufferStat; if (::fstat(bufferFd, &bufferStat)) { - perror("fstat"); - std::abort(); + rx::die("buffer shm fstat failed, errc {}", std::errc{errno}); } auto audioBuffer = ::mmap(NULL, bufferStat.st_size, PROT_READ | PROT_WRITE, @@ -153,7 +147,7 @@ void AudioOut::channelEntry(AudioOutChannelInfo info) { soxMtx.unlock(); if (!output) { - std::abort(); + rx::die("sox_open_write failed"); } std::vector samples(inSamples * inChannels); diff --git a/rpcsx/audio/AlsaDevice.cpp b/rpcsx/audio/AlsaDevice.cpp index dc87a01e2..c36760d3f 100644 --- a/rpcsx/audio/AlsaDevice.cpp +++ b/rpcsx/audio/AlsaDevice.cpp @@ -1,6 +1,6 @@ #include "AlsaDevice.hpp" #include "orbis/utils/Logs.hpp" -#include "rx/hexdump.hpp" +#include "rx/format.hpp" void AlsaDevice::start() { if (mWorking) { @@ -19,9 +19,7 @@ void AlsaDevice::start() { break; case AudioFormat::AC3: default: - ORBIS_LOG_FATAL("Format is not supported", int(mFormat)); - std::abort(); - break; + rx::die("Format is not supported, {}", mFormat); } mAlsaFormat = fmt; } @@ -29,60 +27,51 @@ void AlsaDevice::start() { if (auto err = snd_pcm_open(&mPCMHandle, "default", SND_PCM_STREAM_PLAYBACK, 0); err < 0) { - ORBIS_LOG_FATAL("Cannot open audio device", snd_strerror(err)); - std::abort(); + rx::die("Cannot open audio device: {}", snd_strerror(err)); } if (auto err = snd_pcm_hw_params_malloc(&mHWParams); err < 0) { - ORBIS_LOG_FATAL("Cannot allocate hardware parameter structure", - snd_strerror(err)); - std::abort(); + rx::die("Cannot allocate hardware parameter structure: {}", + snd_strerror(err)); } if (auto err = snd_pcm_hw_params_any(mPCMHandle, mHWParams); err < 0) { - ORBIS_LOG_FATAL("Cannot initialize hardware parameter structure", - snd_strerror(err)); - std::abort(); + rx::die("Cannot initialize hardware parameter structure: {}", + snd_strerror(err)); } if (auto err = snd_pcm_hw_params_set_rate_resample(mPCMHandle, mHWParams, 0); err < 0) { - ORBIS_LOG_FATAL("Cannot disable rate resampling", snd_strerror(err)); - std::abort(); + rx::die("Cannot disable rate resampling: {}", snd_strerror(err)); } if (auto err = snd_pcm_hw_params_set_access(mPCMHandle, mHWParams, SND_PCM_ACCESS_RW_INTERLEAVED); err < 0) { - ORBIS_LOG_FATAL("Cannot set access type", snd_strerror(err)); - std::abort(); + rx::die("Cannot set access type: {}", snd_strerror(err)); } if (auto err = snd_pcm_hw_params_set_format(mPCMHandle, mHWParams, mAlsaFormat); err < 0) { - ORBIS_LOG_FATAL("Cannot set sample format", snd_strerror(err)); - std::abort(); + rx::die("Cannot set sample format: {}", snd_strerror(err)); } if (auto err = snd_pcm_hw_params_set_rate(mPCMHandle, mHWParams, mFrequency, 0); err < 0) { - ORBIS_LOG_FATAL("Cannot set sample rate", snd_strerror(err)); - std::abort(); + rx::die("Cannot set sample rate: {}", snd_strerror(err)); } if (auto err = snd_pcm_hw_params_set_channels(mPCMHandle, mHWParams, mChannels); err < 0) { - ORBIS_LOG_FATAL("cannot set channel count", snd_strerror(err), mChannels); - std::abort(); + rx::die("cannot set channel count: {}", snd_strerror(err), mChannels); } if (auto err = snd_pcm_hw_params_set_periods(mPCMHandle, mHWParams, mSampleCount * 10, 0); err < 0) { - ORBIS_LOG_FATAL("Cannot set periods count", snd_strerror(err)); - std::abort(); + rx::die("Cannot set periods count: {}", snd_strerror(err)); } int frameBytes = snd_pcm_format_physical_width(mAlsaFormat) * mChannels / 8; @@ -109,8 +98,7 @@ void AlsaDevice::start() { } if (err < 0) { - ORBIS_LOG_FATAL("Cannot set buffer size", snd_strerror(err)); - std::abort(); + rx::die("Cannot set buffer size: {}", snd_strerror(err)); } } @@ -135,8 +123,7 @@ void AlsaDevice::start() { } if (err < 0) { - ORBIS_LOG_FATAL("Cannot set period size", snd_strerror(err)); - std::abort(); + rx::die("Cannot set period size: {}", snd_strerror(err)); } } @@ -144,63 +131,52 @@ void AlsaDevice::start() { if (auto err = snd_pcm_hw_params_get_period_size(mHWParams, &periodSize, nullptr); err < 0) { - ORBIS_LOG_FATAL("cannot set parameters", snd_strerror(err)); - std::abort(); + rx::die("cannot set parameters: {}", snd_strerror(err)); } snd_pcm_uframes_t bufferSize; if (auto err = snd_pcm_hw_params_get_buffer_size(mHWParams, &bufferSize); err < 0) { - ORBIS_LOG_FATAL("cannot set parameters", snd_strerror(err)); - std::abort(); + rx::die("cannot set parameters: {}", snd_strerror(err)); } ORBIS_LOG_TODO("period and buffer", periodSize, bufferSize); if (auto err = snd_pcm_hw_params(mPCMHandle, mHWParams); err < 0) { - ORBIS_LOG_FATAL("cannot set parameters", snd_strerror(err)); - std::abort(); + rx::die("cannot set parameters: {}", snd_strerror(err)); } if (auto err = snd_pcm_sw_params_malloc(&mSWParams); err < 0) { - ORBIS_LOG_FATAL("Cannot allocate software parameter structure", - snd_strerror(err)); - std::abort(); + rx::die("Cannot allocate software parameter structure: {}", + snd_strerror(err)); } if (auto err = snd_pcm_sw_params_current(mPCMHandle, mSWParams); err < 0) { - ORBIS_LOG_FATAL("cannot sw params current", snd_strerror(err)); - std::abort(); + rx::die("cannot sw params current: {}", snd_strerror(err)); } if (auto err = snd_pcm_sw_params_set_start_threshold(mPCMHandle, mSWParams, periodSize); err < 0) { - ORBIS_LOG_FATAL("cannot set start threshold", snd_strerror(err)); - std::abort(); + rx::die("cannot set start threshold: {}", snd_strerror(err)); } if (auto err = snd_pcm_sw_params_set_stop_threshold(mPCMHandle, mSWParams, bufferSize); err < 0) { - ORBIS_LOG_FATAL("cannot set stop threshold", snd_strerror(err)); - std::abort(); + rx::die("cannot set stop threshold: {}", snd_strerror(err)); } if (auto err = snd_pcm_sw_params(mPCMHandle, mSWParams); err < 0) { - ORBIS_LOG_FATAL("cannot set parameters", snd_strerror(err)); - std::abort(); + rx::die("cannot set parameters: {}", snd_strerror(err)); } if (auto err = snd_pcm_nonblock(mPCMHandle, 1); err < 0) { - ORBIS_LOG_FATAL("set nonblock mode failed", snd_strerror(err)); - std::abort(); + rx::die("set nonblock mode failed: {}", snd_strerror(err)); } if (auto err = snd_pcm_prepare(mPCMHandle); err < 0) { - ORBIS_LOG_FATAL("cannot prepare audio interface for use", - snd_strerror(err)); - std::abort(); + rx::die("cannot prepare audio interface for use: {}", snd_strerror(err)); } mWorking = true; diff --git a/rpcsx/audio/AudioDevice.hpp b/rpcsx/audio/AudioDevice.hpp index b7d3090e6..360170b34 100644 --- a/rpcsx/audio/AudioDevice.hpp +++ b/rpcsx/audio/AudioDevice.hpp @@ -16,6 +16,7 @@ enum class AudioFormat : std::uint32_t { S16_LE = 0x10, AC3 = 0x400, S32_LE = 0x1000, + _last = S32_LE, }; class AudioDevice : public rx::RcBase { diff --git a/rpcsx/core/include/rx/watchdog.hpp b/rpcsx/core/include/rx/watchdog.hpp index e76ba2962..77bb5b85b 100644 --- a/rpcsx/core/include/rx/watchdog.hpp +++ b/rpcsx/core/include/rx/watchdog.hpp @@ -9,5 +9,6 @@ std::filesystem::path getShmGuestPath(std::string_view path); void createGpuDevice(); void shutdown(); void attachProcess(int pid); +void attachGpuProcess(int pid); void startWatchdog(); } // namespace rx diff --git a/rpcsx/core/src/watchdog.cpp b/rpcsx/core/src/watchdog.cpp index 5719a83e7..7fb2c9e4a 100644 --- a/rpcsx/core/src/watchdog.cpp +++ b/rpcsx/core/src/watchdog.cpp @@ -32,7 +32,7 @@ enum class MessageId { }; static void runGPU() { - if (g_gpuPid != 0 || orbis::g_context->gpuDevice != nullptr) { + if (g_gpuPid != 0) { return; } @@ -51,26 +51,16 @@ static void runGPU() { } } - amdgpu::DeviceCtl gpu; - { - pthread_setname_np(pthread_self(), "rpcsx-gpu"); - std::lock_guard lock(orbis::g_context->gpuDeviceMtx); - if (orbis::g_context->gpuDevice != nullptr) { - std::exit(0); - } + pthread_setname_np(pthread_self(), "rpcsx-gpu"); - int logFd = - ::open("log-gpu.txt", O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); - dup2(logFd, 1); - dup2(logFd, 2); - ::close(logFd); + int logFd = + ::open("log-gpu.txt", O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); + dup2(logFd, 1); + dup2(logFd, 2); + ::close(logFd); - gpu = amdgpu::DeviceCtl::createDevice(); - orbis::g_context->gpuDevice = gpu.getOpaque(); - } - - gpu.start(); - std::exit(0); + amdgpu::DeviceCtl{orbis::g_context->gpuDevice}.start(); + std::_Exit(0); } static void handleManagementSignal(siginfo_t *info) { @@ -121,6 +111,7 @@ void rx::createGpuDevice() { void rx::shutdown() { kill(g_watchdogPid, SIGQUIT); } void rx::attachProcess(int pid) { sendMessage(MessageId::AttachProcess, pid); } +void rx::attachGpuProcess(int pid) { g_gpuPid = pid; } static void killProcesses(std::vector list) { int iteration = 0; diff --git a/rpcsx/ipmi.cpp b/rpcsx/ipmi.cpp index 5b3182181..810465d74 100644 --- a/rpcsx/ipmi.cpp +++ b/rpcsx/ipmi.cpp @@ -743,22 +743,19 @@ void ipmi::createShellCoreObjects(orbis::Process *process) { int shmFd = ::open(hostPath.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (shmFd == -1) { - perror("shm_open"); - std::abort(); + rx::die("shm_open failed, errc {}", std::errc{ errno }); } struct stat controlStat; if (::fstat(shmFd, &controlStat)) { - perror("fstat"); - std::abort(); + rx::die("fstat failed, errc {}", std::errc{errno}); } auto shmAddress = reinterpret_cast( ::mmap(nullptr, controlStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, shmFd, 0)); if (shmAddress == MAP_FAILED) { - perror("mmap"); - std::abort(); + rx::die("mmap failed, errc {}", std::errc{errno}); } orbis::g_context->dialogs.emplace_back(shmAddress, controlStat.st_size); diff --git a/rpcsx/linker.cpp b/rpcsx/linker.cpp index 0808afd48..5fe1e667a 100644 --- a/rpcsx/linker.cpp +++ b/rpcsx/linker.cpp @@ -527,7 +527,7 @@ static rx::Ref loadModule(ElfFile *elf, orbis::Process *process, Elf64_Phdr phdrsStorage[16]; if (header.e_phnum > std::size(phdrsStorage)) { - std::abort(); + rx::die("unexpected phnum {}", header.e_phnum); } std::memcpy(phdrsStorage, elf->image.data() + header.e_phoff, @@ -1004,7 +1004,7 @@ static rx::Ref loadModule(ElfFile *elf, orbis::Process *process, hashPos = moduleLibary.find('#'); if (hashPos == std::string_view::npos) { - std::abort(); + rx::die("unexpected symbol name {}", fullName); } library = moduleLibary.substr(0, hashPos);