1 // SPDX-License-Identifier: GPL-2.0+
3 * efi_selftest_exception
5 * Copyright (c) 2019 Heinrich Schuchardt <xypron.glpk@gmx.de>
7 * This test checks the handling of exceptions.
9 * The efi_selftest_miniapp_exception.efi application is loaded into memory
13 #include <efi_selftest.h>
14 /* Include containing the UEFI application */
15 #include "efi_miniapp_file_image_exception.h"
17 /* Block size of compressed disk image */
18 #define COMPRESSED_DISK_IMAGE_BLOCK_SIZE 8
20 /* Binary logarithm of the block size */
21 #define LB_BLOCK_SIZE 9
23 /* File device path for LoadImage() */
25 struct efi_device_path dp;
27 struct efi_device_path end;
30 DEVICE_PATH_TYPE_MEDIA_DEVICE,
31 DEVICE_PATH_SUB_TYPE_FILE_PATH,
32 sizeof(dp.dp) + sizeof(dp.filename),
37 DEVICE_PATH_SUB_TYPE_END,
42 static efi_handle_t image_handle;
43 static struct efi_boot_services *boottime;
45 /* One 8 byte block of the compressed disk image */
51 /* Compressed file image */
52 struct compressed_file_image {
57 static struct compressed_file_image img = EFI_ST_DISK_IMG;
59 /* Decompressed file image */
63 * Decompress the disk image.
65 * @image decompressed disk image
68 static efi_status_t decompress(u8 **image)
76 ret = boottime->allocate_pool(EFI_LOADER_DATA, img.length,
78 if (ret != EFI_SUCCESS) {
79 efi_st_error("Out of memory\n");
82 boottime->set_mem(buf, img.length, 0);
85 if (!img.lines[i].line)
87 addr = img.lines[i].addr;
88 len = COMPRESSED_DISK_IMAGE_BLOCK_SIZE;
89 if (addr + len > img.length)
90 len = img.length - addr;
91 boottime->copy_mem(buf + addr, img.lines[i].line, len);
100 * @handle: handle of the loaded image
101 * @systable: system table
102 * @return: EFI_ST_SUCCESS for success
104 static int setup(const efi_handle_t handle,
105 const struct efi_system_table *systable)
107 image_handle = handle;
108 boottime = systable->boottime;
110 /* Load the application image into memory */
113 return EFI_ST_SUCCESS;
119 * Load and start the application image.
121 * @return: EFI_ST_SUCCESS for success
123 static int execute(void)
128 ret = boottime->load_image(false, image_handle, &dp.dp, image,
129 img.length, &handle);
130 if (ret != EFI_SUCCESS) {
131 efi_st_error("Failed to load image\n");
132 return EFI_ST_FAILURE;
134 ret = boottime->start_image(handle, NULL, NULL);
136 efi_st_error("Exception not triggered\n");
138 return EFI_ST_FAILURE;
141 EFI_UNIT_TEST(exception) = {
143 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,