By wrapping the few EFI handler functions used by the Xen boot process
and casting away constness where safe, it is possible to allow most of
the rest of the EFI boot code to use constant strings and GUIDs.
There are a few places in the code that casts away the const that should
be reconsidered. For instance, the config parser code modifies the config
file in place, which would not work if it were in a read-only segment.
Signed-off-by: Trammell Hudson
---
xen/arch/arm/efi/efi-boot.h | 8 +-
xen/arch/x86/efi/efi-boot.h | 40 -
xen/common/efi/boot.c | 157
3 files changed, 111 insertions(+), 94 deletions(-)
diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h
index 6527cb0bdf..13666bc065 100644
--- a/xen/arch/arm/efi/efi-boot.h
+++ b/xen/arch/arm/efi/efi-boot.h
@@ -418,9 +418,9 @@ static void __init efi_arch_memory_setup(void)
{
}
-static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
- CHAR16 *cmdline_options,
- char *cfgfile_options)
+static void __init efi_arch_handle_cmdline(const CHAR16 *image_name,
+ const CHAR16 *cmdline_options,
+ const char *cfgfile_options)
{
union string name;
char *buf;
@@ -482,7 +482,7 @@ static void __init efi_arch_handle_cmdline(CHAR16
*image_name,
}
static void __init efi_arch_handle_module(struct file *file, const CHAR16
*name,
- char *options)
+ const char *options)
{
int node;
int chosen;
diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index 7188c9a551..8e9811f3e0 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -280,10 +280,10 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE
dir_handle, char *sect
{
union string name;
-name.s = get_value(&cfg, section, "ucode");
-if ( !name.s )
-name.s = get_value(&cfg, "global", "ucode");
-if ( name.s )
+name.cs = get_value(&cfg, section, "ucode");
+if ( !name.cs )
+name.cs = get_value(&cfg, "global", "ucode");
+if ( name.cs )
{
microcode_set_module(mbi.mods_count);
split_string(name.s);
@@ -292,29 +292,29 @@ static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE
dir_handle, char *sect
}
}
-static void __init efi_arch_handle_cmdline(CHAR16 *image_name,
- CHAR16 *cmdline_options,
- char *cfgfile_options)
+static void __init efi_arch_handle_cmdline(const CHAR16 *image_name,
+ const CHAR16 *cmdline_options,
+ const char *cfgfile_options)
{
union string name;
if ( cmdline_options )
{
-name.w = cmdline_options;
+name.cw = cmdline_options;
w2s(&name);
-place_string(&mbi.cmdline, name.s);
+place_string(&mbi.cmdline, name.cs);
}
if ( cfgfile_options )
place_string(&mbi.cmdline, cfgfile_options);
/* Insert image name last, as it gets prefixed to the other options. */
if ( image_name )
{
-name.w = image_name;
+name.cw = image_name;
w2s(&name);
}
else
-name.s = "xen";
-place_string(&mbi.cmdline, name.s);
+name.cs = "xen";
+place_string(&mbi.cmdline, name.cs);
if ( mbi.cmdline )
mbi.flags |= MBI_CMDLINE;
@@ -328,8 +328,8 @@ static void __init efi_arch_handle_cmdline(CHAR16
*image_name,
static void __init efi_arch_edd(void)
{
-static EFI_GUID __initdata bio_guid = BLOCK_IO_PROTOCOL;
-static EFI_GUID __initdata devp_guid = DEVICE_PATH_PROTOCOL;
+static const EFI_GUID __initconst bio_guid = BLOCK_IO_PROTOCOL;
+static const EFI_GUID __initconst devp_guid = DEVICE_PATH_PROTOCOL;
EFI_HANDLE *handles = NULL;
unsigned int i;
UINTN size;
@@ -339,12 +339,12 @@ static void __init efi_arch_edd(void)
BUILD_BUG_ON(offsetof(struct edd_info, edd_device_params) != EDDEXTSIZE);
BUILD_BUG_ON(sizeof(struct edd_device_params) != EDDPARMSIZE);
size = 0;
-status = efi_bs->LocateHandle(ByProtocol, &bio_guid, NULL, &size, NULL);
+status = efi_locate_handle(ByProtocol, &bio_guid, NULL, &size, NULL);
if ( status == EFI_BUFFER_TOO_SMALL )
status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
if ( !EFI_ERROR(status) )
-status = efi_bs->LocateHandle(ByProtocol, &bio_guid, NULL, &size,
- handles);
+status = efi_locate_handle(ByProtocol, &bio_guid, NULL, &size,
+ handles);
if ( EFI_ERROR(status) )
size = 0;
for ( i = 0; i < size / sizeof(*handles); ++i )