diff --git a/ChangeLog b/ChangeLog index 57d7dfb3e..60348fde1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2012-03-04 Vladimir Serbinenko + + * include/grub/misc.h (ALIGN_UP_OVERHEAD): New define. + * grub-core/loader/i386/linux.c (grub_cmd_initrd): Align initrds at 4. + * grub-core/loader/i386/pc/linux.c (grub_cmd_initrd): Likewise. + * grub-core/loader/ia64/efi/linux.c (grub_cmd_initrd): Likewise. + * grub-core/loader/mips/linux.c (grub_cmd_initrd): Likewise. + * grub-core/loader/powerpc/ieee1275/linux.c (grub_cmd_initrd): Likewise. + * grub-core/loader/sparc64/ieee1275/linux.c (grub_cmd_initrd): Likewise. + 2012-03-04 Vladimir Serbinenko * grub-core/commands/menuentry.c (options): Remove diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index bc1c81fb8..df133c2cb 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -1034,7 +1034,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (! files[i]) goto fail; nfiles++; - size += grub_file_size (files[i]); + size += ALIGN_UP (grub_file_size (files[i]), 4); } initrd_pages = (page_align (size) >> 12); @@ -1101,6 +1101,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } ptr += cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); + ptr += ALIGN_UP_OVERHEAD (cursize, 4); } grub_dprintf ("linux", "Initrd, addr=0x%x, size=0x%x\n", diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c index 90497c0cc..4eeb1b6c2 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -421,7 +421,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (! files[i]) goto fail; nfiles++; - size += grub_file_size (files[i]); + size += ALIGN_UP (grub_file_size (files[i]), 4); } { @@ -449,6 +449,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } ptr += cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); + ptr += ALIGN_UP_OVERHEAD (cursize, 4); } lh->ramdisk_image = initrd_addr; diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c index 5301fa67a..17843fdbf 100644 --- a/grub-core/loader/ia64/efi/linux.c +++ b/grub-core/loader/ia64/efi/linux.c @@ -597,7 +597,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (! files[i]) goto fail; nfiles++; - initrd_size += grub_file_size (files[i]); + initrd_size += ALIGN_UP (grub_file_size (files[i]), 4); grub_dprintf ("linux", "File %d: %s\n", i, argv[i]); } @@ -624,6 +624,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } ptr += cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); + ptr += ALIGN_UP_OVERHEAD (cursize, 4); } fail: for (i = 0; i < nfiles; i++) diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c index 2b7df0a78..f2cf7ccfc 100644 --- a/grub-core/loader/mips/linux.c +++ b/grub-core/loader/mips/linux.c @@ -468,7 +468,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (! files[i]) goto fail; nfiles++; - size += grub_file_size (files[i]); + size += ALIGN_UP (grub_file_size (files[i]), 4); } { @@ -499,6 +499,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } ptr += cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); + ptr += ALIGN_UP_OVERHEAD (cursize, 4); } #ifdef GRUB_MACHINE_MIPS_QEMU_MIPS diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c index 3929b0f37..5cfa988f6 100644 --- a/grub-core/loader/powerpc/ieee1275/linux.c +++ b/grub-core/loader/powerpc/ieee1275/linux.c @@ -350,7 +350,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (! files[i]) goto fail; nfiles++; - size += grub_file_size (files[i]); + size += ALIGN_UP (grub_file_size (files[i]), 4); } first_addr = linux_addr + linux_size; @@ -376,6 +376,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } ptr += cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); + ptr += ALIGN_UP_OVERHEAD (cursize, 4); } initrd_addr = addr; diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c index 351a74cb5..06d1df6ae 100644 --- a/grub-core/loader/sparc64/ieee1275/linux.c +++ b/grub-core/loader/sparc64/ieee1275/linux.c @@ -403,7 +403,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), if (! files[i]) goto fail; nfiles++; - size += grub_file_size (files[i]); + size += ALIGN_UP(grub_file_size (files[i]), 4); } addr = 0x60000000; @@ -438,6 +438,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), goto fail; } ptr += cursize; + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); + ptr += ALIGN_UP_OVERHEAD (cursize, 4); } initrd_addr = addr; diff --git a/include/grub/misc.h b/include/grub/misc.h index e3d61d75b..a87c43691 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -44,6 +44,7 @@ #define ALIGN_UP(addr, align) \ ((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1)) +#define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((typeof (addr)) (align) - 1)) #define ALIGN_DOWN(addr, align) \ ((addr) & ~((typeof (addr)) align - 1)) #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))