fix(nid): fix updates detections for nid_patcher rerun

This commit is contained in:
boykopovar 2026-09-07 09:55:41 +03:00
parent d5bc6c9f66
commit 9d4c87b686
4 changed files with 29 additions and 21 deletions

View File

@ -1,10 +1,10 @@
# About
Converter for native execution of PlayStation 5 ELF binaries on Linux through binary format conversion and ABI compatibility. The relinker implementation uses only the C++20 standard library and performs deterministic binary transformation without heuristics or interpretation.
Converter for native execution of PlayStation 5 ELF binaries on Linux through binary format conversion and ABI compatibility. The relinker implementation uses only the C++20 standard library and performs deterministic binary transformation.
## Status
Execution reaches `_start`, stack unwinding and exception handling tables are built. All unimplemented stub functions throw std::runtime_error. `what()` is printed to stderr and the process terminates. Now: `pthread_mutex_lock not implemented`
Execution reaches `_start`, stack unwinding and exception handling tables are built. All unimplemented stub functions throw std::runtime_error. `what()` is printed to stderr and the process terminates. Now: `memset_nid_postfix not implemented`
## Disclaimer

View File

@ -14,28 +14,31 @@ set(LIBC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/prx/libc)
add_library(libc SHARED EXCLUDE_FROM_ALL ${LIBC_DIR}/Export.cpp)
target_include_directories(libc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
set(UNPATCHED_DIR ${CMAKE_CURRENT_BINARY_DIR}/libs/unpatched)
set(PATCHED_DIR ${CMAKE_CURRENT_BINARY_DIR}/libs)
set_target_properties(libc PROPERTIES
PREFIX ""
SUFFIX .prx
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs
RUNTIME_OUTPUT_DIRECTORY ${UNPATCHED_DIR}
LIBRARY_OUTPUT_DIRECTORY ${UNPATCHED_DIR}
)
set(LIBC_PRX_FILE ${CMAKE_CURRENT_BINARY_DIR}/libs/libc.prx)
set(LIBC_STAMP_FILE ${CMAKE_CURRENT_BINARY_DIR}/libs/libc.patched)
set(LIBC_UNPATCHED ${UNPATCHED_DIR}/libc.prx)
set(LIBC_PATCHED ${PATCHED_DIR}/libc.prx)
add_custom_command(
OUTPUT ${LIBC_STAMP_FILE}
COMMAND $<TARGET_FILE:nid_patcher> libc ${LIBC_PRX_FILE}
COMMAND ${CMAKE_COMMAND} -E touch ${LIBC_STAMP_FILE}
DEPENDS nid_patcher libc
OUTPUT ${LIBC_PATCHED}
COMMAND ${CMAKE_COMMAND} -E copy ${LIBC_UNPATCHED} ${LIBC_PATCHED}
COMMAND $<TARGET_FILE:nid_patcher> libc ${LIBC_PATCHED}
DEPENDS nid_patcher libc ${LIBC_UNPATCHED}
COMMENT "Patching NIDs for libc"
)
file(GLOB LIBS_DIRS LIST_DIRECTORIES true ${CMAKE_CURRENT_SOURCE_DIR}/prx/*)
list(REMOVE_ITEM LIBS_DIRS ${LIBC_DIR})
set(PATCHED_STAMPS ${LIBC_STAMP_FILE})
set(PATCHED_OUTPUTS ${LIBC_PATCHED})
foreach(LIB_DIR ${LIBS_DIRS})
if(IS_DIRECTORY ${LIB_DIR})
@ -54,23 +57,23 @@ foreach(LIB_DIR ${LIBS_DIRS})
set_target_properties(${LIB_NAME} PROPERTIES
PREFIX ""
SUFFIX .prx
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/libs
RUNTIME_OUTPUT_DIRECTORY ${UNPATCHED_DIR}
LIBRARY_OUTPUT_DIRECTORY ${UNPATCHED_DIR}
)
set(RPX_FILE ${CMAKE_CURRENT_BINARY_DIR}/libs/${LIB_NAME}.prx)
set(STAMP_FILE ${CMAKE_CURRENT_BINARY_DIR}/libs/${LIB_NAME}.patched)
set(UNPATCHED_FILE ${UNPATCHED_DIR}/${LIB_NAME}.prx)
set(PATCHED_FILE ${PATCHED_DIR}/${LIB_NAME}.prx)
add_custom_command(
OUTPUT ${STAMP_FILE}
COMMAND $<TARGET_FILE:nid_patcher> ${LIB_NAME} ${RPX_FILE}
COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_FILE}
DEPENDS nid_patcher ${LIB_NAME}
OUTPUT ${PATCHED_FILE}
COMMAND ${CMAKE_COMMAND} -E copy ${UNPATCHED_FILE} ${PATCHED_FILE}
COMMAND $<TARGET_FILE:nid_patcher> ${LIB_NAME} ${PATCHED_FILE}
DEPENDS nid_patcher ${LIB_NAME} ${UNPATCHED_FILE}
COMMENT "Patching NIDs for ${LIB_NAME}"
)
list(APPEND PATCHED_STAMPS ${STAMP_FILE})
list(APPEND PATCHED_OUTPUTS ${PATCHED_FILE})
endif()
endforeach()
add_custom_target(libs DEPENDS ${PATCHED_STAMPS})
add_custom_target(libs DEPENDS ${PATCHED_OUTPUTS})

View File

@ -9,6 +9,7 @@ extern "C" {
void* memset_nid_postfix(void* s, int c, size_t n) {
NotImplemented_nid_no_patch(__func__);
fprintf(stderr, "memset_nid_postfix: s=%p c=%d n=%zu\n", s, c, n);
return std::memset(s, c, n);
}

View File

@ -1,6 +1,7 @@
#include "DirectMemory.hpp"
#include "MemoryPool.hpp"
#include <sys/mman.h>
#include <cstdio>
static int LinuxProtFromSce(int prot) {
int result = PROT_NONE;
@ -11,6 +12,7 @@ static int LinuxProtFromSce(int prot) {
}
int DoMapDirect(void** addr, size_t len, int prot, int flags, int64_t physStart, size_t alignment) {
fprintf(stderr, "DoMapDirect: addr=%p len=%zu prot=%d flags=%d physStart=%ld\n", addr ? *addr : nullptr, len, prot, flags, physStart);
(void)alignment;
if (!addr || len == 0 || (len & (PS5_PAGE_SIZE - 1)) || physStart < 0
|| (static_cast<uint64_t>(physStart) & (PS5_PAGE_SIZE - 1)))
@ -22,11 +24,13 @@ int DoMapDirect(void** addr, size_t len, int prot, int flags, int64_t physStart,
if (fixed) mmapFlags |= MAP_FIXED;
void* result = mmap(hint, len, LinuxProtFromSce(prot), mmapFlags, -1, 0);
if (result == MAP_FAILED) return SCE_KERNEL_ERROR_ENOMEM;
fprintf(stderr, "DoMapDirect: mmap result=%p linuxProt=%d\n", result, LinuxProtFromSce(prot));
*addr = result;
return 0;
}
int DoMapAnon(void** addr, size_t len, int prot, int flags) {
fprintf(stderr, "DoMapAnon: addr=%p len=%zu prot=%d flags=%d\n", addr ? *addr : nullptr, len, prot, flags);
if (!addr || len == 0 || (len & (PS5_PAGE_SIZE - 1))) return SCE_KERNEL_ERROR_EINVAL;
constexpr int GUEST_MAP_FIXED = 0x10;
bool fixed = (flags & GUEST_MAP_FIXED) != 0;