Repository navigation
OS: allocate MEM1 on a 64 KiB boundary - #311
StilesCrisis wants to merge 1 commit into
Conversation
On hardware MEM1 starts at 0x80000000, so arena memory carved from it has whatever large alignment the game rounds to. Outside 64-bit Windows debug builds, AllocMEM1 used calloc, which only guarantees malloc alignment (8 or 16 bytes), so games that align pointers to absolute boundaries got addresses that weren't aligned the way they expect. Over-allocate with calloc and use the 64 KiB-aligned part (MEM1 is never freed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SjpWoYqNDKkH5Zpdbz3WaW
|
In what ways do GC games expect MEM1 to be 64k aligned? |
|
64K gives parity with the VirtualAlloc on the Windows side. Concretely, everything fails if you don't have at least 16b alignment, and if we're going to bother to add alignment, it made sense to match the side that works. (EDIT: I had put a comment about |
The Windows path doesn't VirtualAlloc for the sake of alignment, it's explicitly a debug-aiding feature to make sure MEM1 is allocated at |
|
I checked all the docs and there wasn't any policy about AI-assisted contributions so feel free to have your opinions in private. Aside from that, concretely we need some sort of alignment. 64K may well be too high but IMO we are splitting hairs--the only thing we are wasting is address space, and obviously no one is using 32-bit but me (the build was broken). The untouched pages cost nothing; they never hit RAM. Happy to dial it back to a smaller number if you feel more passionately about it than I do, just name the alignment that you think is reasonable. Based on the existence of dcbz I think 32 is an absolute minimum. |
|
Don't talk to our contributors that way, she's right about why we do things the way we do, you must actually understand the code you're submitting. |
|
I do actually understand the code, ask me anything. Sorry if I came off as brash. Just trying to contribute here. I'm not a vibe coder; I've been in the industry for a long time and I'm not pushing PRs I haven't personally read. |

The Win32 path allocated MEM1 using
VirtualAllocwhich natively gives a nice 64K alignment.The platform-neutral path just used
calloc, which has no special alignment guarantees. (In wasm, it might not even be 16-byte aligned!) Having the base of MEM1 be misaligned can break GameCube titles in all sorts of subtle ways.To get a 64K-aligned block, we now overallocate with
callocand usestd::alignto round the pointer up to a 64K boundary. (It's never freed, so we don't even need to save off the base address.)