[lib][uefi] Add error checking to certain functions

This commit is contained in:
Kelvin Zhang
2025-06-11 10:34:33 -07:00
parent e51cf68c3c
commit 62409f55f6
2 changed files with 22 additions and 6 deletions

View File

@@ -35,6 +35,10 @@ EfiStatus read_blocks(EfiBlockIoProtocol *self, uint32_t media_id, uint64_t lba,
printf("OOB read %llu %u\n", lba, dev->block_count);
return END_OF_MEDIA;
}
if (interface->io_stack == nullptr) {
printf("No IO stack allocted.\n");
return OUT_OF_RESOURCES;
}
const size_t bytes_read =
call_with_stack(interface->io_stack, bio_read_block, dev, buffer, lba,
@@ -67,12 +71,20 @@ EfiStatus open_block_device(EfiHandle handle, void **intf) {
static constexpr size_t kIoStackSize = 1024ul * 1024 * 64;
static void *io_stack = nullptr;
if (io_stack == nullptr) {
vmm_alloc(vmm_get_kernel_aspace(), "uefi_io_stack", kIoStackSize, &io_stack,
PAGE_SIZE_SHIFT, 0, 0);
auto status = vmm_alloc(vmm_get_kernel_aspace(), "uefi_io_stack",
kIoStackSize, &io_stack, PAGE_SIZE_SHIFT, 0, 0);
if (io_stack == nullptr) {
printf("Failed to allocated IO stack of size %zu error %d\n",
kIoStackSize, status);
return OUT_OF_RESOURCES;
}
}
printf("%s(%p)\n", __FUNCTION__, handle);
const auto interface = reinterpret_cast<EfiBlockIoInterface *>(
uefi_malloc(sizeof(EfiBlockIoInterface)));
if (interface == nullptr) {
return OUT_OF_RESOURCES;
}
memset(interface, 0, sizeof(EfiBlockIoInterface));
auto dev = bio_open(reinterpret_cast<const char *>(handle));
interface->dev = dev;

View File

@@ -52,7 +52,8 @@ constexpr auto EFI_SYSTEM_TABLE_SIGNATURE =
using EfiEntry = int (*)(void *, struct EfiSystemTable *);
template <typename T> void fill(T *data, size_t skip, uint8_t begin = 0) {
template <typename T>
void fill(T *data, size_t skip, uint8_t begin = 0) {
auto ptr = reinterpret_cast<char *>(data);
for (size_t i = 0; i < sizeof(T); i++) {
if (i < skip) {
@@ -123,13 +124,16 @@ int load_sections_and_execute(bdev_t *dev,
reinterpret_cast<EfiConfigurationTable *>(alloc_page(PAGE_SIZE));
memset(table.configuration_table, 0, PAGE_SIZE);
setup_configuration_table(&table);
platform_setup_system_table(&table);
auto status = platform_setup_system_table(&table);
if (status != SUCCESS) {
printf("platform_setup_system_table failed: %lu\n", status);
return -static_cast<int>(status);
}
constexpr size_t kStackSize = 8 * 1024ul * 1024;
auto stack = reinterpret_cast<char *>(alloc_page(kStackSize, 23));
memset(stack, 0, kStackSize);
printf("Calling kernel with stack [%p, %p]\n", stack,
stack + kStackSize - 1);
printf("Calling kernel with stack [%p, %p]\n", stack, stack + kStackSize - 1);
return call_with_stack(stack + kStackSize, entry, image_base, &table);
}