diff --git a/src/boot/efi/bcd.c b/src/boot/efi/bcd.c index 93783cc51b2..7200012c0a7 100644 --- a/src/boot/efi/bcd.c +++ b/src/boot/efi/bcd.c @@ -1,18 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#ifdef SD_BOOT -# include -# include "macro-fundamental.h" -# include "util.h" -# define TEST_STATIC -#else -/* Provide our own "EFI API" if we are running as a unit test. */ -# include "efi-string.h" -# include "string-util-fundamental.h" +#include -# define UINTN size_t -# define TEST_STATIC static -#endif +#include "bcd.h" +#include "efi-string.h" enum { SIG_BASE_BLOCK = 1718052210, /* regf */ @@ -177,7 +168,7 @@ static const KeyValue *get_key_value(const uint8_t *bcd, uint32_t bcd_len, const return NULL; if (BAD_OFFSET(key->key_values_offset, sizeof(uint32_t) * (uint64_t) key->n_key_values, bcd_len) || - (UINTN)(bcd + key->key_values_offset) % sizeof(uint32_t) != 0) + (uintptr_t) (bcd + key->key_values_offset) % alignof(uint32_t) != 0) return NULL; const uint32_t *key_value_list = (const uint32_t *) (bcd + key->key_values_offset); @@ -227,7 +218,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_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len) { +char16_t *get_bcd_title(uint8_t *bcd, size_t bcd_len) { assert(bcd); if (HIVE_CELL_OFFSET >= bcd_len) @@ -263,13 +254,13 @@ TEST_STATIC char16_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len) { char order_guid[sizeof("{00000000-0000-0000-0000-000000000000}\0")]; if (displayorder_value->data_type != REG_MULTI_SZ || displayorder_value->data_size != sizeof(char16_t[sizeof(order_guid)]) || - (UINTN)(bcd + displayorder_value->data_offset) % sizeof(char16_t) != 0) + (uintptr_t) (bcd + displayorder_value->data_offset) % alignof(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_t *order_guid_utf16 = (char16_t *) (bcd + displayorder_value->data_offset); - for (UINTN i = 0; i < sizeof(order_guid) - 2; i++) { + for (size_t i = 0; i < sizeof(order_guid) - 2; i++) { char16_t c = order_guid_utf16[i]; switch (c) { case '-': @@ -305,7 +296,7 @@ TEST_STATIC char16_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len) { if (description_value->data_type != REG_SZ || description_value->data_size < sizeof(char16_t) || description_value->data_size % sizeof(char16_t) != 0 || - (UINTN)(bcd + description_value->data_offset) % sizeof(char16_t)) + (uintptr_t) (bcd + description_value->data_offset) % alignof(char16_t)) return NULL; /* The data should already be NUL-terminated. */ diff --git a/src/boot/efi/bcd.h b/src/boot/efi/bcd.h index dd666e09e7b..c27af55c1e3 100644 --- a/src/boot/efi/bcd.h +++ b/src/boot/efi/bcd.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include #include -char16_t *get_bcd_title(uint8_t *bcd, UINTN bcd_len); +char16_t *get_bcd_title(uint8_t *bcd, size_t bcd_len); diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index c5a48a270d5..ece1c11cd5e 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -429,7 +429,7 @@ static char16_t *update_timeout_efivar(uint32_t *t, bool inc) { } static bool unicode_supported(void) { - static INTN cache = -1; + static int cache = -1; if (cache < 0) /* Basic unicode box drawing support is mandated by the spec, but it does @@ -1328,7 +1328,7 @@ static void config_entry_parse_tries( static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) { _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; + _cleanup_free_ EFI_FILE_INFO *file_info = NULL; UINTN file_info_size; EFI_STATUS err; @@ -1575,7 +1575,7 @@ static void config_load_entries( const char16_t *loaded_image_path) { _cleanup_(file_closep) EFI_FILE *entries_dir = NULL; - _cleanup_freepool_ EFI_FILE_INFO *f = NULL; + _cleanup_free_ EFI_FILE_INFO *f = NULL; UINTN f_size = 0; EFI_STATUS err; @@ -1886,7 +1886,7 @@ static ConfigEntry *config_entry_add_loader_auto( static void config_entry_add_osx(Config *config) { EFI_STATUS err; UINTN n_handles = 0; - _cleanup_freepool_ EFI_HANDLE *handles = NULL; + _cleanup_free_ EFI_HANDLE *handles = NULL; assert(config); @@ -1917,7 +1917,7 @@ static void config_entry_add_osx(Config *config) { } static EFI_STATUS boot_windows_bitlocker(void) { - _cleanup_freepool_ EFI_HANDLE *handles = NULL; + _cleanup_free_ EFI_HANDLE *handles = NULL; UINTN n_handles; EFI_STATUS err; @@ -1955,7 +1955,7 @@ static EFI_STATUS boot_windows_bitlocker(void) { if (!found) return EFI_NOT_FOUND; - _cleanup_freepool_ uint16_t *boot_order = NULL; + _cleanup_free_ uint16_t *boot_order = NULL; UINTN boot_order_size; /* There can be gaps in Boot#### entries. Instead of iterating over the full @@ -2031,7 +2031,7 @@ static void config_entry_add_unified( EFI_FILE *root_dir) { _cleanup_(file_closep) EFI_FILE *linux_dir = NULL; - _cleanup_freepool_ EFI_FILE_INFO *f = NULL; + _cleanup_free_ EFI_FILE_INFO *f = NULL; UINTN f_size = 0; EFI_STATUS err; @@ -2238,7 +2238,7 @@ static EFI_STATUS initrd_prepare( EFI_STATUS err; UINTN size = 0; - _cleanup_freepool_ uint8_t *initrd = NULL; + _cleanup_free_ uint8_t *initrd = NULL; STRV_FOREACH(i, entry->initrd) { _cleanup_free_ char16_t *o = options; @@ -2252,7 +2252,7 @@ static EFI_STATUS initrd_prepare( if (err != EFI_SUCCESS) return err; - _cleanup_freepool_ EFI_FILE_INFO *info = NULL; + _cleanup_free_ EFI_FILE_INFO *info = NULL; err = get_file_info_harder(handle, &info, NULL); if (err != EFI_SUCCESS) return err; @@ -2288,7 +2288,7 @@ static EFI_STATUS image_start( _cleanup_(devicetree_cleanup) struct devicetree_state dtstate = {}; _cleanup_(unload_imagep) EFI_HANDLE image = NULL; - _cleanup_freepool_ EFI_DEVICE_PATH *path = NULL; + _cleanup_free_ EFI_DEVICE_PATH *path = NULL; EFI_STATUS err; assert(entry); @@ -2307,7 +2307,7 @@ static EFI_STATUS image_start( return log_error_status_stall(err, L"Error making file device path: %r", err); UINTN initrd_size = 0; - _cleanup_freepool_ void *initrd = NULL; + _cleanup_free_ void *initrd = NULL; _cleanup_free_ char16_t *options_initrd = NULL; err = initrd_prepare(image_root, entry, &options_initrd, &initrd, &initrd_size); if (err != EFI_SUCCESS) diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c index ceeb07009d3..ad469af034d 100644 --- a/src/boot/efi/cpio.c +++ b/src/boot/efi/cpio.c @@ -320,9 +320,9 @@ EFI_STATUS pack_cpio( _cleanup_(file_closep) EFI_FILE *root = NULL, *extra_dir = NULL; UINTN dirent_size = 0, buffer_size = 0, n_items = 0, n_allocated = 0; _cleanup_free_ char16_t *rel_dropin_dir = NULL; - _cleanup_freepool_ EFI_FILE_INFO *dirent = NULL; + _cleanup_free_ EFI_FILE_INFO *dirent = NULL; _cleanup_(strv_freep) char16_t **items = NULL; - _cleanup_freepool_ void *buffer = NULL; + _cleanup_free_ void *buffer = NULL; uint32_t inode = 1; /* inode counter, so that each item gets a new inode */ EFI_STATUS err; diff --git a/src/boot/efi/devicetree.c b/src/boot/efi/devicetree.c index 9640ed608fa..03126706135 100644 --- a/src/boot/efi/devicetree.c +++ b/src/boot/efi/devicetree.c @@ -73,7 +73,7 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) { 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; + _cleanup_free_ EFI_FILE_INFO *info = NULL; UINTN len; EFI_STATUS err; diff --git a/src/boot/efi/drivers.c b/src/boot/efi/drivers.c index 751a09a462a..41f0326af1c 100644 --- a/src/boot/efi/drivers.c +++ b/src/boot/efi/drivers.c @@ -12,7 +12,7 @@ static EFI_STATUS load_one_driver( const char16_t *fname) { _cleanup_(unload_imagep) EFI_HANDLE image = NULL; - _cleanup_freepool_ EFI_DEVICE_PATH *path = NULL; + _cleanup_free_ EFI_DEVICE_PATH *path = NULL; _cleanup_free_ char16_t *spath = NULL; EFI_STATUS err; @@ -51,7 +51,7 @@ static EFI_STATUS load_one_driver( } static EFI_STATUS reconnect(void) { - _cleanup_freepool_ EFI_HANDLE *handles = NULL; + _cleanup_free_ EFI_HANDLE *handles = NULL; UINTN n_handles = 0; EFI_STATUS err; @@ -78,7 +78,7 @@ EFI_STATUS load_drivers( EFI_FILE *root_dir) { _cleanup_(file_closep) EFI_FILE *drivers_dir = NULL; - _cleanup_freepool_ EFI_FILE_INFO *dirent = NULL; + _cleanup_free_ EFI_FILE_INFO *dirent = NULL; UINTN dirent_size = 0, n_succeeded = 0; EFI_STATUS err; diff --git a/src/boot/efi/measure.c b/src/boot/efi/measure.c index 575a3ceb558..71085546818 100644 --- a/src/boot/efi/measure.c +++ b/src/boot/efi/measure.c @@ -17,7 +17,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log( UINTN buffer_size, const char16_t *description) { - _cleanup_freepool_ TCG_PCR_EVENT *tcg_event = NULL; + _cleanup_free_ TCG_PCR_EVENT *tcg_event = NULL; EFI_PHYSICAL_ADDRESS event_log_last; uint32_t event_number = 1; UINTN desc_len; @@ -51,7 +51,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log( uint64_t buffer_size, const char16_t *description) { - _cleanup_freepool_ EFI_TCG2_EVENT *tcg_event = NULL; + _cleanup_free_ EFI_TCG2_EVENT *tcg_event = NULL; UINTN desc_len; assert(tcg); diff --git a/src/boot/efi/pe.c b/src/boot/efi/pe.c index 32ac49d1e25..8d7061d55b2 100644 --- a/src/boot/efi/pe.c +++ b/src/boot/efi/pe.c @@ -282,7 +282,7 @@ EFI_STATUS pe_file_locate_sections( const char * const sections[], UINTN *offsets, UINTN *sizes) { - _cleanup_freepool_ PeSectionHeader *section_table = NULL; + _cleanup_free_ PeSectionHeader *section_table = NULL; _cleanup_(file_closep) EFI_FILE *handle = NULL; DosFileHeader dos; PeFileHeader pe; diff --git a/src/boot/efi/random-seed.c b/src/boot/efi/random-seed.c index 598c9b0500f..652634bdc9b 100644 --- a/src/boot/efi/random-seed.c +++ b/src/boot/efi/random-seed.c @@ -18,7 +18,7 @@ #define HASH_VALUE_SIZE 32 static EFI_STATUS acquire_rng(UINTN size, void **ret) { - _cleanup_freepool_ void *data = NULL; + _cleanup_free_ void *data = NULL; EFI_RNG_PROTOCOL *rng; EFI_STATUS err; @@ -90,7 +90,7 @@ static EFI_STATUS hash_many( UINTN n, void **ret) { - _cleanup_freepool_ void *output = NULL; + _cleanup_free_ void *output = NULL; assert(old_seed); assert(system_token_size == 0 || system_token); @@ -122,7 +122,7 @@ static EFI_STATUS mangle_random_seed( void **ret_new_seed, void **ret_for_kernel) { - _cleanup_freepool_ void *new_seed = NULL, *for_kernel = NULL; + _cleanup_free_ void *new_seed = NULL, *for_kernel = NULL; EFI_STATUS err; UINTN n; @@ -230,10 +230,10 @@ static void validate_sha256(void) { } EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) { - _cleanup_freepool_ void *seed = NULL, *new_seed = NULL, *rng = NULL, *for_kernel = NULL, *system_token = NULL; + _cleanup_free_ void *seed = NULL, *new_seed = NULL, *rng = NULL, *for_kernel = NULL, *system_token = NULL; _cleanup_(file_closep) EFI_FILE *handle = NULL; UINTN size, rsize, wsize, system_token_size = 0; - _cleanup_freepool_ EFI_FILE_INFO *info = NULL; + _cleanup_free_ EFI_FILE_INFO *info = NULL; uint64_t uefi_monotonic_counter = 0; EFI_STATUS err; diff --git a/src/boot/efi/splash.c b/src/boot/efi/splash.c index 11a02b52d5e..1f805cf9834 100644 --- a/src/boot/efi/splash.c +++ b/src/boot/efi/splash.c @@ -260,7 +260,7 @@ EFI_STATUS graphics_splash(const uint8_t *content, UINTN len, const EFI_GRAPHICS struct bmp_dib *dib; struct bmp_map *map; const uint8_t *pixmap; - _cleanup_freepool_ void *blt = NULL; + _cleanup_free_ void *blt = NULL; UINTN x_pos = 0; UINTN y_pos = 0; EFI_STATUS err; diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c index de594a54784..2acd5e57385 100644 --- a/src/boot/efi/stub.c +++ b/src/boot/efi/stub.c @@ -169,8 +169,8 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { UINTN cmdline_len = 0, linux_size, initrd_size, dt_size; UINTN credential_initrd_size = 0, global_credential_initrd_size = 0, sysext_initrd_size = 0; - _cleanup_freepool_ void *credential_initrd = NULL, *global_credential_initrd = NULL; - _cleanup_freepool_ void *sysext_initrd = NULL; + _cleanup_free_ void *credential_initrd = NULL, *global_credential_initrd = NULL; + _cleanup_free_ void *sysext_initrd = NULL; EFI_PHYSICAL_ADDRESS linux_base, initrd_base, dt_base; _cleanup_(devicetree_cleanup) struct devicetree_state dt_state = {}; EFI_LOADED_IMAGE_PROTOCOL *loaded_image; diff --git a/src/boot/efi/test-bcd.c b/src/boot/efi/test-bcd.c index d04d1ee45a0..0ee29477040 100644 --- a/src/boot/efi/test-bcd.c +++ b/src/boot/efi/test-bcd.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "alloc-util.h" +#include "bcd.h" #include "compress.h" #include "fileio.h" #include "tests.h" diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index c5142467b24..7603eb8f534 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -241,7 +241,7 @@ void efivar_set_time_usec(const EFI_GUID *vendor, const char16_t *name, uint64_t efivar_set(vendor, name, str, 0); } -static INTN utf8_to_16(const char *stra, char16_t *c) { +static int utf8_to_16(const char *stra, char16_t *c) { char16_t unichar; UINTN len; @@ -309,7 +309,7 @@ char16_t *xstra_to_str(const char *stra) { strlen = 0; i = 0; while (i < len) { - INTN utf8len; + int utf8len; utf8len = utf8_to_16(stra + i, str + strlen); if (utf8len <= 0) { @@ -340,7 +340,7 @@ char16_t *xstra_to_path(const char *stra) { strlen = 1; i = 0; while (i < len) { - INTN utf8len; + int utf8len; utf8len = utf8_to_16(stra + i, str + strlen); if (utf8len <= 0) { @@ -378,7 +378,7 @@ EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, UINTN off, UINTN size, return err; if (size == 0) { - _cleanup_freepool_ EFI_FILE_INFO *info = NULL; + _cleanup_free_ EFI_FILE_INFO *info = NULL; err = get_file_info_harder(handle, &info, NULL); if (err != EFI_SUCCESS) @@ -483,7 +483,7 @@ EFI_STATUS get_file_info_harder( UINTN *ret_size) { UINTN size = offsetof(EFI_FILE_INFO, FileName) + 256; - _cleanup_freepool_ EFI_FILE_INFO *fi = NULL; + _cleanup_free_ EFI_FILE_INFO *fi = NULL; EFI_STATUS err; assert(handle); @@ -585,7 +585,7 @@ EFI_STATUS open_directory( EFI_FILE **ret) { _cleanup_(file_closep) EFI_FILE *dir = NULL; - _cleanup_freepool_ EFI_FILE_INFO *file_info = NULL; + _cleanup_free_ EFI_FILE_INFO *file_info = NULL; EFI_STATUS err; assert(root); diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index e314d319614..4de799ea0e4 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -41,7 +41,6 @@ static inline void freep(void *p) { free(*(void **) p); } -#define _cleanup_freepool_ _cleanup_free_ #define _cleanup_free_ _cleanup_(freep) _malloc_ _alloc_(1) _returns_nonnull_ _warn_unused_result_ @@ -144,22 +143,16 @@ EFI_STATUS open_directory(EFI_FILE *root_dir, const char16_t *path, EFI_FILE **r /* 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 - * conversion indirectly: first into UINTN (which is defined by UEFI to have the same size as a pointer), and - * then extended to EFI_PHYSICAL_ADDRESS. */ + * conversion indirectly: first into uintptr_t and then extended to EFI_PHYSICAL_ADDRESS. */ static inline EFI_PHYSICAL_ADDRESS POINTER_TO_PHYSICAL_ADDRESS(const void *p) { - return (EFI_PHYSICAL_ADDRESS) (UINTN) p; + return (EFI_PHYSICAL_ADDRESS) (uintptr_t) p; } static inline void *PHYSICAL_ADDRESS_TO_POINTER(EFI_PHYSICAL_ADDRESS addr) { -#if __SIZEOF_POINTER__ == 4 /* On 32bit systems the address might not be convertible (as pointers are 32bit but * EFI_PHYSICAL_ADDRESS 64bit) */ - assert(addr <= UINT32_MAX); -#elif __SIZEOF_POINTER__ != 8 - #error "Unexpected pointer size" -#endif - - return (void*) (UINTN) addr; + assert(addr <= UINTPTR_MAX); + return (void *) (uintptr_t) addr; } uint64_t get_os_indications_supported(void); diff --git a/src/boot/efi/xbootldr.c b/src/boot/efi/xbootldr.c index 5db689b65ff..3ccf9fa8b1c 100644 --- a/src/boot/efi/xbootldr.c +++ b/src/boot/efi/xbootldr.c @@ -90,7 +90,7 @@ static EFI_STATUS try_gpt( EFI_LBA *ret_backup_lba, /* May be changed even on error! */ HARDDRIVE_DEVICE_PATH *ret_hd) { - _cleanup_freepool_ EFI_PARTITION_ENTRY *entries = NULL; + _cleanup_free_ EFI_PARTITION_ENTRY *entries = NULL; union GptHeaderBuffer gpt; EFI_STATUS err; uint32_t crc32; @@ -191,7 +191,7 @@ static EFI_STATUS find_device(EFI_HANDLE *device, EFI_DEVICE_PATH **ret_device_p return EFI_NOT_FOUND; /* Chop off the partition part, leaving us with the full path to the disk itself. */ - _cleanup_freepool_ EFI_DEVICE_PATH *disk_path = NULL; + _cleanup_free_ EFI_DEVICE_PATH *disk_path = NULL; EFI_DEVICE_PATH *p = disk_path = path_chop(partition_path, part_node); EFI_HANDLE disk_handle; @@ -254,7 +254,7 @@ static EFI_STATUS find_device(EFI_HANDLE *device, EFI_DEVICE_PATH **ret_device_p } EFI_STATUS xbootldr_open(EFI_HANDLE *device, EFI_HANDLE *ret_device, EFI_FILE **ret_root_dir) { - _cleanup_freepool_ EFI_DEVICE_PATH *partition_path = NULL; + _cleanup_free_ EFI_DEVICE_PATH *partition_path = NULL; EFI_HANDLE new_device; EFI_FILE *root_dir; EFI_STATUS err;