Skip to content

Commit

Permalink
efi: Fix PE header field rva_and_sizes_nr
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: H. Peter Anvin <[email protected]>
  • Loading branch information
Sylvain Gault authored and H. Peter Anvin committed Feb 15, 2014
1 parent 8c11d92 commit 8c9a43f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions efi/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 ||
Expand Down
28 changes: 16 additions & 12 deletions efi/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8c9a43f

Please sign in to comment.