Page 1 of 1

Got strange reaction when trying to get memory map

Posted: Tue Jun 21, 2022 12:24 am
by prcups
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:

Code: Select all

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
This is the code after I added some debug part:
https://pastebin.com/NeD85uz6

Re: Got strange reaction when trying to get memory map

Posted: Tue Jun 21, 2022 6:03 am
by davmac314
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.