-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlibrary.h
97 lines (83 loc) · 2.53 KB
/
library.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef LIBRARY_H_
#define LIBRARY_H_
#include <elf.h>
#include <stdbool.h>
#include <sys/mman.h>
#include <sys/types.h>
#include "maps.h"
#if defined(__x86_64__)
typedef Elf64_Ehdr Elf_Ehdr;
typedef Elf64_Shdr Elf_Shdr;
typedef Elf64_Sym Elf_Sym;
#elif defined(__i386__)
typedef Elf32_Ehdr Elf_Ehdr;
typedef Elf32_Shdr Elf_Shdr;
typedef Elf32_Sym Elf_Sym;
#else
#error Unsupported target platform
#endif
struct symbol {
char *name;
Elf_Sym sym;
struct hlist_node symbol_hash;
};
/* Internal data structure for segments. */
struct segment {
uint64_t addr; /* load addr */
uint64_t off; /* file offset */
uint64_t fsz; /* file size */
uint64_t msz; /* memory size */
uint64_t type; /* segment type */
struct list_head section_list;
struct list_head segments;
};
/* Internal data structure for sections. */
struct section {
struct segment *seg; /* containing segment */
const char *name; /* section name */
int idx; /* secton index */
Elf_Shdr shdr; /* section header */
void *buf; /* section content */
uint8_t *pad; /* section padding */
uint64_t off; /* section offset */
uint64_t sz; /* section size */
uint64_t cap; /* section capacity */
uint64_t align; /* section alignment */
uint64_t type; /* section type */
uint64_t vma; /* section virtual addr */
uint64_t lma; /* section load addr */
uint64_t pad_sz;/* section padding size */
int loadable; /* whether loadable */
int pseudo;
int nocopy;
struct list_head sections;
struct list_head seg_entry; /* list of sections in a segment */
struct hlist_node section_hash;
};
struct library {
char *pathname;
bool valid;
bool vdso;
char *asr_offset;
int vsys_offset;
Elf_Ehdr ehdr;
struct rb_root rb_region;
struct hlist_head *section_hash;
struct hlist_head *symbol_hash;
char *image;
size_t image_size;
struct maps *maps;
struct hlist_node library_hash;
};
extern char *__kernel_vsyscall;
extern char *__kernel_sigreturn;
extern char *__kernel_rt_sigreturn;
extern void library_init(struct library *, const char *name, struct maps *maps);
extern bool library_parse_elf(struct library *);
extern void library_make_writable(struct library *, bool);
extern void library_patch_syscalls(struct library *);
void patch_syscalls_in_func(char *start, char *end);
extern void library_patch_syscalls_in_range(struct library *, char *start, char *stop, char **extra_space, int *extra_len);
extern int library_patch_vsyscalls(struct library *);
extern void library_patch_vdso(struct library *, char **space, int *length);
#endif /* LIBRARY_H_ */