Skip to content

Commit

Permalink
multiboot: make GRUB_MULTIBOOT(make_mbi) return MBI's size
Browse files Browse the repository at this point in the history
GRUB_MULTIBOOT(get_mbi_size) doesn't look like an accurate source of the
final size, more like a minimal memory buffer size.

Signed-off-by: Sergii Dmytruk <[email protected]>
  • Loading branch information
SergiiDmytruk committed Nov 22, 2023
1 parent ee8e036 commit ba8dbc9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion grub-core/loader/i386/multiboot_mbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ retrieve_video_parameters (struct multiboot_info *mbi,
}

grub_err_t
grub_multiboot_make_mbi (grub_uint32_t *target)
grub_multiboot_make_mbi (grub_uint32_t *target, grub_uint32_t *size)
{
struct multiboot_info *mbi;
struct multiboot_mod_list *modlist;
Expand Down Expand Up @@ -618,6 +618,8 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
return err;
#endif

*size = (char *) ptrorig - (char *) mbi;

return GRUB_ERR_NONE;
}

Expand Down
3 changes: 2 additions & 1 deletion grub-core/loader/multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ static grub_err_t
grub_multiboot_boot (void)
{
grub_err_t err;
grub_uint32_t mbi_size;

#ifdef GRUB_USE_MULTIBOOT2
struct grub_relocator32_state state = MULTIBOOT2_INITIAL_STATE;
Expand All @@ -210,7 +211,7 @@ grub_multiboot_boot (void)
#endif
state.MULTIBOOT_ENTRY_REGISTER = GRUB_MULTIBOOT (payload_eip);

err = GRUB_MULTIBOOT (make_mbi) (&state.MULTIBOOT_MBI_REGISTER);
err = GRUB_MULTIBOOT (make_mbi) (&state.MULTIBOOT_MBI_REGISTER, &mbi_size);

if (err)
return err;
Expand Down
6 changes: 4 additions & 2 deletions grub-core/loader/multiboot_mbi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ retrieve_video_parameters (grub_properly_aligned_t **ptrorig)
}

grub_err_t
grub_multiboot2_make_mbi (grub_uint32_t *target)
grub_multiboot2_make_mbi (grub_uint32_t *target, grub_uint32_t *size)
{
grub_properly_aligned_t *ptrorig;
grub_properly_aligned_t *mbistart;
Expand Down Expand Up @@ -1041,7 +1041,9 @@ grub_multiboot2_make_mbi (grub_uint32_t *target)
/ sizeof (grub_properly_aligned_t);
}

((grub_uint32_t *) mbistart)[0] = (char *) ptrorig - (char *) mbistart;
*size = (char *) ptrorig - (char *) mbistart;

((grub_uint32_t *) mbistart)[0] = *size;
((grub_uint32_t *) mbistart)[1] = 0;

return GRUB_ERR_NONE;
Expand Down
2 changes: 1 addition & 1 deletion include/grub/multiboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void grub_multiboot (int argc, char *argv[]);
void grub_module (int argc, char *argv[]);

void grub_multiboot_set_accepts_video (int val);
grub_err_t grub_multiboot_make_mbi (grub_uint32_t *target);
grub_err_t grub_multiboot_make_mbi (grub_uint32_t *target, grub_uint32_t *size);
void grub_multiboot_free_mbi (void);
grub_err_t grub_multiboot_init_mbi (int argc, char *argv[]);
grub_err_t grub_multiboot_add_module (grub_addr_t start, grub_size_t size,
Expand Down
3 changes: 2 additions & 1 deletion include/grub/multiboot2.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ void grub_multiboot2 (int argc, char *argv[]);
void grub_module2 (int argc, char *argv[]);

void grub_multiboot2_set_accepts_video (int val);
grub_err_t grub_multiboot2_make_mbi (grub_uint32_t *target);
grub_err_t grub_multiboot2_make_mbi (grub_uint32_t *target,
grub_uint32_t *size);
void grub_multiboot2_free_mbi (void);
grub_err_t grub_multiboot2_init_mbi (int argc, char *argv[]);
grub_err_t grub_multiboot2_add_module (grub_addr_t start, grub_size_t size,
Expand Down

0 comments on commit ba8dbc9

Please sign in to comment.