2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2018-01-19 18:01:05 +00:00
|
|
|
/*
|
|
|
|
* efi_selftest_miniapp_exit
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 Heinrich Schuchardt
|
|
|
|
*
|
|
|
|
* This EFI application is run by the StartImage selftest.
|
|
|
|
* It uses the Exit boot service to return.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-09-30 11:26:36 +00:00
|
|
|
#include <efi_selftest.h>
|
2018-01-19 18:01:05 +00:00
|
|
|
|
2019-04-20 05:39:11 +00:00
|
|
|
static efi_guid_t loaded_image_protocol_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
|
2018-09-30 07:20:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* check_loaded_image_protocol() - check image_base/image_size
|
|
|
|
*
|
|
|
|
* Try to open the loaded image protocol. Check that this function is located
|
|
|
|
* between image_base and image_base + image_size.
|
|
|
|
*
|
|
|
|
* @image_handle: handle of the loaded image
|
|
|
|
* @systable: system table
|
2022-01-20 18:48:20 +00:00
|
|
|
* Return: status code
|
2018-09-30 07:20:06 +00:00
|
|
|
*/
|
|
|
|
static efi_status_t EFIAPI check_loaded_image_protocol
|
|
|
|
(efi_handle_t image_handle, struct efi_system_table *systable)
|
|
|
|
{
|
|
|
|
struct efi_simple_text_output_protocol *cout = systable->con_out;
|
|
|
|
struct efi_boot_services *boottime = systable->boottime;
|
|
|
|
struct efi_loaded_image *loaded_image_protocol;
|
|
|
|
efi_status_t ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open the loaded image protocol.
|
|
|
|
*/
|
|
|
|
ret = boottime->open_protocol
|
|
|
|
(image_handle, &loaded_image_protocol_guid,
|
|
|
|
(void **)&loaded_image_protocol, NULL,
|
|
|
|
NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
|
|
|
if (ret != EFI_SUCCESS) {
|
|
|
|
cout->output_string(cout,
|
2022-01-23 19:55:12 +00:00
|
|
|
u"Could not open loaded image protocol");
|
2018-09-30 07:20:06 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if ((void *)check_loaded_image_protocol <
|
|
|
|
loaded_image_protocol->image_base ||
|
|
|
|
(void *)check_loaded_image_protocol >=
|
|
|
|
loaded_image_protocol->image_base +
|
|
|
|
loaded_image_protocol->image_size) {
|
|
|
|
cout->output_string(cout,
|
2022-01-23 19:55:12 +00:00
|
|
|
u"Incorrect image_base or image_size\n");
|
2018-09-30 07:20:06 +00:00
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-19 18:01:05 +00:00
|
|
|
* Entry point of the EFI application.
|
|
|
|
*
|
2018-09-30 07:20:06 +00:00
|
|
|
* @handle: handle of the loaded image
|
|
|
|
* @systable: system table
|
2022-01-20 18:48:20 +00:00
|
|
|
* Return: status code
|
2018-01-19 18:01:05 +00:00
|
|
|
*/
|
|
|
|
efi_status_t EFIAPI efi_main(efi_handle_t handle,
|
|
|
|
struct efi_system_table *systable)
|
|
|
|
{
|
|
|
|
struct efi_simple_text_output_protocol *con_out = systable->con_out;
|
2018-09-30 11:26:36 +00:00
|
|
|
efi_status_t ret;
|
|
|
|
u16 text[] = EFI_ST_SUCCESS_STR;
|
2018-01-19 18:01:05 +00:00
|
|
|
|
2022-01-23 19:55:12 +00:00
|
|
|
con_out->output_string(con_out, u"EFI application calling Exit\n");
|
2018-01-19 18:01:05 +00:00
|
|
|
|
2018-09-30 11:26:36 +00:00
|
|
|
if (check_loaded_image_protocol(handle, systable) != EFI_SUCCESS) {
|
|
|
|
con_out->output_string(con_out,
|
2022-01-23 19:55:12 +00:00
|
|
|
u"Loaded image protocol missing\n");
|
2018-09-30 07:20:06 +00:00
|
|
|
ret = EFI_NOT_FOUND;
|
2018-09-30 11:26:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2018-09-30 07:20:06 +00:00
|
|
|
|
2018-09-30 11:26:36 +00:00
|
|
|
/* This return value is expected by the calling test */
|
|
|
|
ret = EFI_UNSUPPORTED;
|
|
|
|
out:
|
|
|
|
systable->boottime->exit(handle, ret, sizeof(text), text);
|
2018-01-19 18:01:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This statement should not be reached.
|
|
|
|
* To enable testing use a different return value.
|
|
|
|
*/
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|