]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Use stdbool 23842/head
authorJan Janssen <medhefgo@web.de>
Mon, 27 Jun 2022 09:04:57 +0000 (11:04 +0200)
committerJan Janssen <medhefgo@web.de>
Mon, 27 Jun 2022 10:27:23 +0000 (12:27 +0200)
The way the UEFI spec defines BOOLEAN is fully compatible to stdbool, so
it is perfectly safe to switch to it. Although any other values than 0/1
are undefined by the spec, we could theoretically have cases where a
sloppy firmware hands us a bad BOOLEAN (since gnu-efi/edk2 declare it
as uint8_t). So any uses where we pass a pointer to BOOLEAN are left
untouched.

18 files changed:
src/boot/efi/boot.c
src/boot/efi/console.c
src/boot/efi/drivers.c
src/boot/efi/graphics.c
src/boot/efi/graphics.h
src/boot/efi/measure.c
src/boot/efi/measure.h
src/boot/efi/pe.c
src/boot/efi/secure-boot.c
src/boot/efi/secure-boot.h
src/boot/efi/shim.c
src/boot/efi/shim.h
src/boot/efi/splash.c
src/boot/efi/stub.c
src/boot/efi/ticks.c
src/boot/efi/util.c
src/boot/efi/util.h
src/boot/efi/xbootldr.c

