mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 20:25:57 +00:00
After the design in #845 by itaskaev2, with one change: no image taken after a build-time run. When a plugin's patch set is on, sdk's DT_INIT runs first, then the plugin's, in the environment of the service run (rtld image below main, the QueryMemory view, the alias pool, process-memory aliases), then the game's constructors. That is rtld's order on the Switch (oss-rtld, librtld/source/ld.cpp __rtld_modules_init runs the modules from the last loaded to the first). sdk's first DT_INIT only registers it with its musl and main's DT_INIT finishes it, so its flag stays 1 and it is not called a second time. The plugin keeps its heap blocks, GOT and alias addresses. The words the init wrote into the game modules and the plugin's .text after it are compared with patches.h: equal, the set stays on; different, it goes off for this run, the reason is logged, the Mods tab row says so and build-cache/plugins.stale has the next start run the rebuild. The branches written into main's .text are taken back. mods.c reads build-cache/plugins.status: a built plugin's set joins its mod's sets and the Mods tab order, a refused one keeps its mod off with the reason (the catalog texts in en, ru, pt-BR, zh-Hans), a plugin without a line waits for the rebuild. A plugin file changed after the build is left out by the loader. TOTK_PLUGIN_TRACE=1 logs the first call of each hook entry. Without a plugin in the build nothing of this runs. --probe-mods covers a plugin set against another mod's patch on one site, a refused plugin, one the build lacks and one whose start differs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
2.6 KiB
C
48 lines
2.6 KiB
C
// Kernel internals shared by kernel.c, svc.c and the kernel probe (kernel_probe.c). Not part of the host.h contract.
|
|
#pragma once
|
|
#include "host.h"
|
|
|
|
// Horizon kernel results (module 1).
|
|
#define KERN_R_OUT_OF_RESOURCE 0xCE01u
|
|
#define KERN_R_INVALID_STATE_MEM 0xD401u
|
|
#define KERN_R_BAD_HANDLE 0xE401u
|
|
#define KERN_R_TIMEOUT 0xEA01u
|
|
#define KERN_R_CANCELLED 0xEC01u
|
|
#define KERN_R_INVALID_ENUM 0xF001u
|
|
#define KERN_R_BAD_STATE 0xFA01u
|
|
#define KERN_H_CURRENT_THREAD 0xFFFF8000u
|
|
#define KERN_WAITERS_BIT 0x40000000u
|
|
|
|
// Fiber overrides, linked as HOST_OVERRIDE entries in kernel.c.
|
|
#define KERN_SYM_INITIALIZE_FIBER "_ZN2nn2os15InitializeFiberEPNS0_9FiberTypeEPFS2_PvES3_S3_mi"
|
|
#define KERN_SYM_FINALIZE_FIBER "_ZN2nn2os13FinalizeFiberEPNS0_9FiberTypeE"
|
|
#define KERN_SYM_SWITCH_TO_FIBER "_ZN2nn2os13SwitchToFiberEPNS0_9FiberTypeE"
|
|
#define KERN_SYM_GET_CURRENT_FIBER "_ZN2nn2os15GetCurrentFiberEv"
|
|
void kern_fiber_initialize(Cpu *c);
|
|
void kern_fiber_finalize(Cpu *c);
|
|
void kern_fiber_switch(Cpu *c);
|
|
void kern_fiber_current(Cpu *c);
|
|
|
|
uint64_t kern_threads_created(void);
|
|
|
|
// The guest frame-pointer chain from c->x[29] to stderr.
|
|
void kern_backtrace(const Cpu *c);
|
|
|
|
// ---- probe support
|
|
enum { KERN_WAIT_NONE, KERN_WAIT_LOCK, KERN_WAIT_CONDVAR, KERN_WAIT_ADDRESS, KERN_WAIT_SYNC };
|
|
#define KERN_THREAD_EXITED 100
|
|
int kern_thread_state(uint32_t handle); // KERN_WAIT_*, KERN_THREAD_EXITED, or -1 for a bad handle
|
|
void kern_core_stats(int *held_now, int *held_max); // virtual-core holders now and the most ever at once
|
|
void kern_core_stats_reset(void);
|
|
extern volatile int kern_test_cv_old_order; // WaitProcessWideKeyAtomic: release the lock before setting
|
|
// the key (MNG's pre-fix order, the negative control)
|
|
extern void (*volatile kern_test_cv_hook)(void); // called right after the lock release, holding the kernel lock
|
|
extern void (*volatile svc_test_exit_hook)(unsigned code); // svc 0x07 calls it instead of ExitProcess (probes)
|
|
|
|
// ---- mod plugin service run (plugin_init.c sets these; the game calls none of the SVCs they serve)
|
|
extern uint64_t rt_svc_tick_offset; // added to GetSystemTick (0x1E): the service run's second run picks other ticks
|
|
extern int (*rt_plugin_svc)(Cpu *c, uint32_t imm, uint64_t pc); // with RT_TRACE_PLUGIN: sees each SVC
|
|
// first; 1: refused, the result is in x0 and the SVC does not run
|
|
extern uint32_t (*rt_process_memory)(int unmap, uint64_t dst, uint32_t process, uint64_t src, uint64_t size);
|
|
// Map/UnmapProcessMemory (0x74/0x75); NULL outside the service run: fatal
|