The two-call GetMemoryMap() pattern you implement here (query size, allocate, query again) is exactly what the Linux kernel's EFI stub and every GRUB2/systemd-boot loader must do before calling ExitBootServices, and getting the MapKey stale is a real bug class that causes ExitBootServices to fail on real hardware. This memory map is also the direct successor to the old BIOS INT 0x15 E820 map that Linux's `e820` code parsed for decades.