From 3b449f289fd23ca8d18aa3eb19b0d5fd643e5bad Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 6 Dec 2025 22:44:37 +0000 Subject: [PATCH] stupid swap system + exit_fn --- src/common/host_memory.cpp | 1 + src/common/virtual_buffer.cpp | 28 +++++++++++++++++++++++++++- src/common/virtual_buffer.h | 1 + src/yuzu_cmd/yuzu.cpp | 11 +++++++++-- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 9fa3b611c9..13f6b33885 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -701,6 +701,7 @@ private: HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) : backing_size(backing_size_), virtual_size(virtual_size_) { #ifdef __OPENORBIS__ + Common::InitSwap(); LOG_WARNING(HW_Memory, "Platform doesn't support fastmem"); fallback_buffer.emplace(backing_size); backing_base = fallback_buffer->data(); diff --git a/src/common/virtual_buffer.cpp b/src/common/virtual_buffer.cpp index 5a05f12d47..34f9c57463 100644 --- a/src/common/virtual_buffer.cpp +++ b/src/common/virtual_buffer.cpp @@ -10,6 +10,10 @@ #include #endif +#ifdef __OPENORBIS__ +#include +#endif + #include "common/assert.h" #include "common/virtual_buffer.h" #include "common/logging/log.h" @@ -33,7 +37,7 @@ void* AllocateMemoryPages(std::size_t size) noexcept { void* addr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE); ASSERT(addr != nullptr); #elif defined(__OPENORBIS__) - void* addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); + void* addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_VOID | MAP_PRIVATE, -1, 0); ASSERT(addr != MAP_FAILED); #else void* addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); @@ -53,4 +57,26 @@ void FreeMemoryPages(void* addr, [[maybe_unused]] std::size_t size) noexcept { #endif } +#ifdef __OPENORBIS__ +static struct sigaction old_sa_segv; +static void SwapHandler(int sig, siginfo_t* si, void* raw_context) { + void* a_addr = reinterpret_cast(uintptr_t(si->si_addr) & ~0xfff); + mmap(a_addr, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); + //mprotect(a_addr, 4096, PROT_READ | PROT_WRITE); +} + +bool InitSwap() noexcept { + struct sigaction sa; + sa.sa_handler = NULL; + sa.sa_sigaction = &SwapHandler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_SIGINFO | SA_RESTART; + return sigaction(SIGSEGV, &sa, &old_sa_segv) == 0; +} +#else +bool InitSwap() noexcept { + return true; +} +#endif + } // namespace Common diff --git a/src/common/virtual_buffer.h b/src/common/virtual_buffer.h index bb012196fe..407f6eb3d3 100644 --- a/src/common/virtual_buffer.h +++ b/src/common/virtual_buffer.h @@ -12,6 +12,7 @@ namespace Common { void* AllocateMemoryPages(std::size_t size) noexcept; void FreeMemoryPages(void* base, std::size_t size) noexcept; +bool InitSwap() noexcept; template class VirtualBuffer final { diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 4d1c43031d..8d3ead201f 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -52,6 +52,7 @@ #endif #ifdef __OPENORBIS__ +#include # define STUB_WEAK(name) extern "C" void name() { printf("called " #name); asm volatile("ud2"); } STUB_WEAK(__cxa_thread_atexit) STUB_WEAK(__assert) @@ -433,10 +434,15 @@ int main(int argc, char** argv) { [](VideoCore::LoadCallbackStage, size_t value, size_t total) {}); } - system.RegisterExitCallback([&] { + auto const exit_fn = [&] { +#ifdef __OPENORBIS__ + sceSystemServiceLoadExec("EXIT", nullptr); +#else // Just exit right away. exit(0); - }); +#endif + }; + system.RegisterExitCallback(exit_fn); #ifdef __linux__ Common::Linux::StartGamemode(); @@ -458,6 +464,7 @@ int main(int argc, char** argv) { #endif detached_tasks.WaitForAllTasks(); + exit_fn(); return 0; }