section->raw_data_offset = grub_host_to_target32 (*rda);
section->raw_data_size = grub_host_to_target32 (rsz);
- (*rda) = ALIGN_UP (*rda + rsz, GRUB_PE32_FILE_ALIGNMENT);
+ (*rda) = *rda + rsz;
section->characteristics = grub_host_to_target32 (characteristics);
char *pe_img, *pe_sbat, *header;
struct grub_pe32_section_table *section;
size_t n_sections = 4;
- size_t scn_size;
+ size_t scn_size, raw_size;
grub_uint32_t vma, raw_data;
size_t pe_size, header_size;
struct grub_pe32_coff_header *c;
GRUB_PE32_SCN_MEM_EXECUTE |
GRUB_PE32_SCN_MEM_READ);
- scn_size = ALIGN_UP (layout.kernel_size - layout.exec_size, GRUB_PE32_FILE_ALIGNMENT);
+ raw_size = layout.kernel_size - layout.exec_size;
+ scn_size = ALIGN_UP (raw_size, GRUB_PE32_FILE_ALIGNMENT);
/* ALIGN_UP (sbat_size, GRUB_PE32_FILE_ALIGNMENT) is done earlier. */
PE_OHDR (o32, o64, data_size) = grub_host_to_target32 (scn_size + sbat_size +
ALIGN_UP (total_module_size,
section = init_pe_section (image_target, section, ".data",
&vma, scn_size, image_target->section_align,
- &raw_data, scn_size,
+ &raw_data, raw_size,
GRUB_PE32_SCN_CNT_INITIALIZED_DATA |
GRUB_PE32_SCN_MEM_READ |
GRUB_PE32_SCN_MEM_WRITE);
- scn_size = pe_size - layout.reloc_size - sbat_size - raw_data;
+ raw_size = pe_size - layout.reloc_size - sbat_size - raw_data;
+ scn_size = ALIGN_UP (raw_size, GRUB_PE32_FILE_ALIGNMENT);
section = init_pe_section (image_target, section, "mods",
&vma, scn_size, image_target->section_align,
- &raw_data, scn_size,
+ &raw_data, raw_size,
GRUB_PE32_SCN_CNT_INITIALIZED_DATA |
GRUB_PE32_SCN_MEM_READ |
GRUB_PE32_SCN_MEM_WRITE);
pe_sbat = pe_img + raw_data;
grub_util_load_image (sbat_path, pe_sbat);
+ scn_size = ALIGN_UP (sbat_size, GRUB_PE32_FILE_ALIGNMENT);
section = init_pe_section (image_target, section, ".sbat",
- &vma, sbat_size,
+ &vma, scn_size,
image_target->section_align,
&raw_data, sbat_size,
GRUB_PE32_SCN_CNT_INITIALIZED_DATA |
GRUB_PE32_SCN_MEM_READ);
}
- scn_size = layout.reloc_size;
+ scn_size = ALIGN_UP (layout.reloc_size, GRUB_PE32_FILE_ALIGNMENT);
PE_OHDR (o32, o64, base_relocation_table.rva) = grub_host_to_target32 (vma);
PE_OHDR (o32, o64, base_relocation_table.size) = grub_host_to_target32 (scn_size);
memcpy (pe_img + raw_data, layout.reloc_section, scn_size);
init_pe_section (image_target, section, ".reloc",
&vma, scn_size, image_target->section_align,
- &raw_data, scn_size,
+ &raw_data, layout.reloc_size,
GRUB_PE32_SCN_CNT_INITIALIZED_DATA |
GRUB_PE32_SCN_MEM_DISCARDABLE |
GRUB_PE32_SCN_MEM_READ);