From c9b57f1face55297b834085c503d2f580d82f501 Mon Sep 17 00:00:00 2001 From: tkchia Date: Mon, 29 May 2023 20:19:57 +0000 Subject: [PATCH] [metal] Fix argc & argv[] setting, & VM page freeing, for UEFI Part of the memory occupied by the argv[] contents was erroneously used for page tables & then later erroneously freed. The symptom was that argv[0] would show up as an empty string (""). --- libc/runtime/efimain.greg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libc/runtime/efimain.greg.c b/libc/runtime/efimain.greg.c index 783c87399..9f25c612f 100644 --- a/libc/runtime/efimain.greg.c +++ b/libc/runtime/efimain.greg.c @@ -172,7 +172,7 @@ __msabi noasan EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, Address = 0x79000; SystemTable->BootServices->AllocatePages( AllocateAddress, EfiRuntimeServicesData, - (0x7e000 - 0x79000 + sizeof(struct EfiArgs) + 4095) / 4096, &Address); + (0x7f000 - 0x79000 + sizeof(struct EfiArgs) + 4095) / 4096, &Address); Address = IMAGE_BASE_PHYSICAL; SystemTable->BootServices->AllocatePages( AllocateAddress, EfiRuntimeServicesData, @@ -180,7 +180,7 @@ __msabi noasan EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, mm = (struct mman *)0x0500; SystemTable->BootServices->SetMem(mm, sizeof(*mm), 0); SystemTable->BootServices->SetMem( - (void *)0x79000, 0x7e000 - 0x79000 + sizeof(struct EfiArgs), 0); + (void *)0x79000, 0x7f000 - 0x79000 + sizeof(struct EfiArgs), 0); SystemTable->BootServices->CopyMem((void *)IMAGE_BASE_PHYSICAL, __executable_start, _end - __executable_start); @@ -188,7 +188,7 @@ __msabi noasan EFI_STATUS EfiMain(EFI_HANDLE ImageHandle, /* * Converts UEFI shell arguments to argv. */ - ArgBlock = (struct EfiArgs *)0x7e000; + ArgBlock = (struct EfiArgs *)0x7f000; SystemTable->BootServices->HandleProtocol(ImageHandle, &kEfiLoadedImageProtocol, &ImgInfo); CmdLine = (const char16_t *)ImgInfo->LoadOptions;