From 0293fb6f286996e18afbd5c4adc715fb834e6da8 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Fri, 5 Jan 2024 15:13:45 +0100 Subject: [PATCH] If ExitBootServices() fails, it is mostly caused by map key that is racing with asynchronous events signaled over the back of the timer interrupt. In this case new memory map should be obtained prior to another ExitBootServices() call attempt --- xtldr/modules/xtos_o/amd64/memory.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/xtldr/modules/xtos_o/amd64/memory.c b/xtldr/modules/xtos_o/amd64/memory.c index 807834b..e227867 100644 --- a/xtldr/modules/xtos_o/amd64/memory.c +++ b/xtldr/modules/xtos_o/amd64/memory.c @@ -140,7 +140,20 @@ XtEnablePaging(IN PLIST_ENTRY MemoryMappings, if(Status != STATUS_EFI_SUCCESS) { /* Failed to exit boot services */ - XtLdrProtocol->Debug.Print(L"Failed to exit boot services (Status code: %lx)\n", Status); + Status = XtLdrProtocol->Memory.GetMemoryMap(MemoryMap); + if(Status != STATUS_EFI_SUCCESS) + { + /* Unable to get memory map */ + return Status; + } + + Status = XtLdrProtocol->Util.ExitBootServices(MemoryMap->MapKey); + } + + /* Check if exitted boot services successfully */ + if(Status != STATUS_EFI_SUCCESS) + { + XtLdrProtocol->Console.Print(L"Failed to exit boot services (Status code: %lx)\n", Status); return STATUS_EFI_ABORTED; }