Keep the virtual core gate on when totk.ini sets free_cores

Earlier settings menus wrote free_cores = 1 under the label "Virtual core gate", which promised the gate. Without it a
thread that holds no virtual core reports its ideal core to GetCurrentProcessorNumber, so the game's job workers all
report core 0 and run its per-core code at once. On 1.2.1 two of them add the same per-core NVN control memory, which
retires the command handle the other just recorded, and its CallCommands fails at start (#212); on 1.4.3 the game
corrupts a heap in main+0x82e00 or hangs at the title menu. A player with such a totk.ini crashed at every start and
the menu no longer shows the row.

free_cores is no longer a setting: only TOTK_FREE_CORES in the environment lifts the gate, and a free_cores value in
totk.ini is logged as ignored. The kernel probe asks the kernel whether the gate is on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-10-31 23:19:34 +03:00
1 parent b5286ef054
commit dafc35fb35
7 files changed
+23 -16

No files matched your search

+16 -2
View File
@@ -296,7 +296,14 @@ static uint32_t block_inner(RtThread *t, int kind, int64_t ns) {
// and gives it up only where Horizon would switch threads (waits, sleep, yield, exit, blocking host calls); a free
// core goes to the best waiting thread. A waiter better than a holder asks one holder to give its core up (core_kick),
// which it does at its next SVC or indirect call (kern_checkpoint, rt_dispatch), as Horizon runs the better thread at
// once; guest code without either keeps the core until it reaches one. TOTK_FREE_CORES=1 turns the gate off.
// once; guest code without either keeps the core until it reaches one.
//
// TOTK_FREE_CORES=1 in the environment turns the gate off, for experiments; totk.ini cannot. Without the gate a thread
// that holds no core reports its ideal core to GetCurrentProcessorNumber, so the game's job workers all report core 0
// and run its per-core code at once: two of them add the same per-core NVN control memory, which retires the command
// handle the other just recorded there, and its CallCommands finds no recording (1.2.1, at start); 1.4.3 corrupts a
// heap in main+0x82e00 or hangs at the title menu. The settings menu of earlier releases wrote free_cores = 1 to
// totk.ini under a label that promised the gate, and those files would keep failing at every start.
static RtThread *g_core_owner[NCORE], *g_core_wait;
static int g_cores_on = -1, g_held_max;
@@ -305,16 +312,23 @@ static void ap_init(void);
static int cores_enabled(void) {
if (g_cores_on < 0) {
g_cores_on = !cfg_bool("TOTK_FREE_CORES"); // "0" keeps the gate, like unset
const char *e = getenv("TOTK_FREE_CORES");
g_cores_on = !e || !*e || !strcmp(e, "0"); // "0" keeps the gate, like unset
const char *ini = cfg_get("TOTK_FREE_CORES"); // the environment's value when set, else totk.ini's
if (!g_cores_on)
rt_log("kernel: virtual core gate off (TOTK_FREE_CORES): guest threads run without the limit of one per "
"core that the game's per-core data needs; for experiments only, the game can fail");
else if (!e && ini && *ini && strcmp(ini, "0"))
rt_log("kernel: free_cores = %s in totk.ini ignored: the virtual core gate stays on (only TOTK_FREE_CORES "
"in the environment lifts it)", ini);
diag_init();
ap_init();
}
return g_cores_on;
}
int kern_core_gate_on(void) { return cores_enabled(); }
static int core_allowed(const RtThread *t, int c) { return (int)((t->mask >> c) & 1); }
// ---- asynchronous preemption (TOTK_ASYNC_PREEMPT, on unless 0)