From c6f2d98fddf88ecadbff411582792958acfb75df Mon Sep 17 00:00:00 2001 From: Pacuka <69674426+Pacuka@users.noreply.github.com> Date: Sat, 26 Sep 2026 11:15:16 +0200 Subject: [PATCH 1/8] fix(build): configure bundled SDL2 without static executable linking Distributions without static X11 libraries (such as Arch-based ones) fail SDL2's X11 feature checks because the global -static linker flag also applies to its try_compile probes. Restore the flag after SDL2 is added. Co-Authored-By: Claude Opus 5.5 --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98a1b94b4..8308a7613 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,10 @@ set(SDL_HAPTIC OFF CACHE BOOL "" FORCE) set(SDL_HIDAPI OFF CACHE BOOL "" FORCE) set(SDL_SENSOR OFF CACHE BOOL "" FORCE) set(SDL_STATIC_PIC ON CACHE BOOL "" FORCE) +set(ANYPS5_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") +set(CMAKE_EXE_LINKER_FLAGS "") add_subdirectory(3rdparty/SDL2) +set(CMAKE_EXE_LINKER_FLAGS "${ANYPS5_EXE_LINKER_FLAGS}") add_subdirectory(core/shader/recompiler) add_subdirectory(core/libs) From a4273c10dcf279b5506690e97ebc73caccb4be0a Mon Sep 17 00:00:00 2001 From: Pacuka <69674426+Pacuka@users.noreply.github.com> Date: Sat, 26 Sep 2026 11:15:16 +0200 Subject: [PATCH 2/8] fix(videoout): drop __stdcall from the window procedure GCC on Linux rejects the attribute, which breaks the libs build since the F11 fullscreen change. It has no effect on x86-64 Windows. Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libSceVideoOut/include/DisplayWindow.hpp | 2 +- core/libs/prx/libSceVideoOut/src/DisplayWindow.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/libs/prx/libSceVideoOut/include/DisplayWindow.hpp b/core/libs/prx/libSceVideoOut/include/DisplayWindow.hpp index 1c7130a78..18cfc77f1 100644 --- a/core/libs/prx/libSceVideoOut/include/DisplayWindow.hpp +++ b/core/libs/prx/libSceVideoOut/include/DisplayWindow.hpp @@ -29,7 +29,7 @@ private: void removeSubclass() noexcept; void applyAspectRatio(void* hwnd, std::uintptr_t edge, void* rect) const; - static std::intptr_t __stdcall windowProc(void* hwnd, unsigned int message, std::uintptr_t wParam, std::intptr_t lParam, std::uintptr_t subclassId, std::uintptr_t referenceData); + static std::intptr_t windowProc(void* hwnd, unsigned int message, std::uintptr_t wParam, std::intptr_t lParam, std::uintptr_t subclassId, std::uintptr_t referenceData); SDL_Window* window = nullptr; std::uint32_t aspectWidth = 0; diff --git a/core/libs/prx/libSceVideoOut/src/DisplayWindow.cpp b/core/libs/prx/libSceVideoOut/src/DisplayWindow.cpp index cced33f9a..6717efe30 100644 --- a/core/libs/prx/libSceVideoOut/src/DisplayWindow.cpp +++ b/core/libs/prx/libSceVideoOut/src/DisplayWindow.cpp @@ -158,7 +158,7 @@ void DisplayWindow::applyAspectRatio(void* hwnd, std::uintptr_t edge, void* rect #endif } -std::intptr_t __stdcall DisplayWindow::windowProc(void* hwnd, unsigned int message, std::uintptr_t wParam, std::intptr_t lParam, std::uintptr_t subclassId, std::uintptr_t referenceData) { +std::intptr_t DisplayWindow::windowProc(void* hwnd, unsigned int message, std::uintptr_t wParam, std::intptr_t lParam, std::uintptr_t subclassId, std::uintptr_t referenceData) { #ifdef _WIN32 static_cast(subclassId); if (message == WM_SIZING) { From 998605fe4e2f54ef5b662ea516dd7597943354ff Mon Sep 17 00:00:00 2001 From: Pacuka <69674426+Pacuka@users.noreply.github.com> Date: Sat, 26 Sep 2026 11:15:16 +0200 Subject: [PATCH 3/8] fix(libc): swap calloc and realloc slots of the malloc replacement table SceLibcMallocReplace lists calloc before realloc (malloc, free, calloc, realloc, memalign, reallocalign, posix_memalign, ...), as the table in retail titles shows. realloc therefore called the application's calloc with the old pointer as the element count, and calloc called realloc. Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libc/src/ApplicationHeap.cpp | 4 ++-- core/libs/tests/ApplicationHeap.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/libs/prx/libc/src/ApplicationHeap.cpp b/core/libs/prx/libc/src/ApplicationHeap.cpp index ffd62cc5a..81e17250d 100644 --- a/core/libs/prx/libc/src/ApplicationHeap.cpp +++ b/core/libs/prx/libc/src/ApplicationHeap.cpp @@ -142,7 +142,7 @@ void* ApplicationHeapReallocate_nid_no_patch(void* pointer, std::size_t bytes) { ApplicationHeapFree_nid_no_patch(pointer); return nullptr; } - const auto reallocate = callback(2); + const auto reallocate = callback(3); CallbackScope scope; return requireAllocation(reallocate(pointer, bytes)); } @@ -158,7 +158,7 @@ void* ApplicationHeapAlign_nid_no_patch(std::size_t alignment, std::size_t bytes void* ApplicationHeapCalloc_nid_no_patch(std::size_t count, std::size_t bytes) { if (bytes != 0 && count > std::numeric_limits::max() / bytes) throw std::length_error("application heap: calloc size overflow"); - const auto calloc = callback(3); + const auto calloc = callback(2); CallbackScope scope; return requireAllocation(calloc(count, bytes)); } diff --git a/core/libs/tests/ApplicationHeap.cpp b/core/libs/tests/ApplicationHeap.cpp index 0d4a8e900..48009f88e 100644 --- a/core/libs/tests/ApplicationHeap.cpp +++ b/core/libs/tests/ApplicationHeap.cpp @@ -87,8 +87,8 @@ int main(int argc, char**) { write(replacement, 0x18, &finalize); write(replacement, 0x20, &allocate); write(replacement, 0x28, &release); - write(replacement, 0x30, &reallocate); - write(replacement, 0x38, &allocateZeroed); + write(replacement, 0x30, &allocateZeroed); + write(replacement, 0x38, &reallocate); write(replacement, 0x40, &align); write(replacement, 0x48, &reallocate); write(replacement, 0x50, &posixAlign); From d15e93681fe22f47f7beff8fc37c2be339d1281a Mon Sep 17 00:00:00 2001 From: Pacuka <69674426+Pacuka@users.noreply.github.com> Date: Sat, 26 Sep 2026 11:15:16 +0200 Subject: [PATCH 4/8] fix(kernel): map SCE protections to readable host pages SCE_KERNEL_PROT_CPU_RW (0x02) and CPU_EXEC (0x04) include read access, but were translated to write-only and execute-only host pages. GPU read and write bits also need host access because the emulated GPU reads and writes guest memory from the CPU. Write-only mappings made the AGC driver reject guest data segments as unreadable. Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp b/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp index 69be5eb95..9c74f54c9 100644 --- a/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp +++ b/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp @@ -66,9 +66,9 @@ int LinuxProtFromSce(int prot) { throw std::invalid_argument("Unsupported memory protection bits"); } int result = PROT_NONE; - if (prot & 1) result |= PROT_READ; - if (prot & 2) result |= PROT_WRITE; - if (prot & 4) result |= PROT_EXEC; + if (prot & 0x13) result |= PROT_READ; + if (prot & 0x22) result |= PROT_READ | PROT_WRITE; + if (prot & 4) result |= PROT_READ | PROT_EXEC; return result; } From ca23f1061296d68c954311b4cbe5c0e747443d83 Mon Sep 17 00:00:00 2001 From: Pacuka <69674426+Pacuka@users.noreply.github.com> Date: Sat, 26 Sep 2026 11:15:16 +0200 Subject: [PATCH 5/8] fix(kernel): accept AMPR and ACP access bits in memory protections Retail titles pass protections such as 0xC2 (CPU read/write plus the 0x40 and 0x80 device access bits). The device bits do not affect CPU access and were rejected as unsupported. Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp b/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp index 9c74f54c9..ac952bac7 100644 --- a/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp +++ b/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp @@ -61,7 +61,7 @@ void ValidateRange(const void* addr, size_t len, size_t alignment) { } int LinuxProtFromSce(int prot) { - if ((prot & ~0x37) != 0) { + if ((prot & ~0xF7) != 0) { // return SCE_KERNEL_ERROR_EINVAL; throw std::invalid_argument("Unsupported memory protection bits"); } From b98257b75ddaf8a0b24a08167ace9b0cdb10a6fa Mon Sep 17 00:00:00 2001 From: Pacuka <69674426+Pacuka@users.noreply.github.com> Date: Sat, 26 Sep 2026 11:15:16 +0200 Subject: [PATCH 6/8] fix(libc): register the main guest image on Linux Guest mprotect calls on the executable's own segments failed with "guest protection or unmap range is not registered" because only the Windows build registered the main image. Register the PT_LOAD segments of the main executable page by page, merging the protections of segments that share a page. Co-Authored-By: Claude Opus 5.5 --- .../prx/libc/include/GuestAllocations.hpp | 4 -- core/libs/prx/libc/src/GuestAllocations.cpp | 48 +++++++++++++++++++ .../libkernel/DirectMemory/DirectMemory.cpp | 2 + 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/core/libs/prx/libc/include/GuestAllocations.hpp b/core/libs/prx/libc/include/GuestAllocations.hpp index db5f0394f..b1fd0f44c 100644 --- a/core/libs/prx/libc/include/GuestAllocations.hpp +++ b/core/libs/prx/libc/include/GuestAllocations.hpp @@ -24,9 +24,7 @@ using Lease = std::vector>; extern "C" { void* GuestAllocationsBegin_nid_postfix(); -#ifdef _WIN32 void GuestAllocationsRegisterMainImage_nid_postfix(void* mutation); -#endif void GuestAllocationsEnd_nid_postfix(void* mutation) noexcept; void GuestAllocationsAdd_nid_postfix(void* mutation, void* pointer, std::size_t bytes, bool readable, bool writable); void GuestAllocationsRequireUnpinned_nid_postfix(void* mutation, const void* pointer, std::size_t bytes); @@ -44,9 +42,7 @@ public: ~Mutation() { GuestAllocationsEnd_nid_postfix(handle); } Mutation(const Mutation&) = delete; Mutation& operator=(const Mutation&) = delete; -#ifdef _WIN32 void RegisterMainImage() { GuestAllocationsRegisterMainImage_nid_postfix(handle); } -#endif void Add(void* pointer, std::size_t bytes, bool readable, bool writable) { GuestAllocationsAdd_nid_postfix(handle, pointer, bytes, readable, writable); } void RequireUnpinned(const void* pointer, std::size_t bytes) const { GuestAllocationsRequireUnpinned_nid_postfix(handle, pointer, bytes); } void RequireAvailable(const void* pointer, std::size_t bytes) const { GuestAllocationsRequireAvailable_nid_postfix(handle, pointer, bytes); } diff --git a/core/libs/prx/libc/src/GuestAllocations.cpp b/core/libs/prx/libc/src/GuestAllocations.cpp index bcac0d0cf..08e9dfc0c 100644 --- a/core/libs/prx/libc/src/GuestAllocations.cpp +++ b/core/libs/prx/libc/src/GuestAllocations.cpp @@ -9,6 +9,9 @@ #define NOMINMAX #endif #include +#else +#include +#include #endif namespace GuestAllocations { @@ -75,6 +78,51 @@ void GuestAllocationsRegisterMainImage_nid_postfix(void*) { state.ranges.swap(replacement); state.mainImageRegistered = true; } +#else +void GuestAllocationsRegisterMainImage_nid_postfix(void*) { + auto& state = registry(); + if (state.mainImageRegistered) return; + struct Page { + bool readable = false; + bool writable = false; + }; + std::map pages; + const auto pageSize = static_cast(::sysconf(_SC_PAGESIZE)); + std::pair*, std::uint64_t> collection{&pages, pageSize}; + dl_iterate_phdr([](dl_phdr_info* image, std::size_t, void* data) { + auto& collected = *static_cast*, std::uint64_t>*>(data); + for (int index = 0; index < image->dlpi_phnum; ++index) { + const auto& header = image->dlpi_phdr[index]; + if (header.p_type != PT_LOAD || header.p_memsz == 0) continue; + const auto start = (image->dlpi_addr + header.p_vaddr) & ~(collected.second - 1); + const auto end = (image->dlpi_addr + header.p_vaddr + header.p_memsz + collected.second - 1) & ~(collected.second - 1); + for (auto page = start; page < end; page += collected.second) { + auto& entry = (*collected.first)[page]; + entry.readable = entry.readable || (header.p_flags & (PF_R | PF_W)) != 0; + entry.writable = entry.writable || (header.p_flags & PF_W) != 0; + } + } + return 1; + }, &collection); + require(!pages.empty(), "main guest image has no loadable segments"); + auto replacement = state.ranges; + for (auto page = pages.begin(); page != pages.end();) { + auto last = page; + while (std::next(last) != pages.end() && std::next(last)->first == last->first + pageSize && std::next(last)->second.readable == page->second.readable && std::next(last)->second.writable == page->second.writable) ++last; + const auto address = page->first; + const auto bytes = static_cast(last->first + pageSize - address); + const auto next = replacement.lower_bound(address); + require(next == replacement.end() || address + bytes <= next->first, "guest image overlaps a registered allocation"); + if (next != replacement.begin()) { + const auto& previous = *std::prev(next)->second; + require(previous.address + previous.bytes <= address, "guest image overlaps a registered allocation"); + } + replacement.emplace(address, std::make_shared(Range{address, bytes, page->second.readable, page->second.writable, address, bytes, false})); + page = std::next(last); + } + state.ranges.swap(replacement); + state.mainImageRegistered = true; +} #endif void GuestAllocationsAdd_nid_postfix(void*, void* pointer, std::size_t bytes, bool readable, bool writable) { diff --git a/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp b/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp index ac952bac7..6bb6e60f8 100644 --- a/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp +++ b/core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp @@ -149,6 +149,8 @@ int DoMprotect(const void* addr, size_t len, int prot) { if (memory.AllocationBase != GetModuleHandleW(nullptr)) throw std::invalid_argument("Memory protection of a foreign image is not supported"); mutation.RegisterMainImage(); } +#else + mutation.RegisterMainImage(); #endif mutation.Protect(pointer, bytes, (prot & 3) != 0, (prot & 2) != 0, [&] { if (mprotect(const_cast(pointer), bytes, nativeProtection) != 0) throw std::system_error(errno, std::generic_category(), "mprotect failed"); From f9695c1069d91ec6ecf34ed58cb95cf1abfd1f62 Mon Sep 17 00:00:00 2001 From: Pacuka <69674426+Pacuka@users.noreply.github.com> Date: Sat, 26 Sep 2026 11:15:16 +0200 Subject: [PATCH 7/8] fix(agc): accept the SDK default GDS range in sceAgcCbReleaseMem The SDK's inline release wrapper passes gdsOffset 0 and gdsSize 1 for every release, not only GDS ones. The packet ignores the range unless the GDS data selector is used, so accept that default. Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libSceAgc/Cb/src/Sync.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/libs/prx/libSceAgc/Cb/src/Sync.cpp b/core/libs/prx/libSceAgc/Cb/src/Sync.cpp index 74115f047..e87166ec6 100644 --- a/core/libs/prx/libSceAgc/Cb/src/Sync.cpp +++ b/core/libs/prx/libSceAgc/Cb/src/Sync.cpp @@ -38,7 +38,7 @@ std::uint32_t* APS5_VABI sceAgcCbReleaseMem(CommandBuffer* buf, std::uint8_t act Agc::Command::Require(data == 0, __func__, "GDS release cannot use immediate data"); value = gdsOffset | (static_cast(gdsSize) << 16u); } else { - Agc::Command::Require(gdsOffset == 0 && gdsSize == 0, __func__, "GDS parameters supplied for a non-GDS release"); + Agc::Command::Require(gdsOffset == 0 && gdsSize <= 1, __func__, "GDS parameters supplied for a non-GDS release"); } if (dataSelect != 0 && interrupt != 4) { Agc::Command::CheckAddress(guestAddress, dataSelect == 2 || dataSelect == 3 ? 8 : 4, __func__); From 37074ab8930d0ead7df9695d0c9707dc5cba29bc Mon Sep 17 00:00:00 2001 From: Pacuka <69674426+Pacuka@users.noreply.github.com> Date: Sat, 26 Sep 2026 11:15:16 +0200 Subject: [PATCH 8/8] fix(build): link guest library tests dynamically on Linux Tests in core/libs link against the prx shared libraries, which the global -static flag rejects on Linux ("attempted static link of dynamic object"). Drop -static in that directory on non-Windows hosts while keeping the static GCC runtime. Co-Authored-By: Claude Opus 5.5 --- core/libs/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/libs/CMakeLists.txt b/core/libs/CMakeLists.txt index 35cdadb35..57f29f6fc 100644 --- a/core/libs/CMakeLists.txt +++ b/core/libs/CMakeLists.txt @@ -1,3 +1,8 @@ +if(NOT WIN32) + string(REPLACE "-static " "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ") + string(STRIP "${CMAKE_EXE_LINKER_FLAGS}" CMAKE_EXE_LINKER_FLAGS) +endif() + add_executable(nid_patcher ${CMAKE_CURRENT_SOURCE_DIR}/nid/src/Sha1.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nid/src/NidCompute.cpp