Subversion Repositories Kolibri OS

Rev

Rev 9220 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9220 Rev 9927
Line 41... Line 41...
41
	"EPEP_ERR_INVALID_BASE_RELOCATION_BLOCK_OFFSET",
41
	"EPEP_ERR_INVALID_BASE_RELOCATION_BLOCK_OFFSET",
42
	"EPEP_ERR_INVALID_NEXT_BASE_RELOCATION_BLOCK_OFFSET",
42
	"EPEP_ERR_INVALID_NEXT_BASE_RELOCATION_BLOCK_OFFSET",
43
	"EPEP_ERR_INVALID_BASE_RELOCATION_BLOCK_BASE_RELOCATION_OFFSET",
43
	"EPEP_ERR_INVALID_BASE_RELOCATION_BLOCK_BASE_RELOCATION_OFFSET",
44
	"EPEP_ERR_INVALID_SECTION_RELOCATION_OFFSET",
44
	"EPEP_ERR_INVALID_SECTION_RELOCATION_OFFSET",
45
	"EPEP_ERR_INVALID_LINENUMBER_OFFSET",
45
	"EPEP_ERR_INVALID_LINENUMBER_OFFSET",
-
 
46
	"EPEP_ERR_INVALID_NUMBER_OF_RELOCATIONS_FOR_EXTENDED",
46
};
47
};
Line -... Line 48...
-
 
48
 
-
 
49
static_assert(sizeof(epep_errors) / sizeof(epep_errors[0]) == EPEP_ERR_END,
-
 
50
              "Each EPEP error should be stringified.");
47
 
51
 
Line 48... Line 52...
48
typedef char *pchar;
52
typedef char *pchar;
49
 
53
 
