From 1274fb65d8e3af53c792450c1ba3f35ce512436d Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Wed, 28 Oct 2026 21:45:48 +0300 Subject: [PATCH] Read totk.ini in mem_init before the pool size: the size asks resolution.c, which decides output_res and render_scale once on that first call, and main read the file only after mem_init, so both settings from totk.ini and the menu were ignored and only TOTK_* environment variables reached them Co-Authored-By: Claude Opus 5.5 --- runtime/cfg.h | 2 +- runtime/main.c | 3 +-- runtime/memory.c | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/cfg.h b/runtime/cfg.h index 7d641216..c0c5dd55 100644 --- a/runtime/cfg.h +++ b/runtime/cfg.h @@ -6,7 +6,7 @@ // is kept). A name without the TOTK_ prefix goes to getenv unchanged. Safe from any thread once cfg_init has returned. const char *cfg_get(const char *name); -// Reads totk.ini once, first thing in main. Logs the file, its key count, unknown keys and environment overrides. +// Reads totk.ini once, from mem_init after the address space is claimed and before any setting is read. Logs the file, its key count, unknown keys and environment overrides. void cfg_init(void); // Replaces the loaded keys with those of the file at path (tests). 1 when the file was read, 0 when missing. diff --git a/runtime/main.c b/runtime/main.c index 2a8b61dd..0c743345 100644 --- a/runtime/main.c +++ b/runtime/main.c @@ -427,10 +427,9 @@ static void portable_paths(RtConfig *c) { } int main(int argc, char **argv) { - mem_init(); // first: claim the guest address space before anything else can land there + mem_init(); // first: claim the guest address space before anything else can land there; reads totk.ini setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); - cfg_init(); // before any setting is read AddVectoredExceptionHandler(0, crash_handler); parse_trace(); prof_start(); diff --git a/runtime/memory.c b/runtime/memory.c index 8e97143d..b0a0a839 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -253,6 +253,9 @@ void mem_init(void) { AddVectoredExceptionHandler(1, thaw_handler); // before the crash handler alias_pages = VirtualAlloc(NULL, ALIAS_PAGES, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (!alias_pages) rt_fatal("memory: cannot allocate the alias page map"); + // totk.ini is read here, once the address space is claimed and before the first setting: the pool size below + // depends on TOTK_APP_POOL and on the resolution settings (resolution.c decides them once, on this first call). + cfg_init(); const char *pool = cfg_get("TOTK_APP_POOL"); L = (RtGuestLayout){ .aslr = {low, RT_ADDRESS_LIMIT - low},