File: kexec-elf-rel-x86.c

package info (click to toggle)
kexec-tools 1%3A2.0.3-1%2Bdeb7u1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,780 kB
  • sloc: ansic: 24,550; sh: 2,912; asm: 2,496; cpp: 1,747; makefile: 731
file content (35 lines) | stat: -rw-r--r-- 712 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <elf.h>
#include "../../kexec.h"
#include "../../kexec-elf.h"

int machine_verify_elf_rel(struct mem_ehdr *ehdr)
{
	if (ehdr->ei_data != ELFDATA2LSB) {
		return 0;
	}
	if (ehdr->ei_class != ELFCLASS32) {
		return 0;
	}
	if ((ehdr->e_machine != EM_386) && (ehdr->e_machine != EM_486)) 
	{
		return 0;
	}
	return 1;
}

void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), unsigned long r_type,
	void *location, unsigned long address, unsigned long value)
{
	switch(r_type) {
	case R_386_32:
		*((uint32_t *)location) += value;
		break;
	case R_386_PC32:
		*((uint32_t *)location) += value - address;
		break;
	default:
		die("Unknown rel relocation: %lu\n", r_type);
		break;
	}
}