diff --git a/dm/host/hle_svc.c b/dm/host/hle_svc.c index e87442e27d..e3f05d87f1 100644 --- a/dm/host/hle_svc.c +++ b/dm/host/hle_svc.c @@ -349,7 +349,25 @@ static void mem_init(void) { // and hands the whole block to its own StandardAllocator (main+0x32137a0) -- so heap size = pool − image footprint, it has only as much as the host reports. // Previously 3 GB was reported here and SetHeapSize never failed: the heap was about 150 MB smaller than on the real device, at the run entry peak the main heap had only about 18 MB left, and under high local load a timing shift made a 128 KB request return null, // which the guest writes to without a null check (CRASH main+0x1b36138, re-verified after merge with inv_tap). -#define APP_POOL DM_GAME_APP_POOL // game profile app_pool (Mario 0xCD500000) +// The application pool: the game profile's app_pool, capped at launch by DM_APP_POOL (bytes; smaller of the two wins). +// The reason to cap it: an iPhone gives a process ~8 GiB resident (jetsam per-process-limit, memstat: phys_footprint + os_proc_available_memory = 8192 MiB), less than what a +// Switch 2's application pool holds; engines that plan their memory from the pool's size adapt (set DM_APP_POOL to what the phone can charge and watch the game's own boot decisions). +// A game that needs the whole profile pool aborts on a smaller answer instead: the memstat log says which it did. +static uint64_t g_app_pool; static int g_app_pool_set; +static uint64_t app_pool(void) { + if (!g_app_pool_set) { + g_app_pool_set = 1; + uint64_t v = DM_GAME_APP_POOL; + const char *e = getenv("DM_APP_POOL"); + if (e && *e) { + uint64_t p = strtoull(e, NULL, 0); + if (p && p < v) { v = p; LOG("[mem] DM_APP_POOL caps the application pool at %#llx (game profile app_pool %#llx)", (unsigned long long)p, (unsigned long long)DM_GAME_APP_POOL); } + } + g_app_pool = v; + } + return g_app_pool; +} +#define APP_POOL app_pool() static size_t image_bytes(void) { size_t n = 0; for (int i = 0; i < g_nmod; i++) if (!g_mod[i].nro) n += g_mod[i].size; // an NRO lives in memory the game allocated (its image and bss buffers) return (n + 0x1fffff) & ~(size_t)0x1fffff; } // Giant bss (modules with the patch area before the base, patch_nso.py FAR): the image bytes beyond the file part. Used memory was reported as "heap + 64 MB", where the 64 MB covers ordinary modules' code and data (Mario's two modules are about 74 MB together, diff --git a/docs/env_switches.tsv b/docs/env_switches.tsv index 5c2b71baa2..84512398c3 100644 --- a/docs/env_switches.tsv +++ b/docs/env_switches.tsv @@ -6,6 +6,7 @@ DM_ALLOW_OTHER_METAL switch `1` lets `own_compilers.py` build the shader librari DM_AOC_DIR path Folder of add-on content: one numbered subfolder per DLC index holding that DLC's RomFS, reported by `aoc` and mounted read-only; the app, the Mac launcher and the NSP script set it when the build has DLC DM_AOC_OWNED switch `0` reports no add-on content even when `DM_AOC_DIR` has some, for runs without the DLC DM_APP_DM path Set by the iOS app of a game of several programs: the running program's `dm/p` folder, where the settings screen finds its `launcher.json` +DM_APP_POOL switch `=` (decimal or `0x` hex) caps the application pool the host reports at launch, the smaller of it and the profile's `app_pool`: GetInfo's pool total, the SetHeapSize limit and the MapPhysicalMemory limit (`app_pool` in `hle_svc.c`). For a Switch 2 game whose pool is larger than a phone gives one process; a cap that takes effect is logged once as `[mem] DM_APP_POOL caps the application pool at ...`. Unset, 0 or a value not below the profile's leaves the profile's pool DM_APP_VERSION switch Overrides the IPA's version in `build_ipa.sh`; by default it is the packed game's display version from its control data (the update's when one is packed) DM_AUDIO switch `1` plays audio through Core Audio, `0` uses the silent sink; real output is the default on iOS, the silent sink on the Mac (the Mac launcher sets `1`) DM_AUDIO_DUMP diagnostic `=` writes every PCM block the game appends as is (16-bit, 48 kHz, channel count as in the OpenAudioOut log), to judge whether a sound played