Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
When I'm in EFI trying to get memory map and exit boot service, I use AllocatePool to get memory used by GetMemoryMap. But the efi application stuck after showing "Trying to get memory map with size xxx, buffer xxx. I try to Print something after function get_memory_map, and it shows:
Trying to get memory map with size: 1920, buffer: BE6B5018...
1631 -1100263400 2448
Trying to get memory map with size: 3088, buffer: BE6B5018...
?
Trying to get memory map with size: 1920, buffer: BE6B4018...
1656 -1100267496 2448
Trying to get memory map with size: 3088, buffer: BE6B4018...
?
Trying to get memory map with size: 1920, buffer: BE6B3018...
1681 -1100271592 2448
Trying to get memory map with size: 3088, buffer: BE6B3018...
?
Unable to successfully exit boot services. Last status: 2
Error: Image at 000BE54D000 start failed: Aborted
It is possible that the call to "Print" (which prints the "?") allocates memory and thus renders the memory map key invalid, which causes ExitBootServices to fail. I had a similar issue with a UEFI loader I wrote. I strongly suggest doing as little as possible between successfully getting the memory map and calling ExitBootServices, i.e. avoid directly or indirectly calling any other EFI API.