From: "Vladimir 'phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: [PATCH 3/4] types: Split aligned and packed guids
Date: Tue, 31 Oct 2023 20:35:26 +0100 [thread overview]
Message-ID: <CAEaD8JP5GAcjvk7g+sWOr+gRwZH16Mmd0Ar2wk=JvLtKczFozw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 376 bytes --]
On ia64 alignment requirements are strict. When we pass a pointer to
UUID it needs to be at least 4-byte aligned or EFI will crash.
On the other hand in device path there is no padding for UUID, so we
need 2 types in one formor another. Make 4-byte aligned and unaligned types
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
--
Regards
Vladimir 'phcoder' Serbinenko
[-- Attachment #2: 0003-types-Split-aligned-and-packed-guids.patch --]
[-- Type: text/x-patch, Size: 10725 bytes --]
From 48c239ad9efc40563015052383d80830d410c2c8 Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <phcoder@gmail.com>
Date: Sun, 13 Aug 2023 09:18:23 +0200
Subject: [PATCH 3/4] types: Split aligned and packed guids
On ia64 alignment requirements are strict. When we pass a pointer to
UUID it needs to be at least 4-byte aligned or EFI will crash.
On the other hand in device path there is no padding for UUID, so we
need 2 types in one formor another. Make 4-byte aligned and unaligned types
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
---
grub-core/commands/efi/lsefi.c | 2 +-
grub-core/efiemu/runtime/efiemu.c | 33 +++++++++++++++++++++----------
grub-core/kern/efi/efi.c | 2 +-
grub-core/kern/misc.c | 2 +-
grub-core/loader/i386/xnu.c | 2 +-
include/grub/efi/api.h | 12 +++++------
include/grub/efiemu/efiemu.h | 4 ++--
include/grub/efiemu/runtime.h | 2 +-
include/grub/types.h | 11 ++++++++++-
9 files changed, 46 insertions(+), 24 deletions(-)
diff --git a/grub-core/commands/efi/lsefi.c b/grub-core/commands/efi/lsefi.c
index 95cba5baf..7b8316d41 100644
--- a/grub-core/commands/efi/lsefi.c
+++ b/grub-core/commands/efi/lsefi.c
@@ -96,7 +96,7 @@ grub_cmd_lsefi (grub_command_t cmd __attribute__ ((unused)),
grub_efi_handle_t handle = handles[i];
grub_efi_status_t status;
grub_efi_uintn_t num_protocols;
- grub_guid_t **protocols;
+ grub_packed_guid_t **protocols;
grub_efi_device_path_t *dp;
grub_printf ("Handle %p\n", handle);
diff --git a/grub-core/efiemu/runtime/efiemu.c b/grub-core/efiemu/runtime/efiemu.c
index c84b30652..f6b6d19f7 100644
--- a/grub-core/efiemu/runtime/efiemu.c
+++ b/grub-core/efiemu/runtime/efiemu.c
@@ -66,7 +66,7 @@ efiemu_convert_pointer (grub_efi_uintn_t debug_disposition,
grub_efi_status_t __grub_efi_api
efiemu_get_variable (grub_efi_char16_t *variable_name,
- const grub_guid_t *vendor_guid,
+ const grub_packed_guid_t *vendor_guid,
grub_efi_uint32_t *attributes,
grub_efi_uintn_t *data_size,
void *data);
@@ -74,11 +74,11 @@ efiemu_get_variable (grub_efi_char16_t *variable_name,
grub_efi_status_t __grub_efi_api
efiemu_get_next_variable_name (grub_efi_uintn_t *variable_name_size,
grub_efi_char16_t *variable_name,
- grub_guid_t *vendor_guid);
+ grub_packed_guid_t *vendor_guid);
grub_efi_status_t __grub_efi_api
efiemu_set_variable (grub_efi_char16_t *variable_name,
- const grub_guid_t *vendor_guid,
+ const grub_packed_guid_t *vendor_guid,
grub_efi_uint32_t attributes,
grub_efi_uintn_t data_size,
void *data);
@@ -416,7 +416,7 @@ EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,
/* Find variable by name and GUID. */
static struct efi_variable *
-find_variable (const grub_guid_t *vendor_guid,
+find_variable (const grub_packed_guid_t *vendor_guid,
grub_efi_char16_t *variable_name)
{
grub_uint8_t *ptr;
@@ -438,7 +438,7 @@ find_variable (const grub_guid_t *vendor_guid,
grub_efi_status_t __grub_efi_api
EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
- const grub_guid_t *vendor_guid,
+ const grub_packed_guid_t *vendor_guid,
grub_efi_uint32_t *attributes,
grub_efi_uintn_t *data_size,
void *data)
@@ -464,7 +464,7 @@ EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
grub_efi_status_t __grub_efi_api EFI_FUNC
(efiemu_get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
grub_efi_char16_t *variable_name,
- grub_guid_t *vendor_guid)
+ grub_packed_guid_t *vendor_guid)
{
struct efi_variable *efivar;
LOG ('l');
@@ -503,7 +503,7 @@ grub_efi_status_t __grub_efi_api EFI_FUNC
grub_efi_status_t __grub_efi_api
EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
- const grub_guid_t *vendor_guid,
+ const grub_packed_guid_t *vendor_guid,
grub_efi_uint32_t attributes,
grub_efi_uintn_t data_size,
void *data)
@@ -597,9 +597,22 @@ struct grub_efi_runtime_services efiemu_runtime_services =
.set_virtual_address_map = efiemu_set_virtual_address_map,
.convert_pointer = efiemu_convert_pointer,
- .get_variable = efiemu_get_variable,
- .get_next_variable_name = efiemu_get_next_variable_name,
- .set_variable = efiemu_set_variable,
+ .get_variable = (grub_efi_status_t
+ (__grub_efi_api *) (grub_efi_char16_t *variable_name,
+ const grub_guid_t *vendor_guid,
+ grub_efi_uint32_t *attributes,
+ grub_efi_uintn_t *data_size,
+ void *data)) efiemu_get_variable,
+ .get_next_variable_name = (grub_efi_status_t
+ (__grub_efi_api *) (grub_efi_uintn_t *variable_name_size,
+ grub_efi_char16_t *variable_name,
+ grub_guid_t *vendor_guid)) efiemu_get_next_variable_name,
+ .set_variable = (grub_efi_status_t
+ (__grub_efi_api *) (grub_efi_char16_t *variable_name,
+ const grub_guid_t *vendor_guid,
+ grub_efi_uint32_t attributes,
+ grub_efi_uintn_t data_size,
+ void *data)) efiemu_set_variable,
.get_next_high_monotonic_count = efiemu_get_next_high_monotonic_count,
.reset_system = efiemu_reset_system
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index e53808307..b93ae3aba 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -1039,7 +1039,7 @@ grub_efi_find_configuration_table (const grub_guid_t *target_guid)
for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
{
- grub_guid_t *guid =
+ grub_packed_guid_t *guid =
&grub_efi_system_table->configuration_table[i].vendor_guid;
if (! grub_memcmp (guid, target_guid, sizeof (grub_guid_t)))
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index b57249acb..7cee5d75c 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -1068,7 +1068,7 @@ grub_vsnprintf_real (char *str, grub_size_t max_len, const char *fmt0,
if (*(fmt) == 'G')
{
++fmt;
- grub_guid_t *guid = (grub_guid_t *)(grub_addr_t) curarg;
+ grub_packed_guid_t *guid = (grub_packed_guid_t *)(grub_addr_t) curarg;
write_number (str, &count, max_len, 8, 0, '0', 'x', guid->data1);
write_char (str, &count, max_len, '-');
write_number (str, &count, max_len, 4, 0, '0', 'x', guid->data2);
diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c
index 4e31ce99a..b91e2f840 100644
--- a/grub-core/loader/i386/xnu.c
+++ b/grub-core/loader/i386/xnu.c
@@ -694,7 +694,7 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out)
{
void *ptr;
struct grub_xnu_devtree_key *curkey;
- grub_guid_t guid;
+ grub_packed_guid_t guid;
char guidbuf[64];
/* Retrieve current key. */
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
index d3eaef3fb..d44d00ad7 100644
--- a/include/grub/efi/api.h
+++ b/include/grub/efi/api.h
@@ -730,7 +730,7 @@ typedef struct grub_efi_memory_mapped_device_path grub_efi_memory_mapped_device_
struct grub_efi_vendor_device_path
{
grub_efi_device_path_t header;
- grub_guid_t vendor_guid;
+ grub_packed_guid_t vendor_guid;
grub_efi_uint8_t vendor_defined_data[0];
} GRUB_PACKED;
typedef struct grub_efi_vendor_device_path grub_efi_vendor_device_path_t;
@@ -974,7 +974,7 @@ typedef struct grub_efi_cdrom_device_path grub_efi_cdrom_device_path_t;
struct grub_efi_vendor_media_device_path
{
grub_efi_device_path_t header;
- grub_guid_t vendor_guid;
+ grub_packed_guid_t vendor_guid;
grub_efi_uint8_t vendor_defined_data[0];
} GRUB_PACKED;
typedef struct grub_efi_vendor_media_device_path grub_efi_vendor_media_device_path_t;
@@ -993,7 +993,7 @@ typedef struct grub_efi_file_path_device_path grub_efi_file_path_device_path_t;
struct grub_efi_protocol_device_path
{
grub_efi_device_path_t header;
- grub_guid_t guid;
+ grub_packed_guid_t guid;
} GRUB_PACKED;
typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
@@ -1002,7 +1002,7 @@ typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t;
struct grub_efi_piwg_device_path
{
grub_efi_device_path_t header;
- grub_guid_t guid;
+ grub_packed_guid_t guid;
} GRUB_PACKED;
typedef struct grub_efi_piwg_device_path grub_efi_piwg_device_path_t;
@@ -1287,7 +1287,7 @@ struct grub_efi_boot_services
grub_efi_status_t
(__grub_efi_api *protocols_per_handle) (grub_efi_handle_t handle,
- grub_guid_t ***protocol_buffer,
+ grub_packed_guid_t ***protocol_buffer,
grub_efi_uintn_t *protocol_buffer_count);
grub_efi_status_t
@@ -1386,7 +1386,7 @@ typedef struct grub_efi_runtime_services grub_efi_runtime_services_t;
struct grub_efi_configuration_table
{
- grub_guid_t vendor_guid;
+ grub_packed_guid_t vendor_guid;
void *vendor_table;
} GRUB_PACKED;
typedef struct grub_efi_configuration_table grub_efi_configuration_table_t;
diff --git a/include/grub/efiemu/efiemu.h b/include/grub/efiemu/efiemu.h
index caf0b505f..d6a868e94 100644
--- a/include/grub/efiemu/efiemu.h
+++ b/include/grub/efiemu/efiemu.h
@@ -183,13 +183,13 @@ struct grub_efiemu_configuration_table
};
struct grub_efiemu_configuration_table32
{
- grub_guid_t vendor_guid;
+ grub_packed_guid_t vendor_guid;
grub_efi_uint32_t vendor_table;
} GRUB_PACKED;
typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t;
struct grub_efiemu_configuration_table64
{
- grub_guid_t vendor_guid;
+ grub_packed_guid_t vendor_guid;
grub_efi_uint64_t vendor_table;
} GRUB_PACKED;
typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t;
diff --git a/include/grub/efiemu/runtime.h b/include/grub/efiemu/runtime.h
index c9ad9fdfa..2ff429845 100644
--- a/include/grub/efiemu/runtime.h
+++ b/include/grub/efiemu/runtime.h
@@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel
struct efi_variable
{
- grub_guid_t guid;
+ grub_packed_guid_t guid;
grub_uint32_t namelen;
grub_uint32_t size;
grub_efi_uint32_t attributes;
diff --git a/include/grub/types.h b/include/grub/types.h
index 45536a661..064066e2e 100644
--- a/include/grub/types.h
+++ b/include/grub/types.h
@@ -376,7 +376,16 @@ struct grub_guid
grub_uint16_t data2;
grub_uint16_t data3;
grub_uint8_t data4[8];
-} GRUB_PACKED;
+} __attribute__ ((aligned(4)));
typedef struct grub_guid grub_guid_t;
+struct grub_packed_guid
+{
+ grub_uint32_t data1;
+ grub_uint16_t data2;
+ grub_uint16_t data3;
+ grub_uint8_t data4[8];
+} GRUB_PACKED;
+typedef struct grub_packed_guid grub_packed_guid_t;
+
#endif /* ! GRUB_TYPES_HEADER */
--
2.39.2
[-- Attachment #3: Type: text/plain, Size: 141 bytes --]
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next reply other threads:[~2023-10-31 19:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-31 19:35 Vladimir 'phcoder' Serbinenko [this message]
2023-10-31 21:43 ` [PATCH 3/4] types: Split aligned and packed guids John Paul Adrian Glaubitz
2023-11-06 17:49 ` Daniel Kiper
2023-11-06 21:59 ` Vladimir 'phcoder' Serbinenko
2023-11-07 18:32 ` Daniel Kiper
-- strict thread matches above, loose matches on Subject: below --
2023-10-07 15:06 Vladimir 'phcoder' Serbinenko
2023-10-17 16:41 ` Daniel Kiper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAEaD8JP5GAcjvk7g+sWOr+gRwZH16Mmd0Ar2wk=JvLtKczFozw@mail.gmail.com' \
--to=phcoder@gmail.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).