Skip to content

Commit ebd7759

Browse files
author
tkchia
committed
[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 ("").
1 parent ddc203b commit ebd7759

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libc/runtime/efimain.greg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,23 @@ __msabi EFI_STATUS EfiMain(EFI_HANDLE ImageHandle,
195195
Address = 0x79000;
196196
SystemTable->BootServices->AllocatePages(
197197
AllocateAddress, EfiRuntimeServicesData,
198-
(0x7e000 - 0x79000 + sizeof(struct EfiArgs) + 4095) / 4096, &Address);
198+
(0x7f000 - 0x79000 + sizeof(struct EfiArgs) + 4095) / 4096, &Address);
199199
Address = IMAGE_BASE_PHYSICAL;
200200
SystemTable->BootServices->AllocatePages(
201201
AllocateAddress, EfiRuntimeServicesData,
202202
((_end - __executable_start) + 4095) / 4096, &Address);
203203
mm = __get_mm_phy();
204204
SystemTable->BootServices->SetMem(mm, sizeof(*mm), 0);
205205
SystemTable->BootServices->SetMem(
206-
(void *)0x79000, 0x7e000 - 0x79000 + sizeof(struct EfiArgs), 0);
206+
(void *)0x79000, 0x7f000 - 0x79000 + sizeof(struct EfiArgs), 0);
207207
SystemTable->BootServices->CopyMem((void *)IMAGE_BASE_PHYSICAL,
208208
__executable_start,
209209
_end - __executable_start);
210210

211211
/*
212212
* Converts UEFI shell arguments to argv.
213213
*/
214-
ArgBlock = (struct EfiArgs *)0x7e000;
214+
ArgBlock = (struct EfiArgs *)0x7f000;
215215
SystemTable->BootServices->HandleProtocol(ImageHandle,
216216
&kEfiLoadedImageProtocol, &ImgInfo);
217217
CmdLine = (const char16_t *)ImgInfo->LoadOptions;

0 commit comments

Comments
 (0)