if (*cpio_buffer_size > UINTN_MAX - l) /* overflow check */
return EFI_OUT_OF_RESOURCES;
- a = ReallocatePool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
- if (!a)
- return EFI_OUT_OF_RESOURCES;
+ a = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
*cpio_buffer = a;
a = (CHAR8*) *cpio_buffer + *cpio_buffer_size;
if (*cpio_buffer_size > UINTN_MAX - l) /* overflow check */
return EFI_OUT_OF_RESOURCES;
- a = ReallocatePool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
- if (!a)
- return EFI_OUT_OF_RESOURCES;
- *cpio_buffer = a;
+ *cpio_buffer = a = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
a = (CHAR8*) *cpio_buffer + *cpio_buffer_size;
CopyMem(a, "070701", 6); /* magic ID */
if (e > p) {
_cleanup_freepool_ CHAR8 *t = NULL;
- t = strndup8(path, e - path);
+ t = xstrndup8(path, e - path);
if (!t)
return EFI_OUT_OF_RESOURCES;
"00000000"
"TRAILER!!!\0\0\0"; /* There's a fourth NUL byte appended here, because this is a string */
- void *a;
-
/* Generates the cpio trailer record that indicates the end of our initrd cpio archive */
assert(cpio_buffer);
assert(cpio_buffer_size);
assert_cc(sizeof(trailer) % 4 == 0);
- a = ReallocatePool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + sizeof(trailer));
- if (!a)
- return EFI_OUT_OF_RESOURCES;
-
- *cpio_buffer = a;
+ *cpio_buffer = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + sizeof(trailer));
CopyMem((UINT8*) *cpio_buffer + *cpio_buffer_size, trailer, sizeof(trailer));
*cpio_buffer_size += sizeof(trailer);
if (!root)
return log_error_status_stall(EFI_LOAD_ERROR, L"Unable to open root directory.");
- extra_dir_path = PoolPrint(L"%D" EXTRA_DIR_SUFFIX, loaded_image->FilePath);
- if (!extra_dir_path)
- return log_oom();
-
+ extra_dir_path = xpool_print(L"%D" EXTRA_DIR_SUFFIX, loaded_image->FilePath);
err = open_directory(root, extra_dir_path, &extra_dir);
if (err == EFI_NOT_FOUND) {
/* No extra subdir, that's totally OK */
if (StrLen(dirent->FileName) > 255) /* Max filename size on Linux */
continue;
- d = StrDuplicate(dirent->FileName);
- if (!d)
- return log_oom();
+ d = xstrdup(dirent->FileName);
if (n_items+2 > n_allocated) {
UINTN m;
return log_oom();
m = n_items + 16;
- items = ReallocatePool(items, n_allocated * sizeof(UINT16*), m * sizeof(UINT16*));
- if (!items)
- return log_oom();
-
+ items = xreallocate_pool(items, n_allocated * sizeof(UINT16*), m * sizeof(UINT16*));
n_allocated = m;
}
assert(loaded_image);
assert(fname);
- spath = PoolPrint(L"\\EFI\\systemd\\drivers\\%s", fname);
- if (!spath)
- return log_oom();
-
+ spath = xpool_print(L"\\EFI\\systemd\\drivers\\%s", fname);
path = FileDevicePath(loaded_image->DeviceHandle, spath);
if (!path)
return log_oom();
#include "initrd.h"
#include "macro-fundamental.h"
#include "missing_efi.h"
+#include "util.h"
/* extend LoadFileProtocol */
struct initrd_loader {
if (err != EFI_NOT_FOUND) /* InitrdMedia is already registered */
return EFI_ALREADY_STARTED;
- loader = AllocatePool(sizeof(struct initrd_loader));
- if (!loader)
- return EFI_OUT_OF_RESOURCES;
-
+ loader = xnew(struct initrd_loader, 1);
*loader = (struct initrd_loader) {
.load_file.LoadFile = initrd_load_file,
.address = initrd_address,
assert(ret_image);
/* create and install new LoadedImage Protocol */
- loaded_image = AllocatePool(sizeof(EFI_LOADED_IMAGE));
- if (!loaded_image)
- return EFI_OUT_OF_RESOURCES;
-
- /* provide the image base address and size */
+ loaded_image = xnew(EFI_LOADED_IMAGE, 1);
*loaded_image = (EFI_LOADED_IMAGE) {
.ImageBase = (void *) linux_buffer,
.ImageSize = linux_length
assert(description);
desc_len = StrSize(description);
- tcg_event = AllocateZeroPool(OFFSETOF(TCG_PCR_EVENT, Event) + desc_len);
- if (!tcg_event)
- return EFI_OUT_OF_RESOURCES;
-
+ tcg_event = xallocate_zero_pool(OFFSETOF(TCG_PCR_EVENT, Event) + desc_len);
*tcg_event = (TCG_PCR_EVENT) {
.EventSize = desc_len,
.PCRIndex = pcrindex,
assert(description);
desc_len = StrSize(description);
- tcg_event = AllocateZeroPool(OFFSETOF(EFI_TCG2_EVENT, Event) + desc_len);
- if (!tcg_event)
- return EFI_OUT_OF_RESOURCES;
-
+ tcg_event = xallocate_zero_pool(OFFSETOF(EFI_TCG2_EVENT, Event) + desc_len);
*tcg_event = (EFI_TCG2_EVENT) {
.Size = OFFSETOF(EFI_TCG2_EVENT, Event) + desc_len,
.Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER),
return EFI_LOAD_ERROR;
section_table_len = pe.FileHeader.NumberOfSections * sizeof(struct PeSectionHeader);
- section_table = AllocatePool(section_table_len);
+ section_table = xallocate_pool(section_table_len);
if (!section_table)
return EFI_OUT_OF_RESOURCES;
if (!rng)
return EFI_UNSUPPORTED;
- data = AllocatePool(size);
- if (!data)
- return log_oom();
+ data = xallocate_pool(size);
err = rng->GetRNG(rng, NULL, size, data);
if (EFI_ERROR(err))
/* Hashes the specified parameters in counter mode, generating n hash values, with the counter in the
* range counter_start…counter_start+n-1. */
- output = AllocatePool(n * HASH_VALUE_SIZE);
- if (!output)
- return log_oom();
+ output = xallocate_pool(n * HASH_VALUE_SIZE);
for (UINTN i = 0; i < n; i++)
hash_once(old_seed, rng, size,
if (size > RANDOM_MAX_SIZE_MAX)
return log_error_status_stall(EFI_INVALID_PARAMETER, L"Random seed file is too large.");
- seed = AllocatePool(size);
- if (!seed)
- return log_oom();
+ seed = xallocate_pool(size);
rsize = size;
err = handle->Read(handle, &rsize, seed);
struct bmp_dib *dib;
struct bmp_map *map;
const UINT8 *pixmap;
- UINT64 blt_size;
_cleanup_freepool_ void *blt = NULL;
UINTN x_pos = 0;
UINTN y_pos = 0;
return err;
/* EFI buffer */
- blt_size = sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * dib->x * dib->y;
- blt = AllocatePool(blt_size);
- if (!blt)
- return EFI_OUT_OF_RESOURCES;
+ blt = xnew(EFI_GRAPHICS_OUTPUT_BLT_PIXEL, dib->x * dib->y);
err = GraphicsOutput->Blt(
GraphicsOutput, blt,
/* if LoaderFirmwareInfo is not set, let's set it */
if (efivar_get_raw(LOADER_GUID, L"LoaderFirmwareInfo", NULL, NULL) != EFI_SUCCESS) {
_cleanup_freepool_ CHAR16 *s = NULL;
-
- s = PoolPrint(L"%s %d.%02d", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
- if (s)
- efivar_set(LOADER_GUID, L"LoaderFirmwareInfo", s, 0);
- else
- log_oom();
+ s = xpool_print(L"%s %d.%02d", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
+ efivar_set(LOADER_GUID, L"LoaderFirmwareInfo", s, 0);
}
/* ditto for LoaderFirmwareType */
if (efivar_get_raw(LOADER_GUID, L"LoaderFirmwareType", NULL, NULL) != EFI_SUCCESS) {
_cleanup_freepool_ CHAR16 *s = NULL;
-
- s = PoolPrint(L"UEFI %d.%02d", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
- if (s)
- efivar_set(LOADER_GUID, L"LoaderFirmwareType", s, 0);
- else
- log_oom();
+ s = xpool_print(L"UEFI %d.%02d", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
+ efivar_set(LOADER_GUID, L"LoaderFirmwareType", s, 0);
}
/* add StubInfo */
if ((!secure_boot_enabled() || cmdline_len == 0) && loaded_image->LoadOptionsSize > 0 &&
*(CHAR16 *) loaded_image->LoadOptions > 0x1F) {
cmdline_len = (loaded_image->LoadOptionsSize / sizeof(CHAR16)) * sizeof(CHAR8);
- cmdline = cmdline_owned = AllocatePool(cmdline_len);
- if (!cmdline)
- return log_oom();
+ cmdline = cmdline_owned = xallocate_pool(cmdline_len);
for (UINTN i = 0; i < cmdline_len; i++)
cmdline[i] = ((CHAR16 *) loaded_image->LoadOptions)[i];
}
/* Make sure a terminating NUL is available at the end */
- val = AllocatePool(size + sizeof(CHAR16));
- if (!val)
- return EFI_OUT_OF_RESOURCES;
+ val = xallocate_pool(size + sizeof(CHAR16));
CopyMem(val, buf, size);
val[size / sizeof(CHAR16)] = 0; /* NUL terminate */
assert(name);
l = sizeof(CHAR16 *) * EFI_MAXIMUM_VARIABLE_SIZE;
- buf = AllocatePool(l);
- if (!buf)
- return EFI_OUT_OF_RESOURCES;
+ buf = xallocate_pool(l);
err = RT->GetVariable((CHAR16 *) name, (EFI_GUID *) vendor, NULL, &l, buf);
if (!EFI_ERROR(err)) {
return err;
}
- buf = AllocatePool(size + 1);
- if (!buf)
- return EFI_OUT_OF_RESOURCES;
-
+ buf = xallocate_pool(size + 1);
err = handle->Read(handle, &size, buf);
if (EFI_ERROR(err))
return err;
/* A lot like LibFileInfo() but with useful error propagation */
- fi = AllocatePool(size);
- if (!fi)
- return EFI_OUT_OF_RESOURCES;
-
+ fi = xallocate_pool(size);
err = handle->GetInfo(handle, &GenericFileInfo, &size, fi);
if (err == EFI_BUFFER_TOO_SMALL) {
FreePool(fi);
- fi = AllocatePool(size); /* GetInfo tells us the required size, let's use that now */
- if (!fi)
- return EFI_OUT_OF_RESOURCES;
-
+ fi = xallocate_pool(size); /* GetInfo tells us the required size, let's use that now */
err = handle->GetInfo(handle, &GenericFileInfo, &size, fi);
}
if (!*buffer) {
sz = OFFSETOF(EFI_FILE_INFO, FileName) /* + 256 */;
-
- *buffer = AllocatePool(sz);
- if (!*buffer)
- return EFI_OUT_OF_RESOURCES;
-
+ *buffer = xallocate_pool(sz);
*buffer_size = sz;
} else
sz = *buffer_size;
err = handle->Read(handle, &sz, *buffer);
if (err == EFI_BUFFER_TOO_SMALL) {
FreePool(*buffer);
-
- *buffer = AllocatePool(sz);
- if (!*buffer) {
- *buffer_size = 0;
- return EFI_OUT_OF_RESOURCES;
- }
-
+ *buffer = xallocate_pool(sz);
*buffer_size = sz;
-
err = handle->Read(handle, &sz, *buffer);
}
if (EFI_ERROR(err))
return c;
}
-CHAR8 *strndup8(const CHAR8 *p, UINTN sz) {
+CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz) {
CHAR8 *n;
/* Following efilib's naming scheme this function would be called strndupa(), but we already have a
sz = strnlena(p, sz);
- n = AllocatePool(sz + 1);
- if (!n)
- return NULL;
+ n = xallocate_pool(sz + 1);
if (sz > 0)
CopyMem(n, p, sz);
EFI_STATUS readdir_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
UINTN strnlena(const CHAR8 *p, UINTN maxlen);
-CHAR8 *strndup8(const CHAR8 *p, UINTN sz);
+CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz);
BOOLEAN is_ascii(const CHAR16 *f);
assert(node);
len = (UINT8*) NextDevicePathNode(node) - (UINT8*) path;
- parent = (EFI_DEVICE_PATH*) AllocatePool(len + sizeof(EFI_DEVICE_PATH));
- if (!parent)
- return NULL;
+ parent = (EFI_DEVICE_PATH*) xallocate_pool(len + sizeof(EFI_DEVICE_PATH));
CopyMem(parent, path, len);
CopyMem((UINT8*) parent + len, EndDevicePath, sizeof(EFI_DEVICE_PATH));
/* Now load the GPT entry table */
size = ALIGN_TO((UINTN) gpt.gpt_header.SizeOfPartitionEntry * (UINTN) gpt.gpt_header.NumberOfPartitionEntries, 512);
- entries = AllocatePool(size);
- if (!entries)
- return EFI_OUT_OF_RESOURCES;
+ entries = xallocate_pool(size);
err = block_io->ReadBlocks(
block_io,