diff --git a/include/grub/mm_private.h b/include/grub/mm_private.h index 203533cc3..a688b92a8 100644 --- a/include/grub/mm_private.h +++ b/include/grub/mm_private.h @@ -20,6 +20,7 @@ #define GRUB_MM_PRIVATE_H 1 #include +#include /* For context, see kern/mm.c */ @@ -89,4 +90,17 @@ typedef struct grub_mm_region extern grub_mm_region_t EXPORT_VAR (grub_mm_base); #endif +static inline void +grub_mm_size_sanity_check (void) { + /* Ensure we preserve alignment when doing h = (grub_mm_header_t) (r + 1). */ + COMPILE_TIME_ASSERT ((sizeof (struct grub_mm_region) % + sizeof (struct grub_mm_header)) == 0); + + /* + * GRUB_MM_ALIGN is supposed to represent cell size, and a mm_header is + * supposed to be 1 cell. + */ + COMPILE_TIME_ASSERT (sizeof (struct grub_mm_header) == GRUB_MM_ALIGN); +} + #endif