Use EFI BS FreePool, SetMem, CopyMem

This commit is contained in:
Lauri Kenttä
2023-11-20 16:10:36 +02:00
parent 0dfc49c800
commit 7dd048346d
3 changed files with 14 additions and 12 deletions

View File

@@ -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;) {

View File

@@ -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

View File

@@ -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) {