Files
AnyPS5/core/relinker/elfpatcher/tests/GuestModuleArgsHost.cpp
T
jeffrey12cali 7b8b2047b8 test(relinker): assert converted modules receive the module argument block
Add a hand-built guest module with an explicit DT_INIT that forwards rdi and rsi to a
host recorder without touching them and returns a known value. The test sets a known
argument count and argument pointer, loads the converted module, and asserts that the
initialiser received both values and that the stub forwarded its return value.

The host recorder also provides the two accessor symbols, so the test resolves them
without loading libkernel. The converted module must import both accessors, which is
what distinguishes the new behaviour from the previous stub that zeroed the arguments.
2026-10-10 00:57:52 +02:00

57 lines
1.5 KiB
C++

#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstdint>
#include <cstdio>
#include <cstdlib>
namespace {
struct Pending {
std::size_t args = 0;
const void* argp = nullptr;
} pending;
[[noreturn]] void Fail(const char* message) noexcept {
std::fprintf(stderr, "Guest module argument fixture: %s\n", message);
std::fflush(stderr);
std::_Exit(EXIT_FAILURE);
}
FILE* Events() {
const auto* path = std::getenv("ANYPS5_GUEST_MODULE_ARGS");
if (!path) Fail("Missing ANYPS5_GUEST_MODULE_ARGS");
auto* file = std::fopen(path, "ab");
if (!file) Fail("Cannot open argument event file");
return file;
}
void Write(const char* text) {
auto* file = Events();
const auto written = std::fputs(text, file);
const auto closed = std::fclose(file);
if (written == EOF || closed != 0) Fail("Cannot write argument event");
}
}
extern "C" void APS5_VABI RecordArgs(std::size_t args, const void* argp) {
char line[80];
std::snprintf(line, sizeof(line), "args=%016zx argp=%016zx\n", args,
static_cast<std::size_t>(reinterpret_cast<std::uintptr_t>(argp)));
Write(line);
}
extern "C" void SetPendingArgs(std::size_t args, const void* argp) {
pending.args = args;
pending.argp = argp;
}
extern "C" const void* __aps5_get_pending_module_args_nid_no_patch() {
return &pending;
}
extern "C" void __aps5_set_module_init_result_nid_no_patch(int result) {
char line[40];
std::snprintf(line, sizeof(line), "result=%d\n", result);
Write(line);
}