Cap the heap at the cart-region boundary#2
Open
neilrackett wants to merge 1 commit into
Open
Conversation
__StackLimit is pico-sdk's _sbrk heap ceiling. Including LENGTH(ROM_IN_RAM) let the heap grow through the entire ROM_IN_RAM mirror -- the region the m68k executes over the cartridge bus. Boot-time allocations (the settings library alone mallocs ~13 KB) and runtime FatFs LFN buffers then silently overwrite the served cartridge code, crashing the ST with bombs / black screens that vary per build with static layout. Drop the + LENGTH(ROM_IN_RAM) so the heap is capped at the RAM/cart boundary and malloc fails cleanly (pico-sdk panics on failed malloc) instead of corrupting the m68k image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
rp/src/memmap_rp.ld, the heap ceiling is:__StackLimitis what pico-sdk's_sbrkuses to bound the heap. IncludingLENGTH(ROM_IN_RAM)lets the heap grow straight through theROM_IN_RAMmirror — the region the m68k executes from over the cartridge bus.Boot-time allocations (the settings library alone mallocs ~13 KB) and runtime FatFs LFN buffers then silently overwrite the served cartridge code, crashing the ST with bombs / a black screen. As with the array-alignment issue, the exact trigger shifts with static layout, so it is intermittent and hard to trace.
Fix
Drop
+ LENGTH(ROM_IN_RAM)so the heap is capped at the RAM/cart boundary. A failed allocation then panics cleanly (pico-sdk panics on OOM) instead of corrupting the m68k image:Verified in a downstream app whose settings-library boot mallocs were overrunning the cart region: with the heap capped, the region stays intact and any genuine OOM surfaces as a clean panic. Apps that need more heap should reclaim RAM rather than borrow the cartridge mirror.