Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 626952
Collapse All | Expand All

(-)a/efi/wrapper.c (-11 / +12 lines)
Lines 17-22 Link Here
17
#include <linux/elf.h>
17
#include <linux/elf.h>
18
#include <sys/types.h>
18
#include <sys/types.h>
19
#include <sys/stat.h>
19
#include <sys/stat.h>
20
#include <stdint.h>
20
#include <stdio.h>
21
#include <stdio.h>
21
#include <stdlib.h>
22
#include <stdlib.h>
22
#include <string.h>
23
#include <string.h>
Lines 43-50 typedef Elf64_Addr Elf_Addr; Link Here
43
 * 	For 64bit machines (class == ELFCLASS64), the optional
44
 * 	For 64bit machines (class == ELFCLASS64), the optional
44
 * 	header includes PE32+header fields
45
 * 	header includes PE32+header fields
45
 */
46
 */
46
static void write_header(FILE *f, __uint32_t entry, size_t data_size,
47
static void write_header(FILE *f, uint32_t entry, size_t data_size,
47
			 __uint32_t so_memsz, __uint8_t class)
48
			 uint32_t so_memsz, uint8_t class)
48
{
49
{
49
	struct optional_hdr o_hdr;
50
	struct optional_hdr o_hdr;
50
	struct optional_hdr_pe32p o_hdr_pe32p;
51
	struct optional_hdr_pe32p o_hdr_pe32p;
Lines 53-61 static void write_header(FILE *f, __uint32_t entry, size_t data_size, Link Here
53
	struct extra_hdr_pe32p e_hdr_pe32p;
54
	struct extra_hdr_pe32p e_hdr_pe32p;
54
	struct coff_hdr c_hdr;
55
	struct coff_hdr c_hdr;
55
	struct header hdr;
56
	struct header hdr;
56
	__uint32_t total_sz = data_size;
57
	uint32_t total_sz = data_size;
57
	__uint32_t hdr_sz;
58
	uint32_t hdr_sz;
58
	__uint32_t reloc_start, reloc_end;
59
	uint32_t reloc_start, reloc_end;
59
60
60
	/*
61
	/*
61
	 * The header size have to be a multiple of file_align, which currently
62
	 * The header size have to be a multiple of file_align, which currently
Lines 103-109 static void write_header(FILE *f, __uint32_t entry, size_t data_size, Link Here
103
		e_hdr.image_sz = hdr_sz + so_memsz;
104
		e_hdr.image_sz = hdr_sz + so_memsz;
104
		e_hdr.headers_sz = hdr_sz;
105
		e_hdr.headers_sz = hdr_sz;
105
		e_hdr.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION;
106
		e_hdr.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION;
106
		e_hdr.rva_and_sizes_nr = sizeof(e_hdr.data_directory) / sizeof(__uint64_t);
107
		e_hdr.rva_and_sizes_nr = sizeof(e_hdr.data_directory) / sizeof(uint64_t);
107
		fwrite(&e_hdr, sizeof(e_hdr), 1, f);
108
		fwrite(&e_hdr, sizeof(e_hdr), 1, f);
108
	}
109
	}
109
	else if (class == ELFCLASS64) {
110
	else if (class == ELFCLASS64) {
Lines 126-132 static void write_header(FILE *f, __uint32_t entry, size_t data_size, Link Here
126
		e_hdr_pe32p.image_sz = hdr_sz + so_memsz;
127
		e_hdr_pe32p.image_sz = hdr_sz + so_memsz;
127
		e_hdr_pe32p.headers_sz = hdr_sz;
128
		e_hdr_pe32p.headers_sz = hdr_sz;
128
		e_hdr_pe32p.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION;
129
		e_hdr_pe32p.subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION;
129
		e_hdr_pe32p.rva_and_sizes_nr = sizeof(e_hdr_pe32p.data_directory) / sizeof(__uint64_t);
130
		e_hdr_pe32p.rva_and_sizes_nr = sizeof(e_hdr_pe32p.data_directory) / sizeof(uint64_t);
130
		fwrite(&e_hdr_pe32p, sizeof(e_hdr_pe32p), 1, f);
131
		fwrite(&e_hdr_pe32p, sizeof(e_hdr_pe32p), 1, f);
131
	}
132
	}
132
133
Lines 163-172 int main(int argc, char **argv) Link Here
163
{
164
{
164
	Elf32_Ehdr e32_hdr;
165
	Elf32_Ehdr e32_hdr;
165
	Elf64_Ehdr e64_hdr;
166
	Elf64_Ehdr e64_hdr;
166
	__uint32_t entry;
167
	uint32_t entry;
167
	__uint8_t class;
168
	uint8_t class;
168
	__uint64_t phoff = 0;
169
	uint64_t phoff = 0;
169
	__uint16_t phnum = 0, phentsize = 0;
170
	uint16_t phnum = 0, phentsize = 0;
170
	unsigned char *id;
171
	unsigned char *id;
171
	FILE *f_in, *f_out;
172
	FILE *f_in, *f_out;
172
	void *buf;
173
	void *buf;
(-)a/efi/wrapper.h (-98 / +98 lines)
Lines 27-39 Link Here
27
#define OFFSETOF(t,m)	((size_t)&((t *)0)->m)
27
#define OFFSETOF(t,m)	((size_t)&((t *)0)->m)
28
28
29
struct header {
29
struct header {
30
	__uint16_t msdos_signature;
30
	uint16_t msdos_signature;
31
	__uint8_t _pad1[0x16];
31
	uint8_t _pad1[0x16];
32
	__uint16_t relocs_ptr;
32
	uint16_t relocs_ptr;
33
	__uint8_t __pad2[0x3c - 0x1a];
33
	uint8_t __pad2[0x3c - 0x1a];
34
	__uint32_t pe_hdr;
34
	uint32_t pe_hdr;
35
	__uint16_t pe_signature;
35
	uint16_t pe_signature;
36
	__uint16_t _pad2;
36
	uint16_t _pad2;
37
} __packed;
37
} __packed;
38
38
39
/* FIXME: when setting up coff_hdr, set up optional_hdr_sz
39
/* FIXME: when setting up coff_hdr, set up optional_hdr_sz
Lines 43-114 struct header { Link Here
43
 * COFF header
43
 * COFF header
44
 */
44
 */
45
struct coff_hdr {
45
struct coff_hdr {
46
	__uint16_t arch;
46
	uint16_t arch;
47
	__uint16_t nr_sections;
47
	uint16_t nr_sections;
48
	__uint32_t timedatestamp;
48
	uint32_t timedatestamp;
49
	__uint32_t symtab;
49
	uint32_t symtab;
50
	__uint32_t nr_syms;
50
	uint32_t nr_syms;
51
	__uint16_t optional_hdr_sz;
51
	uint16_t optional_hdr_sz;
52
	__uint16_t characteristics;
52
	uint16_t characteristics;
53
} __packed;
53
} __packed;
54
54
55
struct optional_hdr {
55
struct optional_hdr {
56
	__uint16_t format;
56
	uint16_t format;
57
	__uint8_t major_linker_version;
57
	uint8_t major_linker_version;
58
	__uint8_t minor_linker_version;
58
	uint8_t minor_linker_version;
59
	__uint32_t code_sz;
59
	uint32_t code_sz;
60
	__uint32_t initialized_data_sz;
60
	uint32_t initialized_data_sz;
61
	__uint32_t uninitialized_data_sz;
61
	uint32_t uninitialized_data_sz;
62
	__uint32_t entry_point;
62
	uint32_t entry_point;
63
	__uint32_t base_code;
63
	uint32_t base_code;
64
	__uint32_t data;
64
	uint32_t data;
65
} __packed;
65
} __packed;
66
66
67
/* For PE32+, the optional_header does NOT have
67
/* For PE32+, the optional_header does NOT have
68
 * data after base_code
68
 * data after base_code
69
 */
69
 */
70
struct optional_hdr_pe32p {
70
struct optional_hdr_pe32p {
71
	__uint16_t format;
71
	uint16_t format;
72
	__uint8_t major_linker_version;
72
	uint8_t major_linker_version;
73
	__uint8_t minor_linker_version;
73
	uint8_t minor_linker_version;
74
	__uint32_t code_sz;
74
	uint32_t code_sz;
75
	__uint32_t initialized_data_sz;
75
	uint32_t initialized_data_sz;
76
	__uint32_t uninitialized_data_sz;
76
	uint32_t uninitialized_data_sz;
77
	__uint32_t entry_point;
77
	uint32_t entry_point;
78
	__uint32_t base_code;
78
	uint32_t base_code;
79
} __packed;
79
} __packed;
80
/*
80
/*
81
 * Extra header fields
81
 * Extra header fields
82
 */
82
 */
83
struct extra_hdr {
83
struct extra_hdr {
84
	__uint32_t image_base;
84
	uint32_t image_base;
85
	__uint32_t section_align;
85
	uint32_t section_align;
86
	__uint32_t file_align;
86
	uint32_t file_align;
87
	__uint16_t major_os_version;
87
	uint16_t major_os_version;
88
	__uint16_t minor_os_version;
88
	uint16_t minor_os_version;
89
	__uint16_t major_image_version;
89
	uint16_t major_image_version;
90
	__uint16_t minor_image_version;
90
	uint16_t minor_image_version;
91
	__uint16_t major_subsystem_version;
91
	uint16_t major_subsystem_version;
92
	__uint16_t minor_subsystem_version;
92
	uint16_t minor_subsystem_version;
93
	__uint32_t win32_version;
93
	uint32_t win32_version;
94
	__uint32_t image_sz;
94
	uint32_t image_sz;
95
	__uint32_t headers_sz;
95
	uint32_t headers_sz;
96
	__uint32_t checksum;
96
	uint32_t checksum;
97
	__uint16_t subsystem;
97
	uint16_t subsystem;
98
	__uint16_t dll_characteristics;
98
	uint16_t dll_characteristics;
99
	__uint32_t stack_reserve_sz;
99
	uint32_t stack_reserve_sz;
100
	__uint32_t stack_commit_sz;
100
	uint32_t stack_commit_sz;
101
	__uint32_t heap_reserve_sz;
101
	uint32_t heap_reserve_sz;
102
	__uint32_t heap_commit_sz;
102
	uint32_t heap_commit_sz;
103
	__uint32_t loader_flags;
103
	uint32_t loader_flags;
104
	__uint32_t rva_and_sizes_nr;
104
	uint32_t rva_and_sizes_nr;
105
	struct {
105
	struct {
106
		__uint64_t export_table;
106
		uint64_t export_table;
107
		__uint64_t import_table;
107
		uint64_t import_table;
108
		__uint64_t resource_table;
108
		uint64_t resource_table;
109
		__uint64_t exception_table;
109
		uint64_t exception_table;
110
		__uint64_t certification_table;
110
		uint64_t certification_table;
111
		__uint64_t base_relocation_table;
111
		uint64_t base_relocation_table;
112
	} data_directory;
112
	} data_directory;
113
} __packed;
113
} __packed;
114
114
Lines 117-170 struct extra_hdr { Link Here
117
 */
117
 */
118
118
119
struct extra_hdr_pe32p {
119
struct extra_hdr_pe32p {
120
	__uint64_t image_base;
120
	uint64_t image_base;
121
	__uint32_t section_align;
121
	uint32_t section_align;
122
	__uint32_t file_align;
122
	uint32_t file_align;
123
	__uint16_t major_os_version;
123
	uint16_t major_os_version;
124
	__uint16_t minor_os_version;
124
	uint16_t minor_os_version;
125
	__uint16_t major_image_version;
125
	uint16_t major_image_version;
126
	__uint16_t minor_image_version;
126
	uint16_t minor_image_version;
127
	__uint16_t major_subsystem_version;
127
	uint16_t major_subsystem_version;
128
	__uint16_t minor_subsystem_version;
128
	uint16_t minor_subsystem_version;
129
	__uint32_t win32_version;
129
	uint32_t win32_version;
130
	__uint32_t image_sz;
130
	uint32_t image_sz;
131
	__uint32_t headers_sz;
131
	uint32_t headers_sz;
132
	__uint32_t checksum;
132
	uint32_t checksum;
133
	__uint16_t subsystem;
133
	uint16_t subsystem;
134
	__uint16_t dll_characteristics;
134
	uint16_t dll_characteristics;
135
	__uint64_t stack_reserve_sz;
135
	uint64_t stack_reserve_sz;
136
	__uint64_t stack_commit_sz;
136
	uint64_t stack_commit_sz;
137
	__uint64_t heap_reserve_sz;
137
	uint64_t heap_reserve_sz;
138
	__uint64_t heap_commit_sz;
138
	uint64_t heap_commit_sz;
139
	__uint32_t loader_flags;
139
	uint32_t loader_flags;
140
	__uint32_t rva_and_sizes_nr;
140
	uint32_t rva_and_sizes_nr;
141
	struct {
141
	struct {
142
		__uint64_t export_table;
142
		uint64_t export_table;
143
		__uint64_t import_table;
143
		uint64_t import_table;
144
		__uint64_t resource_table;
144
		uint64_t resource_table;
145
		__uint64_t exception_table;
145
		uint64_t exception_table;
146
		__uint64_t certification_table;
146
		uint64_t certification_table;
147
		__uint64_t base_relocation_table;
147
		uint64_t base_relocation_table;
148
	} data_directory;
148
	} data_directory;
149
} __packed;
149
} __packed;
150
150
151
struct section {
151
struct section {
152
	__uint8_t name[8];
152
	uint8_t name[8];
153
	__uint32_t virtual_sz;
153
	uint32_t virtual_sz;
154
	__uint32_t virtual_address;
154
	uint32_t virtual_address;
155
	__uint32_t raw_data_sz;
155
	uint32_t raw_data_sz;
156
	__uint32_t raw_data;
156
	uint32_t raw_data;
157
	__uint32_t relocs;
157
	uint32_t relocs;
158
	__uint32_t line_numbers;
158
	uint32_t line_numbers;
159
	__uint16_t relocs_nr;
159
	uint16_t relocs_nr;
160
	__uint16_t line_numbers_nr;
160
	uint16_t line_numbers_nr;
161
	__uint32_t characteristics;
161
	uint32_t characteristics;
162
} __packed;
162
} __packed;
163
163
164
struct coff_reloc {
164
struct coff_reloc {
165
	__uint32_t virtual_address;
165
	uint32_t virtual_address;
166
	__uint32_t symtab_index;
166
	uint32_t symtab_index;
167
	__uint16_t type;
167
	uint16_t type;
168
};
168
};
169
169
170
#endif /* EFI_WRAPPER_H */
170
#endif /* EFI_WRAPPER_H */

Return to bug 626952