50
typedef struct {
54
typedef struct {
Line 61... Line 65...
61
typedef struct {
65
typedef struct {
62
	ObjIdSecId *source;
66
	ObjIdSecId *source;
63
	uint32_t characteristics;
67
	uint32_t characteristics;
64
	size_t size;
68
	size_t size;
65
	size_t number_of_relocations;
69
	size_t number_of_relocations;
-
 
70
	// Number of relocations is greater than 2^16 - 1
-
 
71
	int number_of_relocations_is_extended;
66
} SectionInfo;
72
} SectionInfo;
Line 67... Line 73...
67
 
73
 
68
typedef struct {
74
typedef struct {
69
	EpepCoffSymbol sym;
75
	EpepCoffSymbol sym;
Line 238... Line 244...
238
		fwrite32(out, next_section_offset);       // PointerToRawData
244
		fwrite32(out, next_section_offset);       // PointerToRawData
239
		next_section_offset += si.size;
245
		next_section_offset += si.size;
240
		fwrite32(out, offset_to_next_relocation); // PointerToRelocations
246
		fwrite32(out, offset_to_next_relocation); // PointerToRelocations
241
		offset_to_next_relocation += si.number_of_relocations * 10;
247
		offset_to_next_relocation += si.number_of_relocations * 10;
242
		fwrite32(out, 0);                         // PointerToLinenumbers
248
		fwrite32(out, 0);                         // PointerToLinenumbers
-
 
249
		// NumberOfRelocations
-
 
250
		if (si.number_of_relocations_is_extended) {
-
 
251
			fwrite16(out, 0xffff);
-
 
252
		} else {
243
		fwrite16(out, si.number_of_relocations);  // NumberOfRelocations
253
			fwrite16(out, si.number_of_relocations);
-
 
254
		}
244
		fwrite16(out, 0);                         // NumberOfLinenumbers
255
		fwrite16(out, 0);                         // NumberOfLinenumbers
245
		fwrite32(out, si.characteristics);        // Characteristics
256
		fwrite32(out, si.characteristics);        // Characteristics
246
		log_info("Done.\n");
257
		log_info("Done.\n");
247
	}
258
	}
248
	log_info("}\n");
259
	log_info("}\n");
Line 292... Line 303...
292
	for (size_t sec_i = 0; sec_i < cvec_pchar_size(&ir->section_names_set); sec_i++) {
303
	for (size_t sec_i = 0; sec_i < cvec_pchar_size(&ir->section_names_set); sec_i++) {
293
		char *name = ir->section_names_set[sec_i];
304
		char *name = ir->section_names_set[sec_i];
294
		SectionInfo si = cdict_CStr_SectionInfo_get_v(&ir->info_per_section, name);
305
		SectionInfo si = cdict_CStr_SectionInfo_get_v(&ir->info_per_section, name);
Line 295... Line 306...
295
 
306
 
-
 
307
		log_info(" Writing relocations of %s {\n", name);
-
 
308
		if (si.number_of_relocations_is_extended) {
-
 
309
			EpepCoffRelocation rel = { 0 };
-
 
310
			rel.VirtualAddress = si.number_of_relocations;
-
 
311
			fwrite(&rel, 1, 10, out);
296
		log_info(" Writing relocations of %s {\n", name);
312
		}
297
		for (size_t i = 0; i < cvec_ObjIdSecId_size(&si.source); i++) {
313
		for (size_t i = 0; i < cvec_ObjIdSecId_size(&si.source); i++) {
298
			ObjIdSecId id = cvec_ObjIdSecId_at(&si.source, i);
314
			ObjIdSecId id = cvec_ObjIdSecId_at(&si.source, i);
299
			CoffObject *object = &ir->objects[id.obj_id];
315
			CoffObject *object = &ir->objects[id.obj_id];
Line 311... Line 327...
311
 
327
 
312
			EpepSectionHeader sh = { 0 };
328
			EpepSectionHeader sh = { 0 };
313
			if (!epep_get_section_header_by_index(epep, &sh, id.sec_id)) {
329
			if (!epep_get_section_header_by_index(epep, &sh, id.sec_id)) {
314
				ERROR_EPEP(epep);
330
				ERROR_EPEP(epep);
-
 
331
			}
-
 
332
			size_t number_of_relocations = 0;
-
 
333
			int extended = 0;
-
 
334
			if (!epep_get_section_number_of_relocations_x(epep, &sh, &number_of_relocations, &extended)) {
-
 
335
				ERROR_EPEP(epep);
315
			}
336
			}
316
			for (size_t rel_i = 0; rel_i < sh.NumberOfRelocations; rel_i++) {
337
			for (size_t rel_i = 0; rel_i < number_of_relocations; rel_i++) {
Line 317... Line 338...
317
				EpepCoffRelocation rel = { 0 };
338
				EpepCoffRelocation rel = { 0 };
318
 
339
 
319
				if (!epep_get_section_relocation_by_index(epep, &sh, &rel, rel_i)) {
340
				if (!epep_get_section_relocation_by_index_x(epep, &sh, &rel, rel_i, extended)) {
320
					ERROR_EPEP(epep);
341
					ERROR_EPEP(epep);
321
				}
342
				}
322
				log_info("  { %02x, %02x, %02x }", rel.VirtualAddress, rel.SymbolTableIndex, rel.Type);
343
				log_info("  { %02x, %02x, %02x }", rel.VirtualAddress, rel.SymbolTableIndex, rel.Type);
Line 602... Line 623...
602
			}
623
			}
Line 603... Line 624...
603
 
624
 
604
			size_t sec_offset = si.size;
625
			size_t sec_offset = si.size;
Line -... Line 626...
-
 
626
			cvec_size_t_push_back(&objects[i].section_offsets, sec_offset);
-
 
627
 
-
 
628
			size_t number_of_relocations = 0;
-
 
629
			int unused = 0;
-
 
630
			if (!epep_get_section_number_of_relocations_x(epep, &sh, &number_of_relocations, &unused)) {
-
 
631
				ERROR_EPEP(epep);
605
			cvec_size_t_push_back(&objects[i].section_offsets, sec_offset);
632
			}
606
 
633
 
607
			si.size += sh.SizeOfRawData;
634
			si.size += sh.SizeOfRawData;
-
 
635
			si.characteristics |= sh.Characteristics;
-
 
636
			si.number_of_relocations += number_of_relocations;
-
 
637
			if (si.number_of_relocations > 0xffff && !si.number_of_relocations_is_extended) {
-
 
638
				// One more relocation to store the actual relocation number
-
 
639
				si.number_of_relocations++;
-
 
640
				si.number_of_relocations_is_extended = 1;
-
 
641
				const uint32_t flag_IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000;
608
			si.characteristics |= sh.Characteristics;
642
				si.characteristics |= flag_IMAGE_SCN_LNK_NRELOC_OVFL;
609
			si.number_of_relocations += sh.NumberOfRelocations;
643
			}
Line 610... Line 644...
610
			cvec_ObjIdSecId_push_back(&si.source, (ObjIdSecId){ i, sec_i });
644
			cvec_ObjIdSecId_push_back(&si.source, (ObjIdSecId){ i, sec_i });
611
			cdict_CStr_SectionInfo_add_vv(&info_per_section, strdup(name), si, CDICT_REPLACE_EXIST);
645
			cdict_CStr_SectionInfo_add_vv(&info_per_section, strdup(name), si, CDICT_REPLACE_EXIST);