summaryrefslogtreecommitdiff
path: root/api/lib/elf.h
blob: ea0d6cc8127545ab4bcd6e96b48d4369af40ffbf (plain)
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
36
37
38
39
40
41
#pragma once

#include <elf/elf64.h>

#include <stdbool.h>
#include <stddef.h>

#include <posix/sys/types.h>

#ifdef __x86_64__
# define elf_validate elf64_validate
# define elf_size elf64_size
#endif

struct linear_buffer
{
	char *base;
	size_t length;
};

struct elf64_image 
{
	struct linear_buffer buffer;
	struct
	{
		Elf64_Ehdr *file;
		Elf64_Phdr *segments;
		Elf64_Shdr *sections;
	}
	headers;
};

bool elf64_validate(Elf64_Ehdr const *ehdr, unsigned type, unsigned machine);
bool elf64_validate_fd(int fd, unsigned type, unsigned machine);
size_t elf64_size(Elf64_Ehdr const *ehdr, Elf64_Phdr *phdr);
size_t elf64_size_fd(int fd);
ssize_t elf64_load_segments(int fd, size_t buffer_size, char buffer[buffer_size]);
void *elf64_dt_ptr(char *base, Elf64_Dyn *dyntab, unsigned long dt_type);
uintptr_t elf64_dt_val(Elf64_Dyn *dyntab, unsigned long dt_type);
struct elf64_image elf64_open(const char *path);