diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-06-26 12:35:46 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-06-26 17:09:45 +0200 |
commit | a729187a19548941cabe144cd5287b3d71d38965 (patch) | |
tree | 51f827e9de5f5dc4039344bb3d392a2aba7705ba | |
parent | stub: add helper that turns PE section into char16_t* string (diff) | |
download | systemd-a729187a19548941cabe144cd5287b3d71d38965.tar.xz systemd-a729187a19548941cabe144cd5287b3d71d38965.zip |
stub: turn lookup_name() into shorter and more generic function that turns sectin into char* string
-rw-r--r-- | src/boot/efi/stub.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index 03b6fc8153..98d31af321 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -57,6 +57,19 @@ static char16_t* pe_section_to_str16( return xstrn8_to_16((const char *) loaded_image->ImageBase + section->memory_offset, section->size); } +static char *pe_section_to_str8( + EFI_LOADED_IMAGE_PROTOCOL *loaded_image, + const PeSectionVector *section) { + + assert(loaded_image); + assert(section); + + if (!PE_SECTION_VECTOR_IS_SET(section)) + return NULL; + + return xstrndup8((const char *)loaded_image->ImageBase + section->memory_offset, section->size); +} + static void combine_measured_flag(int *value, int measured) { assert(value); @@ -601,24 +614,6 @@ static void cmdline_append_and_measure_smbios(char16_t **cmdline, int *parameter *cmdline = xasprintf("%ls %ls", tmp, extra16); } -static void lookup_uname( - EFI_LOADED_IMAGE_PROTOCOL *loaded_image, - const PeSectionVector sections[static _UNIFIED_SECTION_MAX], - char **ret_uname) { - - assert(loaded_image); - assert(sections); - assert(ret_uname); - - if (!PE_SECTION_VECTOR_IS_SET(sections + UNIFIED_SECTION_UNAME)) { - *ret_uname = NULL; - return; - } - - *ret_uname = xstrndup8((char *)loaded_image->ImageBase + sections[UNIFIED_SECTION_UNAME].memory_offset, - sections[UNIFIED_SECTION_UNAME].size); -} - static void initrds_free(struct iovec (*initrds)[_INITRD_MAX]) { assert(initrds); @@ -928,7 +923,7 @@ static EFI_STATUS run(EFI_HANDLE image) { refresh_random_seed(loaded_image); - lookup_uname(loaded_image, sections, &uname); + uname = pe_section_to_str8(loaded_image, sections + UNIFIED_SECTION_UNAME); determine_cmdline(image, loaded_image, sections, &cmdline, ¶meters_measured); |