Skip to content

Commit 9856c05

Browse files
committed
Refactor memory management and enhance error handling in UEFI services; improve mouse event handling and add safety checks in keyboard input processing
1 parent 6a409ae commit 9856c05

9 files changed

Lines changed: 230 additions & 81 deletions

File tree

ViOS.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,35 @@ UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
340340
}
341341
}
342342
// End the UEFI services and jump to the kernel
343-
gBS->ExitBootServices(ImageHandle, 0);
343+
UINTN memoryMapSize = 0;
344+
EFI_MEMORY_DESCRIPTOR *memoryMap = NULL;
345+
UINTN mapKey;
346+
UINTN descriptorSize;
347+
UINT32 descriptorVersion;
348+
349+
Status = gBS->GetMemoryMap(&memoryMapSize, NULL, &mapKey, &descriptorSize,
350+
&descriptorVersion);
351+
memoryMapSize += descriptorSize * 10;
352+
memoryMap = AllocatePool(memoryMapSize);
353+
if (memoryMap == NULL)
354+
{
355+
return EFI_OUT_OF_RESOURCES;
356+
}
357+
358+
Status = gBS->GetMemoryMap(&memoryMapSize, memoryMap, &mapKey,
359+
&descriptorSize, &descriptorVersion);
360+
if (EFI_ERROR(Status))
361+
{
362+
FreePool(memoryMap);
363+
return Status;
364+
}
365+
366+
Status = gBS->ExitBootServices(ImageHandle, mapKey);
367+
if (EFI_ERROR(Status))
368+
{
369+
FreePool(memoryMap);
370+
return Status;
371+
}
344372

345373
__asm__ __volatile__(
346374
"movq %0, %%rdi\n\t" // Frame buffer base

ViOS64Bit/src/graphics/graphics.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,9 @@ void graphics_setup(struct graphics_info *main_graphics_info)
820820
}
821821
bool graphics_has_ancestor(struct graphics_info* graphics_child, struct graphics_info* graphics_ancestor)
822822
{
823+
if (!graphics_child || !graphics_ancestor)
824+
return false;
825+
823826
struct graphics_info* parent = graphics_child->parent;
824827
while(parent)
825828
{

0 commit comments

Comments
 (0)