index 33dfa02b6f37ba5c53749b5622dd87aa873eab20..09ad15a0ab503676ea62a54d0586850c28ffc997 100644 (file)
@@ -84,14 +84,14 @@ typedef struct {
         char16_t *entry_default_efivar;
         char16_t *entry_oneshot;
         char16_t *entry_saved;
-        BOOLEAN editor;
-        BOOLEAN auto_entries;
-        BOOLEAN auto_firmware;
-        BOOLEAN reboot_for_bitlocker;
-        BOOLEAN force_menu;
-        BOOLEAN use_saved_entry;
-        BOOLEAN use_saved_entry_efivar;
-        BOOLEAN beep;
+        bool editor;
+        bool auto_entries;
+        bool auto_firmware;
+        bool reboot_for_bitlocker;
+        bool force_menu;
+        bool use_saved_entry;
+        bool use_saved_entry_efivar;
+        bool beep;
         int64_t console_mode;
         int64_t console_mode_efivar;
         RandomSeedMode random_seed_mode;
@@ -139,7 +139,7 @@ static void cursor_right(
                 (*first)++;
 }
 
-static BOOLEAN line_edit(
+static bool line_edit(
                 char16_t **line_in,
                 UINTN x_max,
                 UINTN y_pos) {
@@ -181,7 +181,7 @@ static BOOLEAN line_edit(
 
                         err = console_key_read(&key, 750 * 1000);
                         if (!IN_SET(err, EFI_SUCCESS, EFI_TIMEOUT, EFI_NOT_READY))
-                                return FALSE;
+                                return false;
 
                         print_at(cursor + 1, y_pos, COLOR_EDIT, print + cursor);
                 } while (err != EFI_SUCCESS);
@@ -192,7 +192,7 @@ static BOOLEAN line_edit(
                 case KEYPRESS(EFI_CONTROL_PRESSED, 0, 'g'):
                 case KEYPRESS(EFI_CONTROL_PRESSED, 0, CHAR_CTRL('c')):
                 case KEYPRESS(EFI_CONTROL_PRESSED, 0, CHAR_CTRL('g')):
-                        return FALSE;
+                        return false;
 
                 case KEYPRESS(0, SCAN_HOME, 0):
                 case KEYPRESS(EFI_CONTROL_PRESSED, 0, 'a'):
@@ -321,7 +321,7 @@ static BOOLEAN line_edit(
                                 free(*line_in);
                                 *line_in = TAKE_PTR(line);
                         }
-                        return TRUE;
+                        return true;
 
                 case KEYPRESS(0, 0, CHAR_BACKSPACE):
                         if (len == 0)
@@ -396,7 +396,7 @@ static UINTN entry_lookup_key(Config *config, UINTN start, char16_t key) {
         return IDX_INVALID;
 }
 
-static char16_t *update_timeout_efivar(uint32_t *t, BOOLEAN inc) {
+static char16_t *update_timeout_efivar(uint32_t *t, bool inc) {
         assert(t);
 
         switch (*t) {
@@ -428,7 +428,7 @@ static char16_t *update_timeout_efivar(uint32_t *t, BOOLEAN inc) {
         }
 }
 
-static BOOLEAN unicode_supported(void) {
+static bool unicode_supported(void) {
         static INTN cache = -1;
 
         if (cache < 0)
@@ -445,12 +445,12 @@ static void ps_string(const char16_t *fmt, const void *value) {
                 Print(fmt, value);
 }
 
-static void ps_bool(const char16_t *fmt, BOOLEAN value) {
+static void ps_bool(const char16_t *fmt, bool value) {
         assert(fmt);
         Print(fmt, yes_no(value));
 }
 
-static BOOLEAN ps_continue(void) {
+static bool ps_continue(void) {
         if (unicode_supported())
                 Print(L"\n─── Press any key to continue, ESC or q to quit. ───\n\n");
         else
@@ -595,7 +595,7 @@ static EFI_STATUS reboot_into_firmware(void) {
         assert_not_reached();
 }
 
-static BOOLEAN menu_run(
+static bool menu_run(
                 Config *config,
                 ConfigEntry **chosen_entry,
                 char16_t *loaded_image_path) {
@@ -609,21 +609,21 @@ static BOOLEAN menu_run(
         UINTN idx_highlight = config->idx_default;
         UINTN idx_highlight_prev = 0;
         UINTN idx, idx_first = 0, idx_last = 0;
-        BOOLEAN new_mode = TRUE, clear = TRUE;
-        BOOLEAN refresh = TRUE, highlight = FALSE;
+        bool new_mode = true, clear = true;
+        bool refresh = true, highlight = false;
         UINTN x_start = 0, y_start = 0, y_status = 0;
         UINTN x_max, y_max;
         _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;
+        bool exit = false, run = true, firmware_setup = false;
         int64_t console_mode_initial = ST->ConOut->Mode->Mode, console_mode_efivar_saved = config->console_mode_efivar;
         UINTN default_efivar_saved = config->idx_default_efivar;
 
-        graphics_mode(FALSE);
-        ST->ConIn->Reset(ST->ConIn, FALSE);
-        ST->ConOut->EnableCursor(ST->ConOut, FALSE);
+        graphics_mode(false);
+        ST->ConIn->Reset(ST->ConIn, false);
+        ST->ConOut->EnableCursor(ST->ConOut, false);
 
         /* draw a single character to make ClearScreen work on some firmware */
         Print(L" ");
@@ -707,14 +707,14 @@ static BOOLEAN menu_run(
                         clearline[x_max] = 0;
                         separator[x_max] = 0;
 
-                        new_mode = FALSE;
-                        clear = TRUE;
+                        new_mode = false;
+                        clear = true;
                 }
 
                 if (clear) {
                         clear_screen(COLOR_NORMAL);
-                        clear = FALSE;
-                        refresh = TRUE;
+                        clear = false;
+                        refresh = true;
                 }
 
                 if (refresh) {
@@ -728,7 +728,7 @@ static BOOLEAN menu_run(
                                                  (i == idx_highlight) ? COLOR_HIGHLIGHT : COLOR_ENTRY,
                                                  unicode_supported() ? L" ►" : L"=>");
                         }
-                        refresh = FALSE;
+                        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]);
@@ -742,7 +742,7 @@ static BOOLEAN menu_run(
                                          y_start + idx_highlight - idx_first,
                                          COLOR_HIGHLIGHT,
                                          unicode_supported() ? L" ►" : L"=>");
-                        highlight = FALSE;
+                        highlight = false;
                 }
 
                 if (timeout_remain > 0) {
@@ -783,7 +783,7 @@ static BOOLEAN menu_run(
                         assert(timeout_remain > 0);
                         timeout_remain--;
                         if (timeout_remain == 0) {
-                                exit = TRUE;
+                                exit = true;
                                 break;
                         }
 
@@ -791,7 +791,7 @@ static BOOLEAN menu_run(
                         continue;
                 }
                 if (err != EFI_SUCCESS) {
-                        exit = TRUE;
+                        exit = true;
                         break;
                 }
 
@@ -803,7 +803,7 @@ static BOOLEAN menu_run(
                 idx_highlight_prev = idx_highlight;
 
                 if (firmware_setup) {
-                        firmware_setup = FALSE;
+                        firmware_setup = false;
                         if (key == KEYPRESS(0, 0, CHAR_CARRIAGE_RETURN))
                                 reboot_into_firmware();
                         continue;
@@ -827,7 +827,7 @@ static BOOLEAN menu_run(
                 case KEYPRESS(0, SCAN_HOME, 0):
                 case KEYPRESS(EFI_ALT_PRESSED, 0, '<'):
                         if (idx_highlight > 0) {
-                                refresh = TRUE;
+                                refresh = true;
                                 idx_highlight = 0;
                         }
                         break;
@@ -835,7 +835,7 @@ static BOOLEAN menu_run(
                 case KEYPRESS(0, SCAN_END, 0):
                 case KEYPRESS(EFI_ALT_PRESSED, 0, '>'):
                         if (idx_highlight < config->entry_count-1) {
-                                refresh = TRUE;
+                                refresh = true;
                                 idx_highlight = config->entry_count-1;
                         }
                         break;
@@ -858,7 +858,7 @@ static BOOLEAN menu_run(
                 case KEYPRESS(0, CHAR_CARRIAGE_RETURN, 0): /* EZpad Mini 4s firmware sends malformed events */
                 case KEYPRESS(0, CHAR_CARRIAGE_RETURN, CHAR_CARRIAGE_RETURN): /* Teclast X98+ II firmware sends malformed events */
                 case KEYPRESS(0, SCAN_RIGHT, 0):
-                        exit = TRUE;
+                        exit = true;
                         break;
 
                 case KEYPRESS(0, SCAN_F1, 0):
@@ -870,8 +870,8 @@ static BOOLEAN menu_run(
                         break;
 
                 case KEYPRESS(0, 0, 'Q'):
-                        exit = TRUE;
-                        run = FALSE;
+                        exit = true;
+                        run = false;
                         break;
 
                 case KEYPRESS(0, 0, 'd'):
@@ -886,18 +886,18 @@ static BOOLEAN menu_run(
                                 config->idx_default_efivar = IDX_INVALID;
                                 status = xstrdup16(u"Default boot entry cleared.");
                         }
-                        config->use_saved_entry_efivar = FALSE;
-                        refresh = TRUE;
+                        config->use_saved_entry_efivar = false;
+                        refresh = true;
                         break;
 
                 case KEYPRESS(0, 0, '-'):
                 case KEYPRESS(0, 0, 'T'):
-                        status = update_timeout_efivar(&config->timeout_sec_efivar, FALSE);
+                        status = update_timeout_efivar(&config->timeout_sec_efivar, false);
                         break;
 
                 case KEYPRESS(0, 0, '+'):
                 case KEYPRESS(0, 0, 't'):
-                        status = update_timeout_efivar(&config->timeout_sec_efivar, TRUE);
+                        status = update_timeout_efivar(&config->timeout_sec_efivar, true);
                         break;
 
                 case KEYPRESS(0, 0, 'e'):
@@ -939,12 +939,12 @@ static BOOLEAN menu_run(
                 case KEYPRESS(0, 0, 'p'):
                 case KEYPRESS(0, 0, 'P'):
                         print_status(config, loaded_image_path);
-                        clear = TRUE;
+                        clear = true;
                         break;
 
                 case KEYPRESS(EFI_CONTROL_PRESSED, 0, 'l'):
                 case KEYPRESS(EFI_CONTROL_PRESSED, 0, CHAR_CTRL('l')):
-                        clear = TRUE;
+                        clear = true;
                         break;
 
                 case KEYPRESS(0, 0, 'r'):
@@ -955,7 +955,7 @@ static BOOLEAN menu_run(
                                 config->console_mode_efivar = ST->ConOut->Mode->Mode;
                                 status = xpool_print(L"Console mode changed to %ld.", config->console_mode_efivar);
                         }
-                        new_mode = TRUE;
+                        new_mode = true;
                         break;
 
                 case KEYPRESS(0, 0, 'R'):
@@ -967,7 +967,7 @@ static BOOLEAN menu_run(
                         else
                                 status = xpool_print(L"Console mode reset to %s default.",
                                                      config->console_mode == CONSOLE_MODE_KEEP ? L"firmware" : L"configuration file");
-                        new_mode = TRUE;
+                        new_mode = true;
                         break;
 
                 case KEYPRESS(0, 0, 'f'):
@@ -977,7 +977,7 @@ static BOOLEAN menu_run(
                 case KEYPRESS(0, SCAN_DELETE, 0): /* Same as F2. */
                 case KEYPRESS(0, SCAN_ESC, 0):    /* HP. */
                         if (FLAGS_SET(get_os_indications_supported(), EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) {
-                                firmware_setup = TRUE;
+                                firmware_setup = true;
                                 /* Let's make sure the user really wants to do this. */
                                 status = xpool_print(L"Press Enter to reboot into firmware interface.");
                         } else
@@ -990,21 +990,21 @@ static BOOLEAN menu_run(
                         if (idx == IDX_INVALID)
                                 break;
                         idx_highlight = idx;
-                        refresh = TRUE;
+                        refresh = true;
                 }
 
                 if (idx_highlight > idx_last) {
                         idx_last = idx_highlight;
                         idx_first = 1 + idx_highlight - visible_max;
-                        refresh = TRUE;
+                        refresh = true;
                 } else if (idx_highlight < idx_first) {
                         idx_first = idx_highlight;
                         idx_last = idx_highlight + visible_max-1;
-                        refresh = TRUE;
+                        refresh = true;
                 }
 
                 if (!refresh && idx_highlight != idx_highlight_prev)
-                        highlight = TRUE;
+                        highlight = true;
         }
 
         *chosen_entry = config->entries[idx_highlight];
@@ -1246,7 +1246,7 @@ static void config_defaults_load_from_file(Config *config, char *content) {
                         else if (streq8(value, "always"))
                                 config->random_seed_mode = RANDOM_SEED_ALWAYS;
                         else {
-                                BOOLEAN on;
+                                bool on;
 
                                 err = parse_boolean(value, &on);
                                 if (err != EFI_SUCCESS) {
@@ -1515,10 +1515,10 @@ static void config_load_defaults(Config *config, EFI_FILE *root_dir) {
         assert(root_dir);
 
         *config = (Config) {
-                .editor = TRUE,
-                .auto_entries = TRUE,
-                .auto_firmware = TRUE,
-                .reboot_for_bitlocker = FALSE,
+                .editor = true,
+                .auto_entries = true,
+                .auto_firmware = true,
+                .reboot_for_bitlocker = false,
                 .random_seed_mode = RANDOM_SEED_WITH_SYSTEM_TOKEN,
                 .idx_default_efivar = IDX_INVALID,
                 .console_mode = CONSOLE_MODE_KEEP,
@@ -1543,7 +1543,7 @@ static void config_load_defaults(Config *config, EFI_FILE *root_dir) {
                 (void) efivar_set(LOADER_GUID, L"LoaderConfigTimeoutOneShot", NULL, EFI_VARIABLE_NON_VOLATILE);
 
                 config->timeout_sec = MIN(value, TIMEOUT_TYPE_MAX);
-                config->force_menu = TRUE; /* force the menu when this is set */
+                config->force_menu = true; /* force the menu when this is set */
         }
 
         err = efivar_get_uint_string(LOADER_GUID, L"LoaderConfigConsoleMode", &value);
@@ -1723,8 +1723,8 @@ static void config_default_entry_select(Config *config) {
                 config->timeout_sec = 10;
 }
 
-static BOOLEAN entries_unique(ConfigEntry **entries, BOOLEAN *unique, UINTN entry_count) {
-        BOOLEAN is_unique = TRUE;
+static bool entries_unique(ConfigEntry **entries, bool *unique, UINTN entry_count) {
+        bool is_unique = true;
 
         assert(entries);
         assert(unique);
@@ -1734,7 +1734,7 @@ static BOOLEAN entries_unique(ConfigEntry **entries, BOOLEAN *unique, UINTN entr
                         if (!streq16(entries[i]->title_show, entries[k]->title_show))
                                 continue;
 
-                        is_unique = unique[i] = unique[k] = FALSE;
+                        is_unique = unique[i] = unique[k] = false;
                 }
 
         return is_unique;
@@ -1744,12 +1744,12 @@ static BOOLEAN entries_unique(ConfigEntry **entries, BOOLEAN *unique, UINTN entr
 static void config_title_generate(Config *config) {
         assert(config);
 
-        BOOLEAN unique[config->entry_count];
+        bool unique[config->entry_count];
 
         /* set title */
         for (UINTN i = 0; i < config->entry_count; i++) {
                 assert(!config->entries[i]->title_show);
-                unique[i] = TRUE;
+                unique[i] = true;
                 config->entries[i]->title_show = xstrdup16(config->entries[i]->title ?: config->entries[i]->id);
         }
 
@@ -1761,7 +1761,7 @@ static void config_title_generate(Config *config) {
                 if (unique[i])
                         continue;
 
-                unique[i] = TRUE;
+                unique[i] = true;
 
                 if (!config->entries[i]->version)
                         continue;
@@ -1778,7 +1778,7 @@ static void config_title_generate(Config *config) {
                 if (unique[i])
                         continue;
 
-                unique[i] = TRUE;
+                unique[i] = true;
 
                 if (!config->entries[i]->machine_id)
                         continue;
@@ -1804,7 +1804,7 @@ static void config_title_generate(Config *config) {
         }
 }
 
-static BOOLEAN is_sd_boot(EFI_FILE *root_dir, const char16_t *loader_path) {
+static bool is_sd_boot(EFI_FILE *root_dir, const char16_t *loader_path) {
         EFI_STATUS err;
         const char *sections[] = {
                 ".sdmagic",
@@ -1818,11 +1818,11 @@ static BOOLEAN is_sd_boot(EFI_FILE *root_dir, const char16_t *loader_path) {
 
         err = pe_file_locate_sections(root_dir, loader_path, sections, &offset, &size);
         if (err != EFI_SUCCESS || size != sizeof(magic))
-                return FALSE;
+                return false;
 
         err = file_read(root_dir, loader_path, offset, size, &content, &read);
         if (err != EFI_SUCCESS || size != read)
-                return FALSE;
+                return false;
 
         return memcmp(content, magic, sizeof(magic)) == 0;
 }
@@ -1933,7 +1933,7 @@ static EFI_STATUS boot_windows_bitlocker(void) {
                 return err;
 
         /* Look for BitLocker magic string on all block drives. */
-        BOOLEAN found = FALSE;
+        bool found = false;
         for (UINTN i = 0; i < n_handles; i++) {
                 EFI_BLOCK_IO *block_io;
                 err = BS->HandleProtocol(handles[i], &BlockIoProtocol, (void **) &block_io);
@@ -1946,7 +1946,7 @@ static EFI_STATUS boot_windows_bitlocker(void) {
                         continue;
 
                 if (memcmp(buf + 3, "-FVE-FS-", STRLEN("-FVE-FS-")) == 0) {
-                        found = TRUE;
+                        found = true;
                         break;
                 }
         }
@@ -2313,7 +2313,7 @@ static EFI_STATUS image_start(
         if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error preparing initrd: %r", err);
 
-        err = BS->LoadImage(FALSE, parent_image, path, NULL, 0, &image);
+        err = BS->LoadImage(false, parent_image, path, NULL, 0, &image);
         if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error loading %s: %r", entry->loader, err);
 
@@ -2344,7 +2344,7 @@ static EFI_STATUS image_start(
 
         efivar_set_time_usec(LOADER_GUID, L"LoaderTimeExecUSec", 0);
         err = BS->StartImage(image, NULL, NULL);
-        graphics_mode(FALSE);
+        graphics_mode(false);
         if (err == EFI_SUCCESS)
                 return EFI_SUCCESS;
 
@@ -2361,7 +2361,7 @@ static EFI_STATUS image_start(
                                 (EFI_IMAGE_ENTRY_POINT) ((uint8_t *) loaded_image->ImageBase + kernel_entry_address);
 
                         err = kernel_entry(image, ST);
-                        graphics_mode(FALSE);
+                        graphics_mode(false);
                         if (err == EFI_SUCCESS)
                                 return EFI_SUCCESS;
                 }
@@ -2533,7 +2533,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         char16_t *loaded_image_path;
         EFI_STATUS err;
         uint64_t init_usec;
-        BOOLEAN menu = FALSE;
+        bool menu = false;
 
         InitializeLib(image, sys_table);
         init_usec = time_usec();
@@ -2577,7 +2577,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
 
         /* select entry or show menu when key is pressed or timeout is set */
         if (config.force_menu || config.timeout_sec > 0)
-                menu = TRUE;
+                menu = true;
         else {
                 uint64_t key;
 
@@ -2589,7 +2589,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                         if (idx != IDX_INVALID)
                                 config.idx_default = idx;
                         else
-                                menu = TRUE;
+                                menu = true;
                 }
         }
 
@@ -2620,7 +2620,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                 if (err != EFI_SUCCESS)
                         goto out;
 
-                menu = TRUE;
+                menu = true;
                 config.timeout_sec = 0;
         }
         err = EFI_SUCCESS;
index f09f83f73b3e33ff61f7101091af746996d22070..f61199ccfd86c04ed0106d622ea8abbca765e499 100644 (file)
@@ -39,7 +39,7 @@ static inline void event_closep(EFI_EVENT *event) {
  * any input functions that can freeze on us or using a busy/stall loop. */
 EFI_STATUS console_key_read(uint64_t *key, uint64_t timeout_usec) {
         static EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *conInEx = NULL, *extraInEx = NULL;
-        static BOOLEAN checked = FALSE;
+        static bool checked = false;
         UINTN index;
         EFI_STATUS err;
         _cleanup_(event_closep) EFI_EVENT timer = NULL;
@@ -62,7 +62,7 @@ EFI_STATUS console_key_read(uint64_t *key, uint64_t timeout_usec) {
                 if (conInEx == extraInEx)
                         extraInEx = NULL;
 
-                checked = TRUE;
+                checked = true;
         }
 
         err = BS->CreateEvent(EVT_TIMER, 0, NULL, NULL, &timer);
@@ -176,7 +176,7 @@ static EFI_STATUS change_mode(int64_t mode) {
                 return err;
 
         /* Maybe the device is on fire? */
-        ST->ConOut->Reset(ST->ConOut, TRUE);
+        ST->ConOut->Reset(ST->ConOut, true);
         ST->ConOut->SetMode(ST->ConOut, CONSOLE_MODE_RANGE_MIN);
         return err;
 }
@@ -201,13 +201,13 @@ static int64_t get_auto_mode(void) {
         uint32_t screen_width, screen_height;
 
         if (query_screen_resolution(&screen_width, &screen_height) == EFI_SUCCESS) {
-                BOOLEAN keep = FALSE;
+                bool keep = false;
 
                 /* Start verifying if we are in a resolution larger than Full HD
                  * (1920x1080). If we're not, assume we're in a good mode and do not
                  * try to change it. */
                 if (screen_width <= HORIZONTAL_MAX_OK && screen_height <= VERTICAL_MAX_OK)
-                        keep = TRUE;
+                        keep = true;
                 /* For larger resolutions, calculate the ratio of the total screen
                  * area to the text viewport area. If it's less than 10 times bigger,
                  * then assume the text is readable and keep the text mode. */
@@ -220,7 +220,7 @@ static int64_t get_auto_mode(void) {
                         text_area = SYSTEM_FONT_WIDTH * SYSTEM_FONT_HEIGHT * (uint64_t)x_max * (uint64_t)y_max;
 
                         if (text_area != 0 && screen_area/text_area < VIEWPORT_RATIO)
-                                keep = TRUE;
+                                keep = true;
                 }
 
                 if (keep)
index 30fb784ecc8db4804d04df96c3b337959db14a23..fc47aca16c08f992f349b4e2174ddbaf77594717 100644 (file)
@@ -25,7 +25,7 @@ static EFI_STATUS load_one_driver(
         if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Error making file device path: %r", err);
 
-        err = BS->LoadImage(FALSE, parent_image, path, NULL, 0, &image);
+        err = BS->LoadImage(false, parent_image, path, NULL, 0, &image);
         if (err != EFI_SUCCESS)
                 return log_error_status_stall(err, L"Failed to load image %s: %r", fname, err);
 
@@ -62,7 +62,7 @@ static EFI_STATUS reconnect(void) {
                   return log_error_status_stall(err, L"Failed to get list of handles: %r", err);
 
           for (UINTN i = 0; i < n_handles; i++) {
-                  err = BS->ConnectController(handles[i], NULL, NULL, TRUE);
+                  err = BS->ConnectController(handles[i], NULL, NULL, true);
                   if (err == EFI_NOT_FOUND) /* No drivers for this handle */
                           continue;
                   if (err != EFI_SUCCESS)
index 3a1b69016e540c7ce6c2aa743f60f8bd18bd64c2..dc646bce1f2293da6e75b62222434b741e6dac9f 100644 (file)
@@ -11,7 +11,7 @@
 #include "missing_efi.h"
 #include "util.h"
 
-EFI_STATUS graphics_mode(BOOLEAN on) {
+EFI_STATUS graphics_mode(bool on) {
         EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL;
         EFI_CONSOLE_CONTROL_SCREEN_MODE new;
         EFI_CONSOLE_CONTROL_SCREEN_MODE current;
@@ -37,7 +37,7 @@ EFI_STATUS graphics_mode(BOOLEAN on) {
         err =ConsoleControl->SetMode(ConsoleControl, new);
 
         /* some firmware enables the cursor when switching modes */
-        ST->ConOut->EnableCursor(ST->ConOut, FALSE);
+        ST->ConOut->EnableCursor(ST->ConOut, false);
 
         return err;
 }
index 96f25d809aab1e649dacd6fa9332dfff852945bf..9dadd3985eecd488cfb0fbc4d84cf3b3aded3251 100644 (file)
@@ -6,5 +6,6 @@
 #pragma once
 
 #include <efi.h>
+#include <stdbool.h>
 
-EFI_STATUS graphics_mode(BOOLEAN on);
+EFI_STATUS graphics_mode(bool on);
index a4490056d95bd64b6f1e639e1ec9a02392712109..575a3ceb55849d43d7133bf1b132b90ca0dd2bff 100644 (file)
@@ -137,7 +137,7 @@ static EFI_TCG2 * tcg2_interface_check(void) {
         return tcg;
 }
 
-BOOLEAN tpm_present(void) {
+bool tpm_present(void) {
         return tcg2_interface_check() || tcg1_interface_check();
 }
 
index 5a66cd7a4de6eb997dc5bf1dec1bd1dc677c8375..057f4a44d6c71248c40c323c491bacdff834e6a8 100644 (file)
@@ -2,6 +2,7 @@
 #pragma once
 
 #include <efi.h>
+#include <stdbool.h>
 #include <uchar.h>
 
 /* This TPM PCR is where we extend the kernel command line and any passed credentials here. */
 
 #if ENABLE_TPM
 
-BOOLEAN tpm_present(void);
+bool tpm_present(void);
 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
 
-static inline BOOLEAN tpm_present(void) {
-        return FALSE;
+static inline bool tpm_present(void) {
+        return false;
 }
 
 static inline EFI_STATUS tpm_log_event(uint32_t pcrindex, EFI_PHYSICAL_ADDRESS buffer, UINTN buffer_size, const char16_t *description) {
index bcddf6a8f23219c6c50a5901f1dac8bb8c00781b..4a06268a429ef8e85be440c664656c2ffeb7429d 100644 (file)
@@ -117,12 +117,12 @@ struct PeSectionHeader {
         uint32_t Characteristics;
 } _packed_;
 
-static inline BOOLEAN verify_dos(const struct DosFileHeader *dos) {
+static inline bool verify_dos(const struct DosFileHeader *dos) {
         assert(dos);
         return memcmp(dos->Magic, DOS_FILE_MAGIC, STRLEN(DOS_FILE_MAGIC)) == 0;
 }
 
-static inline BOOLEAN verify_pe(const struct PeFileHeader *pe, BOOLEAN allow_compatibility) {
+static inline bool verify_pe(const struct PeFileHeader *pe, bool allow_compatibility) {
         assert(pe);
         return memcmp(pe->Magic, PE_FILE_MAGIC, STRLEN(PE_FILE_MAGIC)) == 0 &&
                (pe->FileHeader.Machine == TARGET_MACHINE_TYPE ||
@@ -226,7 +226,7 @@ EFI_STATUS pe_alignment_info(
                 return EFI_LOAD_ERROR;
 
         pe = (const struct PeFileHeader*) ((const uint8_t *)base + dos->ExeHeader);
-        if (!verify_pe(pe, /* allow_compatibility= */ TRUE))
+        if (!verify_pe(pe, /* allow_compatibility= */ true))
                 return EFI_LOAD_ERROR;
 
         uint32_t entry_address = pe->OptionalHeader.AddressOfEntryPoint;
@@ -266,7 +266,7 @@ EFI_STATUS pe_memory_locate_sections(
                 return EFI_LOAD_ERROR;
 
         pe = (const struct PeFileHeader*)&base[dos->ExeHeader];
-        if (!verify_pe(pe, /* allow_compatibility= */ FALSE))
+        if (!verify_pe(pe, /* allow_compatibility= */ false))
                 return EFI_LOAD_ERROR;
 
         offset = section_table_offset(dos, pe);
@@ -314,7 +314,7 @@ EFI_STATUS pe_file_locate_sections(
         err = handle->Read(handle, &len, &pe);
         if (err != EFI_SUCCESS)
                 return err;
-        if (len != sizeof(pe) || !verify_pe(&pe, /* allow_compatibility= */ FALSE))
+        if (len != sizeof(pe) || !verify_pe(&pe, /* allow_compatibility= */ false))
                 return EFI_LOAD_ERROR;
 
         section_table_len = pe.FileHeader.NumberOfSections * sizeof(struct PeSectionHeader);
index c1c1db10b0275ae8b31af64bbd8cc232a4d84423..31f634a4d7ab71d79a60967cf05d6477d5b58325 100644 (file)
@@ -4,8 +4,8 @@
 #include "secure-boot.h"
 #include "util.h"
 
-BOOLEAN secure_boot_enabled(void) {
-        BOOLEAN secure;
+bool secure_boot_enabled(void) {
+        bool secure;
         EFI_STATUS err;
 
         err = efivar_get_boolean_u8(EFI_GLOBAL_GUID, L"SecureBoot", &secure);
@@ -14,14 +14,14 @@ BOOLEAN secure_boot_enabled(void) {
 }
 
 SecureBootMode secure_boot_mode(void) {
-        BOOLEAN secure, audit = FALSE, deployed = FALSE, setup = FALSE;
+        bool secure, audit = false, deployed = false, setup = false;
         EFI_STATUS err;
 
         err = efivar_get_boolean_u8(EFI_GLOBAL_GUID, L"SecureBoot", &secure);
         if (err != EFI_SUCCESS)
                 return SECURE_BOOT_UNSUPPORTED;
 
-        /* We can assume FALSE for all these if they are abscent (AuditMode and
+        /* We can assume false for all these if they are abscent (AuditMode and
          * DeployedMode may not exist on older firmware). */
         (void) efivar_get_boolean_u8(EFI_GLOBAL_GUID, L"AuditMode", &audit);
         (void) efivar_get_boolean_u8(EFI_GLOBAL_GUID, L"DeployedMode", &deployed);
index d5f6ba82d449983b3b7949d5f526fdc436012b6f..ce43423fcebafd696dc0ebd980ba83ad397868be 100644 (file)
@@ -4,5 +4,5 @@
 #include <efi.h>
 #include "efivars-fundamental.h"
 
-BOOLEAN secure_boot_enabled(void);
+bool secure_boot_enabled(void);
 SecureBootMode secure_boot_mode(void);
index a4a250060a9659576ef4bb96922c114d39b87b5f..9a5c1396fd6d1322327eb9cd82b18fd16b147508 100644 (file)
@@ -34,23 +34,23 @@ struct ShimLock {
 #define SHIM_LOCK_GUID \
         &(const EFI_GUID) { 0x605dab50, 0xe046, 0x4300, { 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 } }
 
-BOOLEAN shim_loaded(void) {
+bool shim_loaded(void) {
         struct ShimLock *shim_lock;
 
         return BS->LocateProtocol((EFI_GUID*) SHIM_LOCK_GUID, NULL, (void**) &shim_lock) == EFI_SUCCESS;
 }
 
-static BOOLEAN shim_validate(void *data, uint32_t size) {
+static bool shim_validate(void *data, uint32_t size) {
         struct ShimLock *shim_lock;
 
         if (!data)
-                return FALSE;
+                return false;
 
         if (BS->LocateProtocol((EFI_GUID*) SHIM_LOCK_GUID, NULL, (void**) &shim_lock) != EFI_SUCCESS)
-                return FALSE;
+                return false;
 
         if (!shim_lock)
-                return FALSE;
+                return false;
 
         return shim_lock->shim_verify(data, size) == EFI_SUCCESS;
 }
index d682994b9e50445e7f4eda1cedb6b52ad5509197..ddbc88c52c428b7095d960f92ef9dba40dd497e3 100644 (file)
@@ -11,6 +11,6 @@
 
 #include <efi.h>
 
-BOOLEAN shim_loaded(void);
+bool shim_loaded(void);
 
 EFI_STATUS security_policy_install(void);
index 577bd8cc97909cff360e318fc5619204121edfe1..11a02b52d5e43b685433c9956588e8ec866d4781 100644 (file)
@@ -314,7 +314,7 @@ EFI_STATUS graphics_splash(const uint8_t *content, UINTN len, const EFI_GRAPHICS
         if (err != EFI_SUCCESS)
                 return err;
 
-        err = graphics_mode(TRUE);
+        err = graphics_mode(true);
         if (err != EFI_SUCCESS)
                 return err;
 
index d26fe69747848c2299fd56f79558d329a32bfdfc..9af3193d490e5ee6bdda76682165b751b137c4cd 100644 (file)
@@ -300,6 +300,6 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         err = linux_exec(image, cmdline, cmdline_len,
                          PHYSICAL_ADDRESS_TO_POINTER(linux_base), linux_size,
                          PHYSICAL_ADDRESS_TO_POINTER(initrd_base), initrd_size);
-        graphics_mode(FALSE);
+        graphics_mode(false);
         return log_error_status_stall(err, L"Execution of embedded linux image failed: %r", err);
 }
index dd8c06a53e7522683a42eca08369fb8367ca4c54..16e488c9586cb2af87b8b9a29cda357971646b32 100644 (file)
@@ -5,11 +5,12 @@
 #if defined(__i386__) || defined(__x86_64__)
 #include <cpuid.h>
 #endif
+#include <stdbool.h>
 
 #include "ticks.h"
 
 #if defined(__i386__) || defined(__x86_64__)
-static BOOLEAN in_hypervisor(void) {
+static bool in_hypervisor(void) {
         uint32_t eax, ebx, ecx, edx;
 
         /* The TSC might or might not be virtualized in VMs (and thus might not be accurate or start at zero
@@ -20,7 +21,7 @@ static BOOLEAN in_hypervisor(void) {
          * environment. */
 
         if (__get_cpuid(1, &eax, &ebx, &ecx, &edx) == 0)
-                return FALSE;
+                return false;
 
         return !!(ecx & 0x80000000U);
 }
index 2337fdaf71b51e4118247e59739ec26207254f0c..c5142467b24addd64e0efa531e88db323f725b5c 100644 (file)
@@ -6,7 +6,7 @@
 #include "ticks.h"
 #include "util.h"
 
-EFI_STATUS parse_boolean(const char *v, BOOLEAN *b) {
+EFI_STATUS parse_boolean(const char *v, bool *b) {
         assert(b);
 
         if (!v)
@@ -14,13 +14,13 @@ EFI_STATUS parse_boolean(const char *v, BOOLEAN *b) {
 
         if (streq8(v, "1") || streq8(v, "yes") || streq8(v, "y") || streq8(v, "true") || streq8(v, "t") ||
             streq8(v, "on")) {
-                *b = TRUE;
+                *b = true;
                 return EFI_SUCCESS;
         }
 
         if (streq8(v, "0") || streq8(v, "no") || streq8(v, "n") || streq8(v, "false") || streq8(v, "f") ||
             streq8(v, "off")) {
-                *b = FALSE;
+                *b = false;
                 return EFI_SUCCESS;
         }
 
@@ -52,7 +52,7 @@ EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const char16_t *name,
         /* Note that SPrint has no native sized length specifier and will always use ValueToString()
          * regardless of what sign we tell it to use. Therefore, UINTN_MAX will come out as -1 on
          * 64bit machines. */
-        ValueToString(str, FALSE, i);
+        ValueToString(str, false, i);
         return efivar_set(vendor, name, str, flags);
 }
 
@@ -209,7 +209,7 @@ EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const char16_t *name, char **b
         return err;
 }
 
-EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const char16_t *name, BOOLEAN *ret) {
+EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const char16_t *name, bool *ret) {
         _cleanup_free_ char *b = NULL;
         UINTN size;
         EFI_STATUS err;
@@ -237,7 +237,7 @@ void efivar_set_time_usec(const EFI_GUID *vendor, const char16_t *name, uint64_t
                 return;
 
         /* See comment on ValueToString in efivar_set_uint_string(). */
-        ValueToString(str, FALSE, usec);
+        ValueToString(str, false, usec);
         efivar_set(vendor, name, str, 0);
 }
 
@@ -557,15 +557,15 @@ EFI_STATUS readdir_harder(
         return EFI_SUCCESS;
 }
 
-BOOLEAN is_ascii(const char16_t *f) {
+bool is_ascii(const char16_t *f) {
         if (!f)
-                return FALSE;
+                return false;
 
         for (; *f != 0; f++)
                 if (*f > 127)
-                        return FALSE;
+                        return false;
 
-        return TRUE;
+        return true;
 }
 
 char16_t **strv_free(char16_t **v) {
@@ -624,7 +624,7 @@ uint64_t get_os_indications_supported(void) {
 __attribute__((noinline)) void debug_break(void) {
         /* This is a poor programmer's breakpoint to wait until a debugger
          * has attached to us. Just "set variable wait = 0" or "return" to continue. */
-        volatile BOOLEAN wait = TRUE;
+        volatile bool wait = true;
         while (wait)
                 /* Prefer asm based stalling so that gdb has a source location to present. */
 #if defined(__i386__) || defined(__x86_64__)
index 9043c53845f34fd70d9f533bbbd489bda67ef84a..e314d319614847d9606000492d5d9abfa39edeb1 100644 (file)
@@ -69,7 +69,7 @@ static inline void *xrealloc(void *p, size_t old_size, size_t new_size) {
 #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 char *v, BOOLEAN *b);
+EFI_STATUS parse_boolean(const char *v, bool *b);
 
 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);
@@ -83,7 +83,7 @@ EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const char16_t *name, char **b
 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);
+EFI_STATUS efivar_get_boolean_u8(const EFI_GUID *vendor, const char16_t *name, bool *ret);
 
 char16_t *xstra_to_path(const char *stra);
 char16_t *xstra_to_str(const char *stra);
@@ -132,7 +132,7 @@ 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_t *f);
+bool is_ascii(const char16_t *f);
 
 char16_t **strv_free(char16_t **l);
 
index b6ad3a426a46f77207e4ea44b09b6f9510d8121c..674506aa658f0b3347251d992b3e2261d89384e6 100644 (file)
@@ -41,7 +41,7 @@ static EFI_DEVICE_PATH *path_dup(const EFI_DEVICE_PATH *dp) {
         return dup;
 }
 
-static BOOLEAN verify_gpt(union GptHeaderBuffer *gpt_header_buffer, EFI_LBA lba_expected) {
+static bool verify_gpt(union GptHeaderBuffer *gpt_header_buffer, EFI_LBA lba_expected) {
         EFI_PARTITION_TABLE_HEADER *h;
         uint32_t crc32, crc32_saved;
         EFI_STATUS err;
@@ -52,13 +52,13 @@ static BOOLEAN verify_gpt(union GptHeaderBuffer *gpt_header_buffer, EFI_LBA lba_
 
         /* Some superficial validation of the GPT header */
         if (memcmp(&h->Header.Signature, "EFI PART", sizeof(h->Header.Signature)) != 0)
-                return FALSE;
+                return false;
 
         if (h->Header.HeaderSize < 92 || h->Header.HeaderSize > 512)
-                return FALSE;
+                return false;
 
         if (h->Header.Revision != 0x00010000U)
-                return FALSE;
+                return false;
 
         /* Calculate CRC check */
         crc32_saved = h->Header.CRC32;
@@ -66,22 +66,22 @@ static BOOLEAN verify_gpt(union GptHeaderBuffer *gpt_header_buffer, EFI_LBA lba_
         err = BS->CalculateCrc32(gpt_header_buffer, h->Header.HeaderSize, &crc32);
         h->Header.CRC32 = crc32_saved;
         if (err != EFI_SUCCESS || crc32 != crc32_saved)
-                return FALSE;
+                return false;
 
         if (h->MyLBA != lba_expected)
-                return FALSE;
+                return false;
 
         if (h->SizeOfPartitionEntry < sizeof(EFI_PARTITION_ENTRY))
-                return FALSE;
+                return false;
 
         if (h->NumberOfPartitionEntries <= 0 || h->NumberOfPartitionEntries > 1024)
-                return FALSE;
+                return false;
 
         /* overflow check */
         if (h->SizeOfPartitionEntry > UINTN_MAX / h->NumberOfPartitionEntries)
-                return FALSE;
+                return false;
 
-        return TRUE;
+        return true;
 }
 
 static EFI_STATUS try_gpt(