Debian Codegraph @

src/boot/pe.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "efi.h"
5
6 /* PE flags in the Characteristics attribute of the optional header indicating executable code */
7 #define PE_CODE 0x00000020U
8 #define PE_EXECUTE 0x20000000U
9
10 /* This is the actual PE format of the section header */
11 typedef struct PeSectionHeader {
12 uint8_t Name[8];
13 uint32_t VirtualSize;
14 uint32_t VirtualAddress;
15 uint32_t SizeOfRawData;
16 uint32_t PointerToRawData;
17 uint32_t PointerToRelocations;
18 uint32_t PointerToLinenumbers;
19 uint16_t NumberOfRelocations;
20 uint16_t NumberOfLinenumbers;
21 uint32_t Characteristics;
22 } _packed_ PeSectionHeader;
23
24 /* This is a subset of the full PE section header structure, with validated values, and without
25 * the noise. */
26 typedef struct PeSectionVector {
27 size_t memory_size; /* Size of the section in memory (corresponds to VirtualSize field) */
28 size_t memory_offset; /* Offset in memory, relative to base address */
29 uint64_t file_size; /* Amount of bytes of the section read from disk (possibly aligned to FileAlignment in case VirtualSize > SizeOfRawData). */
30 uint64_t file_offset; /* Offset on disk, relative to beginning of file */
31 } PeSectionVector;
32
33 static inline bool PE_SECTION_VECTOR_IS_SET(const PeSectionVector *v) {
34 return v && v->memory_size != 0;
35 }
36
37 EFI_STATUS pe_section_table_from_base(
38 const void *base,
39 const PeSectionHeader **ret_section_table,
40 size_t *ret_n_section_table);
41
42 EFI_STATUS pe_section_table_from_file(
43 EFI_FILE *handle,
44 PeSectionHeader **ret_section_table,
45 size_t *ret_n_section_table);
46
47 EFI_STATUS pe_locate_profile_sections(
48 const PeSectionHeader section_table[],
49 size_t n_section_table,
50 const char* const section_names[],
51 unsigned profile,
52 size_t validate_base,
53 PeSectionVector sections[]);
54
55 EFI_STATUS pe_memory_locate_sections(
56 const void *base,
57 const char *const section_names[],
58 PeSectionVector sections[]);
59
60 EFI_STATUS pe_kernel_info(const void *base, uint32_t *ret_entry_point, uint32_t *ret_compat_entry_point, size_t *ret_size_in_memory);
61
62 EFI_STATUS pe_kernel_check_no_relocation(const void *base);
63
64 bool pe_kernel_check_nx_compat(const void *base);