Files
psxrecomp/runtime/src/game_dispatch_compat.c
T
Alexandros Mandravillis 73eb746479 fix(runtime): validate full AOT entry before straight-line handoff
The dirty-RAM interpreter reused a suffix-aware validity check when resuming generated code after a patched call site. If an entry prologue had been overwritten but its resume suffix still matched, execution could enter stale AOT code and fall through to another generated piece without redispatch.

Emit a whole-entry predicate for straight-line handoffs, retain suffix checks for explicit guest transfers, and fail closed for older generated dispatchers until regeneration.

Validated with the MGS PAL 6,875-frame route, manual codec-to-heliport gameplay, focused continuation-guard tests, and a current-upstream recompiler build.
2026-08-20 14:51:26 +03:00

66 lines
1.6 KiB
C

/* Backward compatibility for game dispatchers generated before
* psx_game_text_native_ok() was added to the emitter.
*
* New dispatchers provide a strong definition that validates every emitted
* CFG range. Older dispatchers fall back to the pre-existing text-image
* check so dirty or byte-diverged game text is still never run natively.
*/
#include <stdint.h>
#include "dirty_ram_interp.h"
#if defined(PSX_HAS_GAME_DISPATCH) && \
!defined(PSX_GAME_DISPATCH_HAS_NATIVE_OK)
extern int psx_game_address_in_text(uint32_t addr);
int psx_game_text_native_ok(uint32_t addr)
{
const uint32_t phys = addr & 0x1FFFFFFFu;
return psx_game_address_in_text(addr) && dirty_ram_text_native_ok(phys);
}
int psx_game_text_native_ok_full(uint32_t addr)
{
(void)addr;
return 0;
}
#elif defined(PSX_HAS_GAME_DISPATCH) && \
!defined(PSX_GAME_DISPATCH_HAS_NATIVE_OK_FULL)
/* A suffix-aware dispatcher cannot prove that a later direct host fallthrough
* in the same compiled entry still matches guest RAM. Decline straight-line
* handoff until regeneration provides exact whole-entry validation. */
int psx_game_text_native_ok_full(uint32_t addr)
{
(void)addr;
return 0;
}
#elif !defined(PSX_HAS_GAME_DISPATCH)
/* The BIOS-only runtime still links shared dispatch observability. There is no
* game image to classify, so both predicates are necessarily false. */
int psx_game_address_in_text(uint32_t addr)
{
(void)addr;
return 0;
}
int psx_game_text_native_ok(uint32_t addr)
{
(void)addr;
return 0;
}
int psx_game_text_native_ok_full(uint32_t addr)
{
(void)addr;
return 0;
}
#endif /* PSX_HAS_GAME_DISPATCH */