Got strange reaction when trying to get memory map

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.
Post Reply
prcups
Posts: 10
Joined: Thu Jun 09, 2022 9:48 pm
Contact:

Got strange reaction when trying to get memory map

Post 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
davmac314
Member
Member
Posts: 121
Joined: Mon Jul 05, 2021 6:57 pm

Re: Got strange reaction when trying to get memory map

Post 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.
Post Reply