From 7dd048346d2bfc874ee76a0b15c0b5873a48e3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20Kentt=C3=A4?= Date: Mon, 20 Nov 2023 16:10:36 +0200 Subject: [PATCH] Use EFI BS FreePool, SetMem, CopyMem --- src/config.c | 4 ++-- src/main.c | 12 ++++++------ src/util.c | 10 ++++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/config.c b/src/config.c index 90814dc..c038f0b 100644 --- a/src/config.c +++ b/src/config.c @@ -21,7 +21,7 @@ BOOLEAN ReadConfigFile(struct HackBGRT_config* config, EFI_FILE_HANDLE root_dir, // UTF-8 -> UCS-2 EFI_STATUS e = BS->AllocatePool(EfiBootServicesData, data_bytes * 2 + 2, (void**)&str); if (EFI_ERROR(e)) { - FreePool(data); + BS->FreePool(data); return FALSE; } UINT8* str0 = data; @@ -51,7 +51,7 @@ BOOLEAN ReadConfigFile(struct HackBGRT_config* config, EFI_FILE_HANDLE root_dir, } } str[str_len] = 0; - FreePool(data); + BS->FreePool(data); } for (int i = 0; i < str_len;) { diff --git a/src/main.c b/src/main.c index 355f6e0..5ee3410 100644 --- a/src/main.c +++ b/src/main.c @@ -64,12 +64,12 @@ static void SetResolution(int w, int h) { continue; } if (info_size < sizeof(*info)) { - FreePool(info); + BS->FreePool(info); continue; } new_w = info->HorizontalResolution; new_h = info->VerticalResolution; - FreePool(info); + BS->FreePool(info); // Sum of missing w/h should be minimal. int new_missing = max(w - new_w, 0) + max(h - new_h, 0); @@ -110,8 +110,8 @@ ACPI_SDT_HEADER* CreateXsdt(ACPI_SDT_HEADER* xsdt0, UINTN entries) { Log(1, L"HackBGRT: Failed to allocate memory for XSDT.\n"); return 0; } - ZeroMem(xsdt, xsdt_len); - CopyMem(xsdt, xsdt0, min(xsdt0->length, xsdt_len)); + BS->SetMem(xsdt, xsdt_len, 0); + BS->CopyMem(xsdt, xsdt0, min(xsdt0->length, xsdt_len)); xsdt->length = xsdt_len; SetAcpiSdtChecksum(xsdt); return xsdt; @@ -257,7 +257,7 @@ static BMP* LoadBMP(EFI_FILE_HANDLE root_dir, const CHAR16* path) { && bmp->compression == 0) { return bmp; } - FreePool(bmp); + BS->FreePool(bmp); Log(1, L"HackBGRT: Invalid BMP (%s)!\n", path); } else { Log(1, L"HackBGRT: Failed to load BMP (%s)!\n", path); @@ -282,7 +282,7 @@ static void CropBMP(BMP* bmp, int w, int h) { if (new_pitch < old_pitch) { for (int i = 1; i < bmp->height; ++i) { - CopyMem( + BS->CopyMem( (UINT8*) bmp + bmp->pixel_data_offset + i * new_pitch, (UINT8*) bmp + bmp->pixel_data_offset + i * old_pitch, new_pitch diff --git a/src/util.c b/src/util.c index 9368b6f..c09f1b6 100644 --- a/src/util.c +++ b/src/util.c @@ -181,9 +181,11 @@ void* LoadFileWithPadding(EFI_FILE_HANDLE dir, const CHAR16* path, UINTN* size_p return 0; } - EFI_FILE_INFO *info = LibFileInfo(handle); - UINTN size = info->FileSize; - FreePool(info); + UINT64 get_size = 0; + handle->SetPosition(handle, ~(UINT64)0); + handle->GetPosition(handle, &get_size); + handle->SetPosition(handle, 0); + UINTN size = (UINTN) get_size; void* data = 0; e = BS->AllocatePool(EfiBootServicesData, size + padding, &data); @@ -197,7 +199,7 @@ void* LoadFileWithPadding(EFI_FILE_HANDLE dir, const CHAR16* path, UINTN* size_p } handle->Close(handle); if (EFI_ERROR(e)) { - FreePool(data); + BS->FreePool(data); return 0; } if (size_ptr) {