summaryrefslogtreecommitdiffstats
path: root/src/boot/efi/bcd.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/boot/efi/bcd.c92
1 files changed, 44 insertions, 48 deletions
diff --git a/src/boot/efi/bcd.c b/src/boot/efi/bcd.c
index 11f2a81c10..7418473d8e 100644
--- a/src/boot/efi/bcd.c
+++ b/src/boot/efi/bcd.c
@@ -12,10 +12,6 @@
# define CHAR8 char
# define CHAR16 char16_t
-# define UINT8 uint8_t
-# define UINT16 uint16_t
-# define UINT32 uint32_t
-# define UINT64 uint64_t
# define UINTN size_t
# define TEST_STATIC static
#endif
@@ -36,16 +32,16 @@ enum {
* been squashed into _padN for our convenience. */
typedef struct {
- UINT32 sig;
- UINT32 primary_seqnum;
- UINT32 secondary_seqnum;
- UINT64 _pad1;
- UINT32 version_major;
- UINT32 version_minor;
- UINT32 type;
- UINT32 _pad2;
- UINT32 root_cell_offset;
- UINT64 _pad3[507];
+ uint32_t sig;
+ uint32_t primary_seqnum;
+ uint32_t secondary_seqnum;
+ uint64_t _pad1;
+ uint32_t version_major;
+ uint32_t version_minor;
+ uint32_t type;
+ uint32_t _pad2;
+ uint32_t root_cell_offset;
+ uint64_t _pad3[507];
} _packed_ BaseBlock;
assert_cc(sizeof(BaseBlock) == 4096);
assert_cc(offsetof(BaseBlock, sig) == 0);
@@ -58,19 +54,19 @@ assert_cc(offsetof(BaseBlock, root_cell_offset) == 36);
/* All offsets are relative to the base block and technically point to a hive
* cell struct. But for our usecase we don't need to bother about that one,
- * so skip over the cell_size UINT32. */
+ * so skip over the cell_size uint32_t. */
#define HIVE_CELL_OFFSET (sizeof(BaseBlock) + 4)
typedef struct {
- UINT16 sig;
- UINT16 _pad1[13];
- UINT32 subkeys_offset;
- UINT32 _pad2;
- UINT32 n_key_values;
- UINT32 key_values_offset;
- UINT32 _pad3[7];
- UINT16 key_name_len;
- UINT16 _pad4;
+ uint16_t sig;
+ uint16_t _pad1[13];
+ uint32_t subkeys_offset;
+ uint32_t _pad2;
+ uint32_t n_key_values;
+ uint32_t key_values_offset;
+ uint32_t _pad3[7];
+ uint16_t key_name_len;
+ uint16_t _pad4;
CHAR8 key_name[];
} _packed_ Key;
assert_cc(offsetof(Key, sig) == 0);
@@ -81,10 +77,10 @@ assert_cc(offsetof(Key, key_name_len) == 72);
assert_cc(offsetof(Key, key_name) == 76);
typedef struct {
- UINT16 sig;
- UINT16 n_entries;
+ uint16_t sig;
+ uint16_t n_entries;
struct SubkeyFastEntry {
- UINT32 key_offset;
+ uint32_t key_offset;
CHAR8 name_hint[4];
} _packed_ entries[];
} _packed_ SubkeyFast;
@@ -93,12 +89,12 @@ assert_cc(offsetof(SubkeyFast, n_entries) == 2);
assert_cc(offsetof(SubkeyFast, entries) == 4);
typedef struct {
- UINT16 sig;
- UINT16 name_len;
- UINT32 data_size;
- UINT32 data_offset;
- UINT32 data_type;
- UINT32 _pad;
+ uint16_t sig;
+ uint16_t name_len;
+ uint32_t data_size;
+ uint32_t data_offset;
+ uint32_t data_type;
+ uint32_t _pad;
CHAR8 name[];
} _packed_ KeyValue;
assert_cc(offsetof(KeyValue, sig) == 0);
@@ -109,18 +105,18 @@ assert_cc(offsetof(KeyValue, data_type) == 12);
assert_cc(offsetof(KeyValue, name) == 20);
#define BAD_OFFSET(offset, len, max) \
- ((UINT64) (offset) + (len) >= (max))
+ ((uint64_t) (offset) + (len) >= (max))
#define BAD_STRUCT(type, offset, max) \
- ((UINT64) (offset) + sizeof(type) >= (max))
+ ((uint64_t) (offset) + sizeof(type) >= (max))
#define BAD_ARRAY(type, array, offset, array_len, max) \
- ((UINT64) (offset) + offsetof(type, array) + \
- sizeof((type){}.array[0]) * (UINT64) (array_len) >= (max))
+ ((uint64_t) (offset) + offsetof(type, array) + \
+ sizeof((type){}.array[0]) * (uint64_t) (array_len) >= (max))
-static const Key *get_key(const UINT8 *bcd, UINT32 bcd_len, UINT32 offset, const CHAR8 *name);
+static const Key *get_key(const uint8_t *bcd, uint32_t bcd_len, uint32_t offset, const CHAR8 *name);
-static const Key *get_subkey(const UINT8 *bcd, UINT32 bcd_len, UINT32 offset, const CHAR8 *name) {
+static const Key *get_subkey(const uint8_t *bcd, uint32_t bcd_len, uint32_t offset, const CHAR8 *name) {
assert(bcd);
assert(name);
@@ -134,7 +130,7 @@ static const Key *get_subkey(const UINT8 *bcd, UINT32 bcd_len, UINT32 offset, co
if (BAD_ARRAY(SubkeyFast, entries, offset, subkey->n_entries, bcd_len))
return NULL;
- for (UINT16 i = 0; i < subkey->n_entries; i++) {
+ for (uint16_t i = 0; i < subkey->n_entries; i++) {
if (!strncaseeq8((char *) name, (char *) subkey->entries[i].name_hint, sizeof(subkey->entries[i].name_hint)))
continue;
@@ -149,7 +145,7 @@ static const Key *get_subkey(const UINT8 *bcd, UINT32 bcd_len, UINT32 offset, co
/* We use NUL as registry path separators for convenience. To start from the root, begin
* name with a NUL. Name must end with two NUL. The lookup depth is not restricted, so
* name must be properly validated before calling get_key(). */
-static const Key *get_key(const UINT8 *bcd, UINT32 bcd_len, UINT32 offset, const CHAR8 *name) {
+static const Key *get_key(const uint8_t *bcd, uint32_t bcd_len, uint32_t offset, const CHAR8 *name) {
assert(bcd);
assert(name);
@@ -174,7 +170,7 @@ static const Key *get_key(const UINT8 *bcd, UINT32 bcd_len, UINT32 offset, const
return *name ? get_subkey(bcd, bcd_len, key->subkeys_offset, name) : key;
}
-static const KeyValue *get_key_value(const UINT8 *bcd, UINT32 bcd_len, const Key *key, const CHAR8 *name) {
+static const KeyValue *get_key_value(const uint8_t *bcd, uint32_t bcd_len, const Key *key, const CHAR8 *name) {
assert(bcd);
assert(key);
assert(name);
@@ -182,13 +178,13 @@ static const KeyValue *get_key_value(const UINT8 *bcd, UINT32 bcd_len, const Key
if (key->n_key_values == 0)
return NULL;
- if (BAD_OFFSET(key->key_values_offset, sizeof(UINT32) * (UINT64) key->n_key_values, bcd_len) ||
- (UINTN)(bcd + key->key_values_offset) % sizeof(UINT32) != 0)
+ 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)
return NULL;
- const UINT32 *key_value_list = (const UINT32 *) (bcd + key->key_values_offset);
- for (UINT32 i = 0; i < key->n_key_values; i++) {
- UINT32 offset = *(key_value_list + i);
+ const uint32_t *key_value_list = (const uint32_t *) (bcd + key->key_values_offset);
+ for (uint32_t i = 0; i < key->n_key_values; i++) {
+ uint32_t offset = *(key_value_list + i);
if (BAD_STRUCT(KeyValue, offset, bcd_len))
continue;
@@ -233,7 +229,7 @@ static const KeyValue *get_key_value(const UINT8 *bcd, UINT32 bcd_len, const Key
* (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 *bcd, UINTN bcd_len) {
+TEST_STATIC CHAR16 *get_bcd_title(uint8_t *bcd, UINTN bcd_len) {
assert(bcd);
if (HIVE_CELL_OFFSET >= bcd_len)