[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 ("").
This commit is contained in:
tkchia 2023-05-29 20:19:57 +00:00
parent ddc203b2a9
commit ebd7759cc3

View file

@ -195,7 +195,7 @@ __msabi EFI_STATUS EfiMain(EFI_HANDLE ImageHandle,
Address = 0x79000; Address = 0x79000;
SystemTable->BootServices->AllocatePages( SystemTable->BootServices->AllocatePages(
AllocateAddress, EfiRuntimeServicesData, AllocateAddress, EfiRuntimeServicesData,
(0x7e000 - 0x79000 + sizeof(struct EfiArgs) + 4095) / 4096, &Address); (0x7f000 - 0x79000 + sizeof(struct EfiArgs) + 4095) / 4096, &Address);
Address = IMAGE_BASE_PHYSICAL; Address = IMAGE_BASE_PHYSICAL;
SystemTable->BootServices->AllocatePages( SystemTable->BootServices->AllocatePages(
AllocateAddress, EfiRuntimeServicesData, AllocateAddress, EfiRuntimeServicesData,
@ -203,7 +203,7 @@ __msabi EFI_STATUS EfiMain(EFI_HANDLE ImageHandle,
mm = __get_mm_phy(); mm = __get_mm_phy();
SystemTable->BootServices->SetMem(mm, sizeof(*mm), 0); SystemTable->BootServices->SetMem(mm, sizeof(*mm), 0);
SystemTable->BootServices->SetMem( 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, SystemTable->BootServices->CopyMem((void *)IMAGE_BASE_PHYSICAL,
__executable_start, __executable_start,
_end - __executable_start); _end - __executable_start);
@ -211,7 +211,7 @@ __msabi EFI_STATUS EfiMain(EFI_HANDLE ImageHandle,
/* /*
* Converts UEFI shell arguments to argv. * Converts UEFI shell arguments to argv.
*/ */
ArgBlock = (struct EfiArgs *)0x7e000; ArgBlock = (struct EfiArgs *)0x7f000;
SystemTable->BootServices->HandleProtocol(ImageHandle, SystemTable->BootServices->HandleProtocol(ImageHandle,
&kEfiLoadedImageProtocol, &ImgInfo); &kEfiLoadedImageProtocol, &ImgInfo);
CmdLine = (const char16_t *)ImgInfo->LoadOptions; CmdLine = (const char16_t *)ImgInfo->LoadOptions;