From 51886a05ddd5be61526c8148be879c70a2a666d0 Mon Sep 17 00:00:00 2001 From: belliash Date: Tue, 20 Dec 2022 23:06:32 +0100 Subject: [PATCH] Get rid of boot services code after exiting boot services --- xtldr/amd64/memory.c | 4 ++++ xtldr/i686/memory.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/xtldr/amd64/memory.c b/xtldr/amd64/memory.c index 0f4f850..d4e6d82 100644 --- a/xtldr/amd64/memory.c +++ b/xtldr/amd64/memory.c @@ -149,6 +149,10 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings, BlDbgPrint(L"Exiting EFI boot services\n"); EfiSystemTable->BootServices->ExitBootServices(EfiImageHandle, MemoryMap->MapKey); + /* No runtime services should touch boot services code, so get rid of it all at this point */ + EfiSystemTable->RuntimeServices->SetVirtualAddressMap(MemoryMap->MapSize, MemoryMap->DescriptorSize, + MemoryMap->DescriptorVersion, MemoryMap->Map); + /* Write PML4 to CR3 */ HlWriteCR3((UINT_PTR)*PtePointer); diff --git a/xtldr/i686/memory.c b/xtldr/i686/memory.c index 25c3b3f..f1c778d 100644 --- a/xtldr/i686/memory.c +++ b/xtldr/i686/memory.c @@ -255,6 +255,10 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings, BlDbgPrint(L"Exiting EFI boot services\n"); EfiSystemTable->BootServices->ExitBootServices(EfiImageHandle, MemoryMap->MapKey); + /* No runtime services should touch boot services code, so get rid of it all at this point */ + EfiSystemTable->RuntimeServices->SetVirtualAddressMap(MemoryMap->MapSize, MemoryMap->DescriptorSize, + MemoryMap->DescriptorVersion, MemoryMap->Map); + /* Enable PAE if supported by CPU */ if(PaeExtension) {