diff options
author | Jan Janssen <medhefgo@web.de> | 2022-06-24 11:37:15 +0200 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2022-06-27 12:26:21 +0200 |
commit | 3639d1b02174449343bd610c274d9d820c446908 (patch) | |
tree | baadee990451c506f4e715761b5dc2f8a11b4d35 /src/boot | |
parent | boot: Use stdint types (diff) | |
download | systemd-3639d1b02174449343bd610c274d9d820c446908.tar.xz systemd-3639d1b02174449343bd610c274d9d820c446908.zip |
boot: Use char16_t
This also switches to _cleanup_free_. Otherwise no code changes.
Diffstat (limited to 'src/boot')
-rw-r--r-- | src/boot/efi/bcd.c | 21 | ||||
-rw-r--r-- | src/boot/efi/bcd.h | 3 | ||||
-rw-r--r-- | src/boot/efi/boot.c | 167 | ||||
-rw-r--r-- | src/boot/efi/console.h | 2 | ||||
-rw-r--r-- | src/boot/efi/cpio.c | 16 | ||||
-rw-r--r-- | src/boot/efi/cpio.h | 7 | ||||
-rw-r--r-- | src/boot/efi/devicetree.c | 2 | ||||
-rw-r--r-- | src/boot/efi/devicetree.h | 5 | ||||
-rw-r--r-- | src/boot/efi/disk.c | 2 | ||||
-rw-r--r-- | src/boot/efi/disk.h | 3 | ||||
-rw-r--r-- | src/boot/efi/drivers.c | 4 | ||||
-rw-r--r-- | src/boot/efi/measure.c | 8 | ||||
-rw-r--r-- | src/boot/efi/measure.h | 9 | ||||
-rw-r--r-- | src/boot/efi/pe.c | 4 | ||||
-rw-r--r-- | src/boot/efi/pe.h | 3 | ||||
-rw-r--r-- | src/boot/efi/random-seed.c | 7 | ||||
-rw-r--r-- | src/boot/efi/random-seed.h | 3 | ||||
-rw-r--r-- | src/boot/efi/shim.c | 2 | ||||
-rw-r--r-- | src/boot/efi/stub.c | 14 | ||||
-rw-r--r-- | src/boot/efi/util.c | 90 | ||||
-rw-r--r-- | src/boot/efi/util.h | 44 |
21 files changed, 217 insertions, 199 deletions
diff --git a/src/boot/efi/bcd.c b/src/boot/efi/bcd.c index 7418473d8e..b486042d23 100644 --- a/src/boot/efi/bcd.c +++ b/src/boot/efi/bcd.c @@ -11,7 +11,6 @@ # include "string-util-fundamental.h" # define CHAR8 char -# define CHAR16 char16_t # define UINTN size_t # define TEST_STATIC static #endif @@ -229,7 +228,7 @@ static const KeyValue *get_key_value(const uint8_t *bcd, uint32_t bcd_len, const * (it always has the GUID 9dea862c-5cdd-4e70-acc1-f32b344d4795). If it contains more than * one GUID, the BCD is multi-boot and we stop looking. Otherwise we take that GUID, look it * up, and return its description property. */ -TEST_STATIC CHAR16 *get_bcd_title(uint8_t *bcd, UINTN bcd_len) { +TEST_STATIC char16_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len) { assert(bcd); if (HIVE_CELL_OFFSET >= bcd_len) @@ -269,15 +268,15 @@ TEST_STATIC CHAR16 *get_bcd_title(uint8_t *bcd, UINTN bcd_len) { CHAR8 order_guid[sizeof("{00000000-0000-0000-0000-000000000000}\0")]; if (displayorder_value->data_type != REG_MULTI_SZ || - displayorder_value->data_size != sizeof(CHAR16[sizeof(order_guid)]) || - (UINTN)(bcd + displayorder_value->data_offset) % sizeof(CHAR16) != 0) + displayorder_value->data_size != sizeof(char16_t[sizeof(order_guid)]) || + (UINTN)(bcd + displayorder_value->data_offset) % sizeof(char16_t) != 0) /* BCD is multi-boot. */ return NULL; /* Keys are stored as ASCII in registry hives if the data fits (and GUIDS always should). */ - CHAR16 *order_guid_utf16 = (CHAR16 *) (bcd + displayorder_value->data_offset); + char16_t *order_guid_utf16 = (char16_t *) (bcd + displayorder_value->data_offset); for (UINTN i = 0; i < sizeof(order_guid) - 2; i++) { - CHAR16 c = order_guid_utf16[i]; + char16_t c = order_guid_utf16[i]; switch (c) { case '-': case '{': @@ -315,13 +314,13 @@ TEST_STATIC CHAR16 *get_bcd_title(uint8_t *bcd, UINTN bcd_len) { return NULL; if (description_value->data_type != REG_SZ || - description_value->data_size < sizeof(CHAR16) || - description_value->data_size % sizeof(CHAR16) != 0 || - (UINTN)(bcd + description_value->data_offset) % sizeof(CHAR16)) + description_value->data_size < sizeof(char16_t) || + description_value->data_size % sizeof(char16_t) != 0 || + (UINTN)(bcd + description_value->data_offset) % sizeof(char16_t)) return NULL; /* The data should already be NUL-terminated. */ - CHAR16 *title = (CHAR16 *) (bcd + description_value->data_offset); - title[description_value->data_size / sizeof(CHAR16) - 1] = '\0'; + char16_t *title = (char16_t *) (bcd + description_value->data_offset); + title[description_value->data_size / sizeof(char16_t) - 1] = '\0'; return title; } diff --git a/src/boot/efi/bcd.h b/src/boot/efi/bcd.h index 63be54566a..dd666e09e7 100644 --- a/src/boot/efi/bcd.h +++ b/src/boot/efi/bcd.h @@ -2,5 +2,6 @@ #pragma once #include <efi.h> +#include <uchar.h> -CHAR16 *get_bcd_title(uint8_t *bcd, UINTN bcd_len); +char16_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len); diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 0c02396662..37d0b6b1d4 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -51,25 +51,25 @@ enum loader_type { }; typedef struct { - CHAR16 *id; /* The unique identifier for this entry (typically the filename of the file defining the entry) */ - CHAR16 *title_show; /* The string to actually display (this is made unique before showing) */ - CHAR16 *title; /* The raw (human readable) title string of the entry (not necessarily unique) */ - CHAR16 *sort_key; /* The string to use as primary sort key, usually ID= from os-release, possibly suffixed */ - CHAR16 *version; /* The raw (human readable) version string of the entry */ - CHAR16 *machine_id; + char16_t *id; /* The unique identifier for this entry (typically the filename of the file defining the entry) */ + char16_t *title_show; /* The string to actually display (this is made unique before showing) */ + char16_t *title; /* The raw (human readable) title string of the entry (not necessarily unique) */ + char16_t *sort_key; /* The string to use as primary sort key, usually ID= from os-release, possibly suffixed */ + char16_t *version; /* The raw (human readable) version string of the entry */ + char16_t *machine_id; EFI_HANDLE *device; enum loader_type type; - CHAR16 *loader; - CHAR16 *devicetree; - CHAR16 *options; - CHAR16 **initrd; - CHAR16 key; + char16_t *loader; + char16_t *devicetree; + char16_t *options; + char16_t **initrd; + char16_t key; EFI_STATUS (*call)(void); int tries_done; int tries_left; - CHAR16 *path; - CHAR16 *current_name; - CHAR16 *next_name; + char16_t *path; + char16_t *current_name; + char16_t *next_name; } ConfigEntry; typedef struct { @@ -80,10 +80,10 @@ typedef struct { uint32_t timeout_sec; /* Actual timeout used (efi_main() override > efivar > config). */ uint32_t timeout_sec_config; uint32_t timeout_sec_efivar; - CHAR16 *entry_default_config; - CHAR16 *entry_default_efivar; - CHAR16 *entry_oneshot; - CHAR16 *entry_saved; + char16_t *entry_default_config; + char16_t *entry_default_efivar; + char16_t *entry_oneshot; + char16_t *entry_saved; BOOLEAN editor; BOOLEAN auto_entries; BOOLEAN auto_firmware; @@ -140,19 +140,19 @@ static void cursor_right( } static BOOLEAN line_edit( - CHAR16 **line_in, + char16_t **line_in, UINTN x_max, UINTN y_pos) { - _cleanup_freepool_ CHAR16 *line = NULL, *print = NULL; + _cleanup_free_ char16_t *line = NULL, *print = NULL; UINTN size, len, first = 0, cursor = 0, clear = 0; assert(line_in); len = strlen16(*line_in); size = len + 1024; - line = xnew(CHAR16, size); - print = xnew(CHAR16, x_max + 1); + line = xnew(char16_t, size); + print = xnew(char16_t, x_max + 1); strcpy16(line, strempty(*line_in)); for (;;) { @@ -162,7 +162,7 @@ static BOOLEAN line_edit( UINTN cursor_color = TEXT_ATTR_SWAP(COLOR_EDIT); j = MIN(len - first, x_max); - memcpy(print, line + first, j * sizeof(CHAR16)); + memcpy(print, line + first, j * sizeof(char16_t)); while (clear > 0 && j < x_max) { clear--; print[j++] = ' '; @@ -370,7 +370,7 @@ static BOOLEAN line_edit( } } -static UINTN entry_lookup_key(Config *config, UINTN start, CHAR16 key) { +static UINTN entry_lookup_key(Config *config, UINTN start, char16_t key) { assert(config); if (key == 0) @@ -396,7 +396,7 @@ static UINTN entry_lookup_key(Config *config, UINTN start, CHAR16 key) { return IDX_INVALID; } -static CHAR16 *update_timeout_efivar(uint32_t *t, BOOLEAN inc) { +static char16_t *update_timeout_efivar(uint32_t *t, BOOLEAN inc) { assert(t); switch (*t) { @@ -434,18 +434,18 @@ static BOOLEAN unicode_supported(void) { if (cache < 0) /* Basic unicode box drawing support is mandated by the spec, but it does * not hurt to make sure it works. */ - cache = ST->ConOut->TestString(ST->ConOut, (CHAR16 *) L"─") == EFI_SUCCESS; + cache = ST->ConOut->TestString(ST->ConOut, (char16_t *) L"─") == EFI_SUCCESS; return cache; } -static void ps_string(const CHAR16 *fmt, const void *value) { +static void ps_string(const char16_t *fmt, const void *value) { assert(fmt); if (value) Print(fmt, value); } -static void ps_bool(const CHAR16 *fmt, BOOLEAN value) { +static void ps_bool(const char16_t *fmt, BOOLEAN value) { assert(fmt); Print(fmt, yes_no(value)); } @@ -461,11 +461,11 @@ static BOOLEAN ps_continue(void) { !IN_SET(key, KEYPRESS(0, SCAN_ESC, 0), KEYPRESS(0, 0, 'q'), KEYPRESS(0, 0, 'Q')); } -static void print_status(Config *config, CHAR16 *loaded_image_path) { +static void print_status(Config *config, char16_t *loaded_image_path) { UINTN x_max, y_max; uint32_t screen_width = 0, screen_height = 0; SecureBootMode secure; - _cleanup_freepool_ CHAR16 *device_part_uuid = NULL; + _cleanup_free_ char16_t *device_part_uuid = NULL; assert(config); assert(loaded_image_path); @@ -598,7 +598,7 @@ static EFI_STATUS reboot_into_firmware(void) { static BOOLEAN menu_run( Config *config, ConfigEntry **chosen_entry, - CHAR16 *loaded_image_path) { + char16_t *loaded_image_path) { assert(config); assert(chosen_entry); @@ -613,8 +613,8 @@ static BOOLEAN menu_run( BOOLEAN refresh = TRUE, highlight = FALSE; UINTN x_start = 0, y_start = 0, y_status = 0; UINTN x_max, y_max; - _cleanup_(strv_freep) CHAR16 **lines = NULL; - _cleanup_freepool_ CHAR16 *clearline = NULL, *separator = NULL, *status = NULL; + _cleanup_(strv_freep) char16_t **lines = NULL; + _cleanup_free_ char16_t *clearline = NULL, *separator = NULL, *status = NULL; uint32_t timeout_efivar_saved = config->timeout_sec_efivar; uint32_t timeout_remain = config->timeout_sec == TIMEOUT_MENU_FORCE ? 0 : config->timeout_sec; BOOLEAN exit = FALSE, run = TRUE, firmware_setup = FALSE; @@ -678,12 +678,12 @@ static BOOLEAN menu_run( separator = mfree(separator); /* menu entries title lines */ - lines = xnew(CHAR16*, config->entry_count + 1); + lines = xnew(char16_t *, config->entry_count + 1); for (UINTN i = 0; i < config->entry_count; i++) { UINTN j, padding; - lines[i] = xnew(CHAR16, line_width + 1); + lines[i] = xnew(char16_t, line_width + 1); padding = (line_width - MIN(strlen16(config->entries[i]->title_show), line_width)) / 2; for (j = 0; j < padding; j++) @@ -698,8 +698,8 @@ static BOOLEAN menu_run( } lines[config->entry_count] = NULL; - clearline = xnew(CHAR16, x_max + 1); - separator = xnew(CHAR16, x_max + 1); + clearline = xnew(char16_t, x_max + 1); + separator = xnew(char16_t, x_max + 1); for (UINTN i = 0; i < x_max; i++) { clearline[i] = ' '; separator[i] = unicode_supported() ? L'─' : L'-'; @@ -723,18 +723,25 @@ static BOOLEAN menu_run( (i == idx_highlight) ? COLOR_HIGHLIGHT : COLOR_ENTRY, lines[i]); if (i == config->idx_default_efivar) - print_at(x_start, y_start + i - idx_first, + print_at(x_start, + y_start + i - idx_first, (i == idx_highlight) ? COLOR_HIGHLIGHT : COLOR_ENTRY, - (CHAR16*) (unicode_supported() ? L" ►" : L"=>")); + unicode_supported() ? L" ►" : L"=>"); } refresh = FALSE; } else if (highlight) { print_at(x_start, y_start + idx_highlight_prev - idx_first, COLOR_ENTRY, lines[idx_highlight_prev]); print_at(x_start, y_start + idx_highlight - idx_first, COLOR_HIGHLIGHT, lines[idx_highlight]); if (idx_highlight_prev == config->idx_default_efivar) - print_at(x_start , y_start + idx_highlight_prev - idx_first, COLOR_ENTRY, (CHAR16*) (unicode_supported() ? L" ►" : L"=>")); + print_at(x_start, + y_start + idx_highlight_prev - idx_first, + COLOR_ENTRY, + unicode_supported() ? L" ►" : L"=>"); if (idx_highlight == config->idx_default_efivar) - print_at(x_start, y_start + idx_highlight - idx_first, COLOR_HIGHLIGHT, (CHAR16*) (unicode_supported() ? L" ►" : L"=>")); + print_at(x_start, + y_start + idx_highlight - idx_first, + COLOR_HIGHLIGHT, + unicode_supported() ? L" ►" : L"=>"); highlight = FALSE; } @@ -1256,9 +1263,9 @@ static void config_defaults_load_from_file(Config *config, CHAR8 *content) { static void config_entry_parse_tries( ConfigEntry *entry, - const CHAR16 *path, - const CHAR16 *file, - const CHAR16 *suffix) { + const char16_t *path, + const char16_t *file, + const char16_t *suffix) { assert(entry); assert(path); @@ -1319,7 +1326,7 @@ static void config_entry_parse_tries( } static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) { - _cleanup_freepool_ CHAR16* old_path = NULL, *new_path = NULL; + _cleanup_free_ char16_t* old_path = NULL, *new_path = NULL; _cleanup_(file_closep) EFI_FILE *handle = NULL; _cleanup_freepool_ EFI_FILE_INFO *file_info = NULL; UINTN file_info_size; @@ -1371,10 +1378,10 @@ static void config_entry_add_type1( Config *config, EFI_HANDLE *device, EFI_FILE *root_dir, - const CHAR16 *path, - const CHAR16 *file, + const char16_t *path, + const char16_t *file, CHAR8 *content, - const CHAR16 *loaded_image_path) { + const char16_t *loaded_image_path) { _cleanup_(config_entry_freep) ConfigEntry *entry = NULL; CHAR8 *line; @@ -1467,13 +1474,11 @@ static void config_entry_add_type1( } if (streq8((char *) key, "options")) { - _cleanup_freepool_ CHAR16 *new = NULL; + _cleanup_free_ char16_t *new = NULL; new = xstra_to_str(value); if (entry->options) { - CHAR16 *s; - - s = xpool_print(L"%s %s", entry->options, new); + char16_t *s = xpool_print(L"%s %s", entry->options, new); free(entry->options); entry->options = s; } else @@ -1567,7 +1572,7 @@ static void config_load_entries( Config *config, EFI_HANDLE *device, EFI_FILE *root_dir, - const CHAR16 *loaded_image_path) { + const char16_t *loaded_image_path) { _cleanup_(file_closep) EFI_FILE *entries_dir = NULL; _cleanup_freepool_ EFI_FILE_INFO *f = NULL; @@ -1661,7 +1666,7 @@ static int config_entry_compare(const ConfigEntry *a, const ConfigEntry *b) { return CMP(a->tries_done, b->tries_done); } -static UINTN config_entry_find(Config *config, const CHAR16 *pattern) { +static UINTN config_entry_find(Config *config, const char16_t *pattern) { assert(config); /* We expect pattern and entry IDs to be already case folded. */ @@ -1761,7 +1766,7 @@ static void config_title_generate(Config *config) { if (!config->entries[i]->version) continue; - _cleanup_freepool_ CHAR16 *t = config->entries[i]->title_show; + _cleanup_free_ char16_t *t = config->entries[i]->title_show; config->entries[i]->title_show = xpool_print(L"%s (%s)", t, config->entries[i]->version); } @@ -1778,7 +1783,7 @@ static void config_title_generate(Config *config) { if (!config->entries[i]->machine_id) continue; - _cleanup_freepool_ CHAR16 *t = config->entries[i]->title_show; + _cleanup_free_ char16_t *t = config->entries[i]->title_show; config->entries[i]->title_show = xpool_print( L"%s (%.*s)", t, @@ -1794,12 +1799,12 @@ static void config_title_generate(Config *config) { if (unique[i]) continue; - _cleanup_freepool_ CHAR16 *t = config->entries[i]->title_show; + _cleanup_free_ char16_t *t = config->entries[i]->title_show; config->entries[i]->title_show = xpool_print(L"%s (%s)", t, config->entries[i]->id); } } -static BOOLEAN is_sd_boot(EFI_FILE *root_dir, const CHAR16 *loader_path) { +static BOOLEAN is_sd_boot(EFI_FILE *root_dir, const char16_t *loader_path) { EFI_STATUS err; const CHAR8 *sections[] = { (CHAR8 *)".sdmagic", @@ -1826,11 +1831,11 @@ static ConfigEntry *config_entry_add_loader_auto( Config *config, EFI_HANDLE *device, EFI_FILE *root_dir, - const CHAR16 *loaded_image_path, - const CHAR16 *id, - CHAR16 key, - const CHAR16 *title, - const CHAR16 *loader) { + const char16_t *loaded_image_path, + const char16_t *id, + char16_t key, + const char16_t *title, + const char16_t *loader) { assert(config); assert(device); @@ -1858,7 +1863,7 @@ static ConfigEntry *config_entry_add_loader_auto( /* check existence */ _cleanup_(file_closep) EFI_FILE *handle = NULL; - EFI_STATUS err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL); + EFI_STATUS err = root_dir->Open(root_dir, &handle, (char16_t *) loader, EFI_FILE_MODE_READ, 0ULL); if (err != EFI_SUCCESS) return NULL; @@ -1961,7 +1966,7 @@ static EFI_STATUS boot_windows_bitlocker(void) { for (UINTN i = 0; i < boot_order_size / sizeof(uint16_t); i++) { _cleanup_freepool_ CHAR8 *buf = NULL; - CHAR16 name[sizeof(L"Boot0000")]; + char16_t name[sizeof(L"Boot0000")]; UINTN buf_size; SPrint(name, sizeof(name), L"Boot%04x", (uint32_t) boot_order[i]); @@ -1972,10 +1977,10 @@ static EFI_STATUS boot_windows_bitlocker(void) { /* Boot#### are EFI_LOAD_OPTION. But we really are only interested * for the description, which is at this offset. */ UINTN offset = sizeof(uint32_t) + sizeof(uint16_t); - if (buf_size < offset + sizeof(CHAR16)) + if (buf_size < offset + sizeof(char16_t)) continue; - if (streq16((CHAR16 *) (buf + offset), L"Windows Boot Manager")) { + if (streq16((char16_t *) (buf + offset), L"Windows Boot Manager")) { err = efivar_set_raw( EFI_GLOBAL_GUID, L"BootNext", @@ -1995,7 +2000,7 @@ static EFI_STATUS boot_windows_bitlocker(void) { static void config_entry_add_windows(Config *config, EFI_HANDLE *device, EFI_FILE *root_dir) { #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) _cleanup_freepool_ CHAR8 *bcd = NULL; - CHAR16 *title = NULL; + char16_t *title = NULL; EFI_STATUS err; UINTN len; @@ -2053,9 +2058,9 @@ static void config_entry_add_unified( NULL, }; - _cleanup_freepool_ CHAR16 *os_pretty_name = NULL, *os_image_id = NULL, *os_name = NULL, *os_id = NULL, + _cleanup_free_ char16_t *os_pretty_name = NULL, *os_image_id = NULL, *os_name = NULL, *os_id = NULL, *os_image_version = NULL, *os_version = NULL, *os_version_id = NULL, *os_build_id = NULL; - const CHAR16 *good_name, *good_version, *good_sort_key; + const char16_t *good_name, *good_version, *good_sort_key; _cleanup_freepool_ CHAR8 *content = NULL; UINTN offs[_SECTION_MAX] = {}; UINTN szs[_SECTION_MAX] = {}; @@ -2207,7 +2212,7 @@ static void config_load_xbootldr( static EFI_STATUS initrd_prepare( EFI_FILE *root, const ConfigEntry *entry, - CHAR16 **ret_options, + char16_t **ret_options, void **ret_initrd, UINTN *ret_initrd_size) { @@ -2229,14 +2234,14 @@ static EFI_STATUS initrd_prepare( /* Add initrd= to options for older kernels that do not support LINUX_INITRD_MEDIA. Should be dropped * if linux_x86.c is dropped. */ - _cleanup_freepool_ CHAR16 *options = NULL; + _cleanup_free_ char16_t *options = NULL; EFI_STATUS err; UINTN size = 0; _cleanup_freepool_ uint8_t *initrd = NULL; STRV_FOREACH(i, entry->initrd) { - _cleanup_freepool_ CHAR16 *o = options; + _cleanup_free_ char16_t *o = options; if (o) options = xpool_print(L"%s initrd=%s", o, *i); else @@ -2267,7 +2272,7 @@ static EFI_STATUS initrd_prepare( } if (entry->options) { - _cleanup_freepool_ CHAR16 *o = options; + _cleanup_free_ char16_t *o = options; options = xpool_print(L"%s %s", o, entry->options); } @@ -2303,7 +2308,7 @@ static EFI_STATUS image_start( UINTN initrd_size = 0; _cleanup_freepool_ void *initrd = NULL; - _cleanup_freepool_ CHAR16 *options_initrd = NULL; + _cleanup_free_ char16_t *options_initrd = NULL; err = initrd_prepare(image_root, entry, &options_initrd, &initrd, &initrd_size); if (err != EFI_SUCCESS) return log_error_status_stall(err, L"Error preparing initrd: %r", err); @@ -2328,7 +2333,7 @@ static EFI_STATUS image_start( if (err != EFI_SUCCESS) return log_error_status_stall(err, L"Error getting LoadedImageProtocol handle: %r", err); - CHAR16 *options = options_initrd ?: entry->options; + char16_t *options = options_initrd ?: entry->options; if (options) { loaded_image->LoadOptions = options; loaded_image->LoadOptionsSize = strsize16(options); @@ -2426,7 +2431,7 @@ static void save_selected_entry(const Config *config, const ConfigEntry *entry) static void export_variables( EFI_LOADED_IMAGE *loaded_image, - const CHAR16 *loaded_image_path, + const char16_t *loaded_image_path, uint64_t init_usec) { static const uint64_t loader_features = @@ -2440,8 +2445,8 @@ static void export_variables( EFI_LOADER_FEATURE_LOAD_DRIVER | 0; - _cleanup_freepool_ CHAR16 *infostr = NULL, *typestr = NULL; - CHAR16 uuid[37]; + _cleanup_free_ char16_t *infostr = NULL, *typestr = NULL; + char16_t uuid[37]; assert(loaded_image); assert(loaded_image_path); @@ -2468,7 +2473,7 @@ static void export_variables( static void config_load_all_entries( Config *config, EFI_LOADED_IMAGE *loaded_image, - const CHAR16 *loaded_image_path, + const char16_t *loaded_image_path, EFI_FILE *root_dir) { assert(config); @@ -2525,7 +2530,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { EFI_LOADED_IMAGE *loaded_image; _cleanup_(file_closep) EFI_FILE *root_dir = NULL; _cleanup_(config_free) Config config = {}; - CHAR16 *loaded_image_path; + char16_t *loaded_image_path; EFI_STATUS err; uint64_t init_usec; BOOLEAN menu = FALSE; diff --git a/src/boot/efi/console.h b/src/boot/efi/console.h index ac8b2f8362..673a8ee79a 100644 --- a/src/boot/efi/console.h +++ b/src/boot/efi/console.h @@ -11,7 +11,7 @@ enum { }; #define KEYPRESS(keys, scan, uni) ((((uint64_t)keys) << 32) | (((uint64_t)scan) << 16) | (uni)) -#define KEYCHAR(k) ((CHAR16)(k)) +#define KEYCHAR(k) ((char16_t)(k)) #define CHAR_CTRL(c) ((c) - 'a' + 1) enum { diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c index 6769d4e2e7..1d122d961f 100644 --- a/src/boot/efi/cpio.c +++ b/src/boot/efi/cpio.c @@ -17,7 +17,7 @@ static CHAR8* write_cpio_word(CHAR8 *p, uint32_t v) { return p + 8; } -static CHAR8* mangle_filename(CHAR8 *p, const CHAR16 *f) { +static CHAR8* mangle_filename(CHAR8 *p, const char16_t *f) { CHAR8* w; assert(p); @@ -50,7 +50,7 @@ static CHAR8* pad4(CHAR8 *p, const CHAR8* start) { } static EFI_STATUS pack_cpio_one( - const CHAR16 *fname, + const char16_t *fname, const void *contents, UINTN contents_size, const CHAR8 *target_dir_prefix, @@ -306,22 +306,22 @@ static EFI_STATUS pack_cpio_trailer( EFI_STATUS pack_cpio( EFI_LOADED_IMAGE *loaded_image, - const CHAR16 *dropin_dir, - const CHAR16 *match_suffix, + const char16_t *dropin_dir, + const char16_t *match_suffix, const CHAR8 *target_dir_prefix, uint32_t dir_mode, uint32_t access_mode, const uint32_t tpm_pcr[], UINTN n_tpm_pcr, - const CHAR16 *tpm_description, + const char16_t *tpm_description, void **ret_buffer, UINTN *ret_buffer_size) { _cleanup_(file_closep) EFI_FILE *root = NULL, *extra_dir = NULL; UINTN dirent_size = 0, buffer_size = 0, n_items = 0, n_allocated = 0; - _cleanup_freepool_ CHAR16 *rel_dropin_dir = NULL; + _cleanup_free_ char16_t *rel_dropin_dir = NULL; _cleanup_freepool_ EFI_FILE_INFO *dirent = NULL; - _cleanup_(strv_freep) CHAR16 **items = NULL; + _cleanup_(strv_freep) char16_t **items = NULL; _cleanup_freepool_ void *buffer = NULL; uint32_t inode = 1; /* inode counter, so that each item gets a new inode */ EFI_STATUS err; @@ -372,7 +372,7 @@ EFI_STATUS pack_cpio( return log_error_status_stall(err, L"Failed to open extra directory of loaded image: %r", err); for (;;) { - _cleanup_freepool_ CHAR16 *d = NULL; + _cleanup_free_ char16_t *d = NULL; err = readdir_harder(extra_dir, &dirent, &dirent_size); if (err != EFI_SUCCESS) diff --git a/src/boot/efi/cpio.h b/src/boot/efi/cpio.h index e1600a3d19..4dd64a1801 100644 --- a/src/boot/efi/cpio.h +++ b/src/boot/efi/cpio.h @@ -2,16 +2,17 @@ #pragma once #include <efi.h> +#include <uchar.h> EFI_STATUS pack_cpio( EFI_LOADED_IMAGE *loaded_image, - const CHAR16 *dropin_dir, - const CHAR16 *match_suffix, + const char16_t *dropin_dir, + const char16_t *match_suffix, const CHAR8 *target_dir_prefix, uint32_t dir_mode, uint32_t access_mode, const uint32_t tpm_pcr[], UINTN n_tpm_pcr, - const CHAR16 *tpm_description, + const char16_t *tpm_description, void **ret_buffer, UINTN *ret_buffer_size); diff --git a/src/boot/efi/devicetree.c b/src/boot/efi/devicetree.c index a9b605ae1b..9640ed608f 100644 --- a/src/boot/efi/devicetree.c +++ b/src/boot/efi/devicetree.c @@ -71,7 +71,7 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) { return err; } -EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name) { +EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, char16_t *name) { _cleanup_(file_closep) EFI_FILE *handle = NULL; _cleanup_freepool_ EFI_FILE_INFO *info = NULL; UINTN len; diff --git a/src/boot/efi/devicetree.h b/src/boot/efi/devicetree.h index 71ce105028..d512cb5037 100644 --- a/src/boot/efi/devicetree.h +++ b/src/boot/efi/devicetree.h @@ -1,13 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include <efi.h> +#include <uchar.h> + struct devicetree_state { EFI_PHYSICAL_ADDRESS addr; UINTN pages; void *orig; }; -EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name); +EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, char16_t *name); EFI_STATUS devicetree_install_from_memory( struct devicetree_state *state, const VOID *dtb_buffer, UINTN dtb_length); void devicetree_cleanup(struct devicetree_state *state); diff --git a/src/boot/efi/disk.c b/src/boot/efi/disk.c index bf2984ed1f..5f889a365c 100644 --- a/src/boot/efi/disk.c +++ b/src/boot/efi/disk.c @@ -6,7 +6,7 @@ #include "disk.h" #include "util.h" -EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, CHAR16 uuid[static 37]) { +EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, char16_t uuid[static 37]) { EFI_STATUS err; EFI_DEVICE_PATH *dp; diff --git a/src/boot/efi/disk.h b/src/boot/efi/disk.h index 8e10bb7279..1a5a18733e 100644 --- a/src/boot/efi/disk.h +++ b/src/boot/efi/disk.h @@ -2,5 +2,6 @@ #pragma once #include <efi.h> +#include <uchar.h> -EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, CHAR16 uuid[static 37]); +EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, char16_t uuid[static 37]); diff --git a/src/boot/efi/drivers.c b/src/boot/efi/drivers.c index fcc7288533..30fb784ecc 100644 --- a/src/boot/efi/drivers.c +++ b/src/boot/efi/drivers.c @@ -9,11 +9,11 @@ static EFI_STATUS load_one_driver( EFI_HANDLE parent_image, EFI_LOADED_IMAGE *loaded_image, - const CHAR16 *fname) { + const char16_t *fname) { _cleanup_(unload_imagep) EFI_HANDLE image = NULL; _cleanup_freepool_ EFI_DEVICE_PATH *path = NULL; - _cleanup_freepool_ CHAR16 *spath = NULL; + _cleanup_free_ char16_t *spath = NULL; EFI_STATUS err; assert(parent_image); diff --git a/src/boot/efi/measure.c b/src/boot/efi/measure.c index 3ca1a835e7..a4490056d9 100644 --- a/src/boot/efi/measure.c +++ b/src/boot/efi/measure.c @@ -15,7 +15,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log( uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, UINTN buffer_size, - const CHAR16 *description) { + const char16_t *description) { _cleanup_freepool_ TCG_PCR_EVENT *tcg_event = NULL; EFI_PHYSICAL_ADDRESS event_log_last; @@ -49,7 +49,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log( uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, uint64_t buffer_size, - const CHAR16 *description) { + const char16_t *description) { _cleanup_freepool_ EFI_TCG2_EVENT *tcg_event = NULL; UINTN desc_len; @@ -141,7 +141,7 @@ BOOLEAN tpm_present(void) { return tcg2_interface_check() || tcg1_interface_check(); } -EFI_STATUS tpm_log_event(uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, UINTN buffer_size, const CHAR16 *description) { +EFI_STATUS tpm_log_event(uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, UINTN buffer_size, const char16_t *description) { EFI_TCG *tpm1; EFI_TCG2 *tpm2; @@ -163,7 +163,7 @@ EFI_STATUS tpm_log_event(uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, UINTN b return EFI_SUCCESS; } -EFI_STATUS tpm_log_load_options(const CHAR16 *load_options) { +EFI_STATUS tpm_log_load_options(const char16_t *load_options) { EFI_STATUS err; /* Measures a load options string into the TPM2, i.e. the kernel command line */ diff --git a/src/boot/efi/measure.h b/src/boot/efi/measure.h index 060b8eded7..5a66cd7a4d 100644 --- a/src/boot/efi/measure.h +++ b/src/boot/efi/measure.h @@ -2,6 +2,7 @@ #pragma once #include <efi.h> +#include <uchar.h> /* This TPM PCR is where we extend the kernel command line and any passed credentials here. */ #define TPM_PCR_INDEX_KERNEL_PARAMETERS 12U @@ -20,8 +21,8 @@ #if ENABLE_TPM BOOLEAN tpm_present(void); -EFI_STATUS tpm_log_event(uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, UINTN buffer_size, const CHAR16 *description); -EFI_STATUS tpm_log_load_options(const CHAR16 *cmdline); +EFI_STATUS tpm_log_event(uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, UINTN buffer_size, const char16_t *description); +EFI_STATUS tpm_log_load_options(const char16_t *cmdline); #else @@ -29,11 +30,11 @@ static inline BOOLEAN tpm_present(void) { return FALSE; } -static inline EFI_STATUS tpm_log_event(uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, UINTN buffer_size, const CHAR16 *description) { +static inline EFI_STATUS tpm_log_event(uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, UINTN buffer_size, const char16_t *description) { return EFI_SUCCESS; } -static inline EFI_STATUS tpm_log_load_options(const CHAR16 *cmdline) { +static inline EFI_STATUS tpm_log_load_options(const char16_t *cmdline) { return EFI_SUCCESS; } diff --git a/src/boot/efi/pe.c b/src/boot/efi/pe.c index 754176c84b..32d0c66503 100644 --- a/src/boot/efi/pe.c +++ b/src/boot/efi/pe.c @@ -278,7 +278,7 @@ EFI_STATUS pe_memory_locate_sections( EFI_STATUS pe_file_locate_sections( EFI_FILE *dir, - const CHAR16 *path, + const char16_t *path, const CHAR8 **sections, UINTN *offsets, UINTN *sizes) { @@ -295,7 +295,7 @@ EFI_STATUS pe_file_locate_sections( assert(offsets); assert(sizes); - err = dir->Open(dir, &handle, (CHAR16*)path, EFI_FILE_MODE_READ, 0ULL); + err = dir->Open(dir, &handle, (char16_t *) path, EFI_FILE_MODE_READ, 0ULL); if (err != EFI_SUCCESS) return err; diff --git a/src/boot/efi/pe.h b/src/boot/efi/pe.h index 54bc2428ff..c057cf6497 100644 --- a/src/boot/efi/pe.h +++ b/src/boot/efi/pe.h @@ -2,6 +2,7 @@ #pragma once #include <efidef.h> +#include <uchar.h> EFI_STATUS pe_memory_locate_sections( const CHAR8 *base, @@ -11,7 +12,7 @@ EFI_STATUS pe_memory_locate_sections( EFI_STATUS pe_file_locate_sections( EFI_FILE *dir, - const CHAR16 *path, + const char16_t *path, const CHAR8 **sections, UINTN *offsets, UINTN *sizes); diff --git a/src/boot/efi/random-seed.c b/src/boot/efi/random-seed.c index c4c9fa45a7..f332f4582b 100644 --- a/src/boot/efi/random-seed.c +++ b/src/boot/efi/random-seed.c @@ -256,7 +256,12 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) { if (mode != RANDOM_SEED_ALWAYS && err != EFI_SUCCESS) return err; - err = root_dir->Open(root_dir, &handle, (CHAR16*) L"\\loader\\random-seed", EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0ULL); + err = root_dir->Open( + root_dir, + &handle, + (char16_t *) L"\\loader\\random-seed", + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, + 0); if (err != EFI_SUCCESS) { if (err != EFI_NOT_FOUND && err != EFI_WRITE_PROTECTED) log_error_stall(L"Failed to open random seed file: %r", err); diff --git a/src/boot/efi/random-seed.h b/src/boot/efi/random-seed.h index e0e055ab03..6aa1cc5288 100644 --- a/src/boot/efi/random-seed.h +++ b/src/boot/efi/random-seed.h @@ -3,6 +3,7 @@ #include <efi.h> #include <errno.h> +#include <uchar.h> typedef enum RandomSeedMode { RANDOM_SEED_OFF, @@ -12,7 +13,7 @@ typedef enum RandomSeedMode { _RANDOM_SEED_MODE_INVALID = -EINVAL, } RandomSeedMode; -static const CHAR16 * const random_seed_modes_table[_RANDOM_SEED_MODE_MAX] = { +static const char16_t * const random_seed_modes_table[_RANDOM_SEED_MODE_MAX] = { [RANDOM_SEED_OFF] = L"off", [RANDOM_SEED_WITH_SYSTEM_TOKEN] = L"with-system-token", [RANDOM_SEED_ALWAYS] = L"always", diff --git a/src/boot/efi/shim.c b/src/boot/efi/shim.c index 3d5690f670..233c87246e 100644 --- a/src/boot/efi/shim.c +++ b/src/boot/efi/shim.c @@ -102,7 +102,7 @@ static EFIAPI EFI_STATUS security2_policy_authentication (const EFI_SECURITY2_PR static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROTOCOL *this, uint32_t authentication_status, const EFI_DEVICE_PATH_PROTOCOL *device_path_const) { EFI_STATUS err; - _cleanup_freepool_ CHAR16 *dev_path_str = NULL; + _cleanup_free_ char16_t *dev_path_str = NULL; EFI_HANDLE h; _cleanup_freepool_ CHAR8 *file_buffer = NULL; UINTN file_size; diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index 29ccfa3b4f..ec6b575289 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -102,7 +102,7 @@ static EFI_STATUS combine_initrd( } static void export_variables(EFI_LOADED_IMAGE *loaded_image) { - CHAR16 uuid[37]; + char16_t uuid[37]; assert(loaded_image); @@ -119,7 +119,7 @@ static void export_variables(EFI_LOADED_IMAGE *loaded_image) { * is non-NULL explicitly.) */ if (efivar_get_raw(LOADER_GUID, L"LoaderImageIdentifier", NULL, NULL) != EFI_SUCCESS && loaded_image->FilePath) { - _cleanup_freepool_ CHAR16 *s = NULL; + _cleanup_free_ char16_t *s = NULL; s = DevicePathToStr(loaded_image->FilePath); if (s) @@ -130,14 +130,14 @@ static void export_variables(EFI_LOADED_IMAGE *loaded_image) { /* if LoaderFirmwareInfo is not set, let's set it */ if (efivar_get_raw(LOADER_GUID, L"LoaderFirmwareInfo", NULL, NULL) != EFI_SUCCESS) { - _cleanup_freepool_ CHAR16 *s = NULL; + _cleanup_free_ char16_t *s = NULL; s = xpool_print(L"%s %u.%02u", ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff); efivar_set(LOADER_GUID, L"LoaderFirmwareInfo", s, 0); } /* ditto for LoaderFirmwareType */ if (efivar_get_raw(LOADER_GUID, L"LoaderFirmwareType", NULL, NULL) != EFI_SUCCESS) { - _cleanup_freepool_ CHAR16 *s = NULL; + _cleanup_free_ char16_t *s = NULL; s = xpool_print(L"UEFI %u.%02u", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff); efivar_set(LOADER_GUID, L"LoaderFirmwareType", s, 0); } @@ -212,12 +212,12 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { /* if we are not in secure boot mode, or none was provided, accept a custom command line and replace the built-in one */ if ((!secure_boot_enabled() || cmdline_len == 0) && loaded_image->LoadOptionsSize > 0 && - *(CHAR16 *) loaded_image->LoadOptions > 0x1F) { - cmdline_len = (loaded_image->LoadOptionsSize / sizeof(CHAR16)) * sizeof(CHAR8); + *(char16_t *) loaded_image->LoadOptions > 0x1F) { + cmdline_len = (loaded_image->LoadOptionsSize / sizeof(char16_t)) * sizeof(CHAR8); cmdline = cmdline_owned = xmalloc(cmdline_len); for (UINTN i = 0; i < cmdline_len; i++) - cmdline[i] = ((CHAR16 *) loaded_image->LoadOptions)[i]; + cmdline[i] = ((char16_t *) loaded_image->LoadOptions)[i]; /* Let's measure the passed kernel command line into the TPM. Note that this possibly * duplicates what we already did in the boot menu, if that was already used. However, since diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 9e38dfbc48..9d74500ec3 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -27,24 +27,24 @@ EFI_STATUS parse_boolean(const CHAR8 *v, BOOLEAN *b) { return EFI_INVALID_PARAMETER; } -EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, const CHAR16 *name, const void *buf, UINTN size, uint32_t flags) { +EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, const char16_t *name, const void *buf, UINTN size, uint32_t flags) { assert(vendor); assert(name); assert(buf || size == 0); flags |= EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; - return RT->SetVariable((CHAR16 *) name, (EFI_GUID *) vendor, flags, size, (void *) buf); + return RT->SetVariable((char16_t *) name, (EFI_GUID *) vendor, flags, size, (void *) buf); } -EFI_STATUS efivar_set(const EFI_GUID *vendor, const CHAR16 *name, const CHAR16 *value, uint32_t flags) { +EFI_STATUS efivar_set(const EFI_GUID *vendor, const char16_t *name, const char16_t *value, uint32_t flags) { assert(vendor); assert(name); return efivar_set_raw(vendor, name, value, value ? strsize16(value) : 0, flags); } -EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UINTN i, uint32_t flags) { - CHAR16 str[32]; +EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const char16_t *name, UINTN i, uint32_t flags) { + char16_t str[32]; assert(vendor); assert(name); @@ -56,7 +56,7 @@ EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UI return efivar_set(vendor, name, str, flags); } -EFI_STATUS efivar_set_uint32_le(const EFI_GUID *vendor, const CHAR16 *name, uint32_t value, uint32_t flags) { +EFI_STATUS efivar_set_uint32_le(const EFI_GUID *vendor, const char16_t *name, uint32_t value, uint32_t flags) { uint8_t buf[4]; assert(vendor); @@ -70,7 +70,7 @@ EFI_STATUS efivar_set_uint32_le(const EFI_GUID *vendor, const CHAR16 *name, uint return efivar_set_raw(vendor, name, buf, sizeof(buf), flags); } -EFI_STATUS efivar_set_uint64_le(const EFI_GUID *vendor, const CHAR16 *name, uint64_t value, uint32_t flags) { +EFI_STATUS efivar_set_uint64_le(const EFI_GUID *vendor, const char16_t *name, uint64_t value, uint32_t flags) { uint8_t buf[8]; assert(vendor); @@ -88,10 +88,10 @@ EFI_STATUS efivar_set_uint64_le(const EFI_GUID *vendor, const CHAR16 *name, uint return efivar_set_raw(vendor, name, buf, sizeof(buf), flags); } -EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value) { - _cleanup_freepool_ CHAR16 *buf = NULL; +EFI_STATUS efivar_get(const EFI_GUID *vendor, const char16_t *name, char16_t **value) { + _cleanup_free_ char16_t *buf = NULL; EFI_STATUS err; - CHAR16 *val; + char16_t *val; UINTN size; assert(vendor); @@ -102,30 +102,30 @@ EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value return err; /* Make sure there are no incomplete characters in the buffer */ - if ((size % sizeof(CHAR16)) != 0) + if ((size % sizeof(char16_t)) != 0) return EFI_INVALID_PARAMETER; if (!value) return EFI_SUCCESS; /* Return buffer directly if it happens to be NUL terminated already */ - if (size >= sizeof(CHAR16) && buf[size / sizeof(CHAR16) - 1] == 0) { + if (size >= sizeof(char16_t) && buf[size / sizeof(char16_t) - 1] == 0) { *value = TAKE_PTR(buf); return EFI_SUCCESS; } /* Make sure a terminating NUL is available at the end */ - val = xmalloc(size + sizeof(CHAR16)); + val = xmalloc(size + sizeof(char16_t)); memcpy(val, buf, size); - val[size / sizeof(CHAR16) - 1] = 0; /* NUL terminate */ + val[size / sizeof(char16_t) - 1] = 0; /* NUL terminate */ *value = val; return EFI_SUCCESS; } -EFI_STATUS efivar_get_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UINTN *i) { - _cleanup_freepool_ CHAR16 *val = NULL; +EFI_STATUS efivar_get_uint_string(const EFI_GUID *vendor, const char16_t *name, UINTN *i) { + _cleanup_free_ char16_t *val = NULL; EFI_STATUS err; uint64_t u; @@ -144,7 +144,7 @@ EFI_STATUS efivar_get_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UI return EFI_SUCCESS; } -EFI_STATUS efivar_get_uint32_le(const EFI_GUID *vendor, const CHAR16 *name, uint32_t *ret) { +EFI_STATUS efivar_get_uint32_le(const EFI_GUID *vendor, const char16_t *name, uint32_t *ret) { _cleanup_freepool_ CHAR8 *buf = NULL; UINTN size; EFI_STATUS err; @@ -164,7 +164,7 @@ EFI_STATUS efivar_get_uint32_le(const EFI_GUID *vendor, const CHAR16 *name, uint return err; } -EFI_STATUS efivar_get_uint64_le(const EFI_GUID *vendor, const CHAR16 *name, uint64_t *ret) { +EFI_STATUS efivar_get_uint64_le(const EFI_GUID *vendor, const char16_t *name, uint64_t *ret) { _cleanup_freepool_ CHAR8 *buf = NULL; UINTN size; EFI_STATUS err; @@ -185,7 +185,7 @@ EFI_STATUS efivar_get_uint64_le(const EFI_GUID *vendor, const CHAR16 *name, uint return err; } -EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const CHAR16 *name, CHAR8 **buffer, UINTN *size) { +EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const char16_t *name, CHAR8 **buffer, UINTN *size) { _cleanup_freepool_ CHAR8 *buf = NULL; UINTN l; EFI_STATUS err; @@ -193,10 +193,10 @@ EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const CHAR16 *name, CHAR8 **bu assert(vendor); assert(name); - l = sizeof(CHAR16 *) * EFI_MAXIMUM_VARIABLE_SIZE; + l = sizeof(char16_t *) * EFI_MAXIMUM_VARIABLE_SIZE; buf = xmalloc(l); - err = RT->GetVariable((CHAR16 *) name, (EFI_GUID *) vendor, NULL, &l, buf); + err = RT->GetVariable((char16_t *) name, (EFI_GUID *) vendor, NULL, &l, buf); if (err == EFI_SUCCESS) { if (buffer) @@ -209,7 +209,7 @@ EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const CHAR16 *name, CHAR8 **bu return err; } -EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const CHAR16 *name, BOOLEAN *ret) { +EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const char16_t *name, BOOLEAN *ret) { _cleanup_freepool_ CHAR8 *b = NULL; UINTN size; EFI_STATUS err; @@ -225,8 +225,8 @@ EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const CHAR16 *name, BOO return err; } -void efivar_set_time_usec(const EFI_GUID *vendor, const CHAR16 *name, uint64_t usec) { - CHAR16 str[32]; +void efivar_set_time_usec(const EFI_GUID *vendor, const char16_t *name, uint64_t usec) { + char16_t str[32]; assert(vendor); assert(name); @@ -241,8 +241,8 @@ void efivar_set_time_usec(const EFI_GUID *vendor, const CHAR16 *name, uint64_t u efivar_set(vendor, name, str, 0); } -static INTN utf8_to_16(const CHAR8 *stra, CHAR16 *c) { - CHAR16 unichar; +static INTN utf8_to_16(const CHAR8 *stra, char16_t *c) { + char16_t unichar; UINTN len; assert(stra); @@ -295,16 +295,16 @@ static INTN utf8_to_16(const CHAR8 *stra, CHAR16 *c) { return len; } -CHAR16 *xstra_to_str(const CHAR8 *stra) { +char16_t *xstra_to_str(const CHAR8 *stra) { UINTN strlen; UINTN len; UINTN i; - CHAR16 *str; + char16_t *str; assert(stra); len = strlen8((const char *) stra); - str = xnew(CHAR16, len + 1); + str = xnew(char16_t, len + 1); strlen = 0; i = 0; @@ -325,8 +325,8 @@ CHAR16 *xstra_to_str(const CHAR8 *stra) { return str; } -CHAR16 *xstra_to_path(const CHAR8 *stra) { - CHAR16 *str; +char16_t *xstra_to_path(const CHAR8 *stra) { + char16_t *str; UINTN strlen; UINTN len; UINTN i; @@ -334,7 +334,7 @@ CHAR16 *xstra_to_path(const CHAR8 *stra) { assert(stra); len = strlen8((const char *) stra); - str = xnew(CHAR16, len + 2); + str = xnew(char16_t, len + 2); str[0] = '\\'; strlen = 1; @@ -364,7 +364,7 @@ CHAR16 *xstra_to_path(const CHAR8 *stra) { return str; } -EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) { +EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) { _cleanup_(file_closep) EFI_FILE *handle = NULL; _cleanup_freepool_ CHAR8 *buf = NULL; EFI_STATUS err; @@ -373,7 +373,7 @@ EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, C assert(name); assert(ret); - err = dir->Open(dir, &handle, (CHAR16*) name, EFI_FILE_MODE_READ, 0ULL); + err = dir->Open(dir, &handle, (char16_t*) name, EFI_FILE_MODE_READ, 0ULL); if (err != EFI_SUCCESS) return err; @@ -393,8 +393,8 @@ EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, C return err; } - /* Allocate some extra bytes to guarantee the result is NUL-terminated for CHAR8 and CHAR16 strings. */ - UINTN extra = size % sizeof(CHAR16) + sizeof(CHAR16); + /* Allocate some extra bytes to guarantee the result is NUL-terminated for CHAR8 and char16_t strings. */ + UINTN extra = size % sizeof(char16_t) + sizeof(char16_t); buf = xmalloc(size + extra); err = handle->Read(handle, &size, buf); @@ -411,7 +411,7 @@ EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, C return err; } -void log_error_stall(const CHAR16 *fmt, ...) { +void log_error_stall(const char16_t *fmt, ...) { va_list args; assert(fmt); @@ -439,11 +439,11 @@ EFI_STATUS log_oom(void) { return EFI_OUT_OF_RESOURCES; } -void print_at(UINTN x, UINTN y, UINTN attr, const CHAR16 *str) { +void print_at(UINTN x, UINTN y, UINTN attr, const char16_t *str) { assert(str); ST->ConOut->SetCursorPosition(ST->ConOut, x, y); ST->ConOut->SetAttribute(ST->ConOut, attr); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)str); + ST->ConOut->OutputString(ST->ConOut, (char16_t *) str); } void clear_screen(UINTN attr) { @@ -531,7 +531,7 @@ EFI_STATUS readdir_harder( * the buffer was too small. Therefore, start with a buffer that should handle FAT32 max * file name length. * As a side effect, most readdir_harder() calls will now be slightly faster. */ - sz = sizeof(EFI_FILE_INFO) + 256 * sizeof(CHAR16); + sz = sizeof(EFI_FILE_INFO) + 256 * sizeof(char16_t); *buffer = xmalloc(sz); *buffer_size = sz; } else @@ -557,7 +557,7 @@ EFI_STATUS readdir_harder( return EFI_SUCCESS; } -BOOLEAN is_ascii(const CHAR16 *f) { +BOOLEAN is_ascii(const char16_t *f) { if (!f) return FALSE; @@ -568,11 +568,11 @@ BOOLEAN is_ascii(const CHAR16 *f) { return TRUE; } -CHAR16 **strv_free(CHAR16 **v) { +char16_t **strv_free(char16_t **v) { if (!v) return NULL; - for (CHAR16 **i = v; *i; i++) + for (char16_t **i = v; *i; i++) free(*i); free(v); @@ -581,7 +581,7 @@ CHAR16 **strv_free(CHAR16 **v) { EFI_STATUS open_directory( EFI_FILE *root, - const CHAR16 *path, + const char16_t *path, EFI_FILE **ret) { _cleanup_(file_closep) EFI_FILE *dir = NULL; @@ -592,7 +592,7 @@ EFI_STATUS open_directory( /* Opens a file, and then verifies it is actually a directory */ - err = root->Open(root, &dir, (CHAR16*) path, EFI_FILE_MODE_READ, 0ULL); + err = root->Open(root, &dir, (char16_t *) path, EFI_FILE_MODE_READ, 0); if (err != EFI_SUCCESS) return err; diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 8196db78e8..db48f7add5 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -66,29 +66,29 @@ static inline void *xrealloc(void *p, size_t old_size, size_t new_size) { return r; } -#define xpool_print(fmt, ...) ((CHAR16 *) ASSERT_SE_PTR(PoolPrint((fmt), ##__VA_ARGS__))) +#define xpool_print(fmt, ...) ((char16_t *) ASSERT_SE_PTR(PoolPrint((fmt), ##__VA_ARGS__))) #define xnew(type, n) ((type *) xmalloc_multiply(sizeof(type), (n))) EFI_STATUS parse_boolean(const CHAR8 *v, BOOLEAN *b); -EFI_STATUS efivar_set(const EFI_GUID *vendor, const CHAR16 *name, const CHAR16 *value, uint32_t flags); -EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, const CHAR16 *name, const void *buf, UINTN size, uint32_t flags); -EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UINTN i, uint32_t flags); -EFI_STATUS efivar_set_uint32_le(const EFI_GUID *vendor, const CHAR16 *NAME, uint32_t value, uint32_t flags); -EFI_STATUS efivar_set_uint64_le(const EFI_GUID *vendor, const CHAR16 *name, uint64_t value, uint32_t flags); -void efivar_set_time_usec(const EFI_GUID *vendor, const CHAR16 *name, uint64_t usec); +EFI_STATUS efivar_set(const EFI_GUID *vendor, const char16_t *name, const char16_t *value, uint32_t flags); +EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, const char16_t *name, const void *buf, UINTN size, uint32_t flags); +EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const char16_t *name, UINTN i, uint32_t flags); +EFI_STATUS efivar_set_uint32_le(const EFI_GUID *vendor, const char16_t *NAME, uint32_t value, uint32_t flags); +EFI_STATUS efivar_set_uint64_le(const EFI_GUID *vendor, const char16_t *name, uint64_t value, uint32_t flags); +void efivar_set_time_usec(const EFI_GUID *vendor, const char16_t *name, uint64_t usec); -EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value); -EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const CHAR16 *name, CHAR8 **buffer, UINTN *size); -EFI_STATUS efivar_get_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UINTN *i); -EFI_STATUS efivar_get_uint32_le(const EFI_GUID *vendor, const CHAR16 *name, uint32_t *ret); -EFI_STATUS efivar_get_uint64_le(const EFI_GUID *vendor, const CHAR16 *name, uint64_t *ret); -EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const CHAR16 *name, BOOLEAN *ret); +EFI_STATUS efivar_get(const EFI_GUID *vendor, const char16_t *name, char16_t **value); +EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const char16_t *name, CHAR8 **buffer, UINTN *size); +EFI_STATUS efivar_get_uint_string(const EFI_GUID *vendor, const char16_t *name, UINTN *i); +EFI_STATUS efivar_get_uint32_le(const EFI_GUID *vendor, const char16_t *name, uint32_t *ret); +EFI_STATUS efivar_get_uint64_le(const EFI_GUID *vendor, const char16_t *name, uint64_t *ret); +EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const char16_t *name, BOOLEAN *ret); -CHAR16 *xstra_to_path(const CHAR8 *stra); -CHAR16 *xstra_to_str(const CHAR8 *stra); +char16_t *xstra_to_path(const CHAR8 *stra); +char16_t *xstra_to_str(const CHAR8 *stra); -EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size); +EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size); static inline void file_closep(EFI_FILE **handle) { if (!*handle) @@ -111,7 +111,7 @@ static inline void unload_imagep(EFI_HANDLE *image) { &(const EFI_GUID) { 0x4a67b082, 0x0a4c, 0x41cf, { 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f } } #define EFI_GLOBAL_GUID &(const EFI_GUID) EFI_GLOBAL_VARIABLE -void log_error_stall(const CHAR16 *fmt, ...); +void log_error_stall(const char16_t *fmt, ...); EFI_STATUS log_oom(void); /* This works just like log_error_errno() from userspace, but requires you @@ -122,7 +122,7 @@ EFI_STATUS log_oom(void); err; \ }) -void print_at(UINTN x, UINTN y, UINTN attr, const CHAR16 *str); +void print_at(UINTN x, UINTN y, UINTN attr, const char16_t *str); void clear_screen(UINTN attr); typedef int (*compare_pointer_func_t)(const void *a, const void *b); @@ -132,15 +132,15 @@ EFI_STATUS get_file_info_harder(EFI_FILE *handle, EFI_FILE_INFO **ret, UINTN *re EFI_STATUS readdir_harder(EFI_FILE *handle, EFI_FILE_INFO **buffer, UINTN *buffer_size); -BOOLEAN is_ascii(const CHAR16 *f); +BOOLEAN is_ascii(const char16_t *f); -CHAR16 **strv_free(CHAR16 **l); +char16_t **strv_free(char16_t **l); -static inline void strv_freep(CHAR16 ***p) { +static inline void strv_freep(char16_t ***p) { strv_free(*p); } -EFI_STATUS open_directory(EFI_FILE *root_dir, const CHAR16 *path, EFI_FILE **ret); +EFI_STATUS open_directory(EFI_FILE *root_dir, const char16_t *path, EFI_FILE **ret); /* Conversion between EFI_PHYSICAL_ADDRESS and pointers is not obvious. The former is always 64bit, even on * 32bit archs. And gcc complains if we cast a pointer to an integer of a different size. Hence let's do the |