From 8c9a43f9fbd69a022f4a0913192e7bbc847e1af5 Mon Sep 17 00:00:00 2001 From: Sylvain Gault Date: Mon, 3 Feb 2014 05:43:02 +0100 Subject: [PATCH] efi: Fix PE header field rva_and_sizes_nr The value of the field rva_and_sizes_nr is used by OVMF to check the consistency of the PE file with respect to the field optional_hdr_sz. It now have the right value. Signed-off-by: Sylvain Gault Signed-off-by: H. Peter Anvin --- efi/wrapper.c | 6 +++--- efi/wrapper.h | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/efi/wrapper.c b/efi/wrapper.c index 04c895f6e..ec77271be 100644 --- a/efi/wrapper.c +++ b/efi/wrapper.c @@ -102,7 +102,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, e_hdr.image_sz = total_sz; e_hdr.headers_sz = 512; e_hdr.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; - e_hdr.rva_and_sizes_nr = 1; + e_hdr.rva_and_sizes_nr = sizeof(e_hdr.data_directory) / sizeof(__uint64_t); fwrite(&e_hdr, sizeof(e_hdr), 1, f); } else if (class == ELFCLASS64) { @@ -130,7 +130,7 @@ static void write_header(FILE *f, __uint32_t entry, size_t data_size, e_hdr_pe32p.image_sz = total_sz; e_hdr_pe32p.headers_sz = 512; e_hdr_pe32p.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION; - e_hdr_pe32p.rva_and_sizes_nr = 1; + e_hdr_pe32p.rva_and_sizes_nr = sizeof(e_hdr_pe32p.data_directory) / sizeof(__uint64_t); fwrite(&e_hdr_pe32p, sizeof(e_hdr_pe32p), 1, f); } @@ -237,7 +237,7 @@ int main(int argc, char **argv) fprintf(stderr, "Unsupported architecture\n"); exit(EXIT_FAILURE); } - + if (id[EI_MAG0] != ELFMAG0 || id[EI_MAG1] != ELFMAG1 || id[EI_MAG2] != ELFMAG2 || diff --git a/efi/wrapper.h b/efi/wrapper.h index 4f769914c..0e6b38ea7 100644 --- a/efi/wrapper.h +++ b/efi/wrapper.h @@ -102,12 +102,14 @@ struct extra_hdr { __uint32_t heap_commit_sz; __uint32_t loader_flags; __uint32_t rva_and_sizes_nr; - __uint64_t export_table; - __uint64_t import_table; - __uint64_t resource_table; - __uint64_t exception_table; - __uint64_t certification_table; - __uint64_t base_relocation_table; + struct { + __uint64_t export_table; + __uint64_t import_table; + __uint64_t resource_table; + __uint64_t exception_table; + __uint64_t certification_table; + __uint64_t base_relocation_table; + } data_directory; } __packed; /* Extra header for PE32+ format @@ -136,12 +138,14 @@ struct extra_hdr_pe32p { __uint64_t heap_commit_sz; __uint32_t loader_flags; __uint32_t rva_and_sizes_nr; - __uint64_t export_table; - __uint64_t import_table; - __uint64_t resource_table; - __uint64_t exception_table; - __uint64_t certification_table; - __uint64_t base_relocation_table; + struct { + __uint64_t export_table; + __uint64_t import_table; + __uint64_t resource_table; + __uint64_t exception_table; + __uint64_t certification_table; + __uint64_t base_relocation_table; + } data_directory; } __packed; struct section {