mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-20 20:55:56 +00:00
totk.exe --plugin-init runs a mod plugin's init on our kernel and records what it did (#845)
The plugin service run loads the modules as boot does, runs sdk's DT_INIT and then each plugin's from nn::init::Start's module-init callback (rtld initialises the last loaded module first), writes the record and exits before any game constructor, graphics or audio. The record holds every word the init wrote into a game module, the plugin's image before and after its init, the process-memory maps, and the svcs and imports it called. exlaunch's init needs a Switch-like address space: QueryMemory shows the game's own rtld image below main and the host's ranges as Inaccessible (it takes Code RX runs for modules), and a 64 GiB free pool for its random alias picks. New svcs: GetSystemTick, GetInfo 65001 (current process handle), and Map/UnmapProcessMemory, which only the service run serves: an alias is a copy whose changed words go back into the source when it is unmapped. Any other svc, such as the CreateSession fallback, ends the run with a reason. nn::oe::GetDisplayVersion is answered with the build's game version. The game calls none of these svcs; the SVC trace test is still one mask test per SVC. After the design in #845 by itaskaev2, with the init run natively instead of under Unicorn. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b94e8127af
commit
b488d9e41d
11 files changed
+559
-22
No files matched your search
+20
-2
@@ -77,6 +77,7 @@ static void cb_loader_ready(Cpu *c) {
|
||||
// afterwards (MacNativeGames loader.c:458-462).
|
||||
static void cb_module_inits(Cpu *c) {
|
||||
if (plat_cas32(&inits_done, 0, 0)) rt_fatal("boot: module constructors requested twice");
|
||||
if (rt_config()->plugin_init) plugin_init_run(c, module_named("sdk")); // the plugin service run ends there
|
||||
for (unsigned k = 0; k < sizeof inits_121 / sizeof *inits_121; k++) {
|
||||
const RtLoaded *m = module_named(expected_inits[k].name);
|
||||
uint64_t entries = m->init_array_size / 8;
|
||||
@@ -118,8 +119,8 @@ void rt_boot_event(const char *what, Cpu *c, const char *detail) {
|
||||
rt_fatal("boot: checkpoint %s reached from %s, expected main+%#llx", detail, at,
|
||||
(unsigned long long)CHECKPOINT_RET);
|
||||
if (!plat_cas32(&inits_done, 0, 0)) rt_fatal("boot: checkpoint %s before DT_INIT", detail);
|
||||
for (int i = 0; i < ldr_count(); i++)
|
||||
if (ctor_state(ldr_module(i)) != CTOR_DONE)
|
||||
for (int i = 0; i < ldr_count(); i++) // a plugin's init does not run at play time (plugin_init.c)
|
||||
if (!ldr_module(i)->plugin && ctor_state(ldr_module(i)) != CTOR_DONE)
|
||||
rt_fatal("boot: checkpoint %s: %s constructor flag reads %u", detail, ldr_module(i)->name,
|
||||
ctor_state(ldr_module(i)));
|
||||
plat_xchg32(&checkpoint_seen, 1);
|
||||
@@ -341,6 +342,23 @@ static void prewarm_main(void *arg) {
|
||||
return;
|
||||
}
|
||||
|
||||
// --plugin-init DIR: the modules load and nn::init::Start runs as at boot, and its module-init callback runs sdk's
|
||||
// DT_INIT and each plugin's instead of the game's constructors, writes the record and exits (plugin_init.c). No game
|
||||
// constructor, nnMain, shader prewarm, graphics or audio runs.
|
||||
void rt_boot_plugin_init(void) {
|
||||
check_npdm();
|
||||
plugin_init_setup();
|
||||
ldr_load(rt_config()->exefs);
|
||||
rt_patches_init(); // the generated code reads the patch page
|
||||
cb_addr[0] = hostfn_register("<rtld loader_ready>", cb_loader_ready);
|
||||
cb_addr[1] = hostfn_register("<rtld module_inits>", cb_module_inits);
|
||||
cb_addr[2] = hostfn_register("<rtld module_finis>", cb_module_finis);
|
||||
hostfn_seal();
|
||||
rt_guest_start_ns = kern_now_ns();
|
||||
kern_run_on_guest_main(guest_main);
|
||||
rt_fatal("boot: the guest main thread ended");
|
||||
}
|
||||
|
||||
void rt_boot(void) {
|
||||
check_npdm();
|
||||
if (!rt_config()->shot) vk_pipeline_async_enable(); // a --shot image must not depend on build timing
|
||||
|
||||
Reference in new issue
Block a user