Annotate doxygen-style
[centaur.git] / include / libelfu / types.h
1 /*!
2  * @file types.h
3  * @brief libelfu's Elfu* types.
4  *
5  * libelfu provides an abstraction of the data in ELF files
6  * to more closely model the dependencies between them, and
7  * thus to facilitate consistent editing.
8  */
9
10 #ifndef __LIBELFU_TYPES_H__
11 #define __LIBELFU_TYPES_H__
12
13 #include <sys/queue.h>
14
15 #include <elf.h>
16 #include <gelf.h>
17
18
19 /*!
20  * ELFU model of a symbol table entry.
21  */
22 typedef struct ElfuSym {
23   /*! Offset into linked string table */
24   GElf_Word name;
25
26
27   /*! Explicit value */
28   GElf_Addr value;
29
30   /*! Size of object referenced */
31   GElf_Word size;
32
33
34   /*! Binding type (GLOBAL, LOCAL, ...) */
35   unsigned char bind;
36
37   /*! Type (FUNC, SECTION, ...) */
38   unsigned char type;
39
40   /*! Always 0, currently meaningless (see ELF spec) */
41   unsigned char other;
42
43
44   /*! If non-null, the section referenced. */
45   struct ElfuScn *scnptr;
46
47   /*! If scnptr is invalid, then this is ABS, COMMON, or UNDEF. */
48   int shndx;
49
50
51   /*! Entry in a symbol table */
52   CIRCLEQ_ENTRY(ElfuSym) elem;
53 } ElfuSym;
54
55
56
57 /*!
58  * ELFU model of a symbol table.
59  */
60 typedef struct ElfuSymtab {
61   /*! All parsed symbols */
62   CIRCLEQ_HEAD(Syms, ElfuSym) syms;
63 } ElfuSymtab;
64
65
66
67
68
69 /*!
70  * ELFU model of a relocation entry.
71  */
72 typedef struct ElfuRel {
73   /*! Location to patch */
74   GElf_Addr offset;
75
76
77   /*! Symbol to calculate value for */
78   GElf_Word sym;
79
80   /*! Relocation type (machine specific) */
81   unsigned char type;
82
83
84   /*! addendUsed == 0: Use addend from relocation destination (REL).
85    *  addendUsed != 0: Use explicit addend (RELA). */
86   int addendUsed;
87
88   /*! Explicit addend in RELA tables */
89   GElf_Sword addend;
90
91
92   /*! Element in table */
93   CIRCLEQ_ENTRY(ElfuRel) elem;
94 } ElfuRel;
95
96
97
98 /*!
99  * ELFU model of a relocation table.
100  */
101 typedef struct ElfuReltab {
102   /*! All parsed relocation entries */
103   CIRCLEQ_HEAD(Rels, ElfuRel) rels;
104 } ElfuReltab;
105
106
107
108
109
110
111
112 /*!
113  * ELFU model of an ELF section.
114  *
115  * Several members of the SHDR are repeated in abstract form and take
116  * precedence if present. For example, if linkptr is non-NULL then
117  * it points to another section and the SHDR's numeric sh_link member
118  * is to be ignored and recomputed by the layouter.
119  */
120 typedef struct ElfuScn {
121   /*! SHDR as per ELF specification.
122    *  Several values are ignored or recomputed from other members of
123    *  ElfuScn. */
124   GElf_Shdr shdr;
125
126   /*! malloc()ed buffer containing this section's flat data backbuffer.
127    *  Present for all sections that occupy space in the file. */
128   char *databuf;
129
130
131   /*! Pointer to a section, meaning dependent on sh_type.
132    *  Preferred over sh_link if non-null. */
133   struct ElfuScn *linkptr;
134
135   /*! Pointer to a section, meaning dependent on sh_type.
136    *  Preferred over sh_info if non-null. */
137   struct ElfuScn *infoptr;
138
139
140   /*! If this section is a clone of another section, then this
141    *  points to that other section.
142    *  Used during code injection to facilitate relocation. */
143   struct ElfuScn *oldptr;
144
145
146   /*! Translated contents of a symbol table. */
147   struct ElfuSymtab symtab;
148
149   /*! Translated contents of a relocation table. */
150   struct ElfuReltab reltab;
151
152
153   /*! Element linking this section into an ElfuPhdr's childScnList,
154    *  or into an ElfuElf's orphanScnList. */
155   CIRCLEQ_ENTRY(ElfuScn) elemChildScn;
156 } ElfuScn;
157
158
159
160 /*!
161  * ELFU model of an ELF PHDR.
162  */
163 typedef struct ElfuPhdr {
164   /*! PHDR as per ELF specification. */
165   GElf_Phdr phdr;
166
167
168   /*! Sections to be shifted in file/memory together with this PHDR */
169   CIRCLEQ_HEAD(ChildScnList, ElfuScn) childScnList;
170
171   /*! PHDRs to be shifted in file/memory together with this PHDR */
172   CIRCLEQ_HEAD(ChildPhdrList, ElfuPhdr) childPhdrList;
173
174
175   /*! Element linking this section into an ElfuPhdr's childPhdrList */
176   CIRCLEQ_ENTRY(ElfuPhdr) elemChildPhdr;
177
178   /*! Element linking this section into an ElfuElf's phdrList */
179   CIRCLEQ_ENTRY(ElfuPhdr) elem;
180 } ElfuPhdr;
181
182
183
184 /*!
185  * ELFU model of an ELF file header
186  */
187 typedef struct {
188   /*! The ELF class -- ELFCLASS32/ELFCLASS64 */
189   int elfclass;
190
191   /*! EHDR as per ELF specification */
192   GElf_Ehdr ehdr;
193
194
195   /*! PHDRs that are not dependent on others.
196    *  Usually, LOAD and GNU_STACK. */
197   CIRCLEQ_HEAD(PhdrList, ElfuPhdr) phdrList;
198
199   /*! Sections not in any PHDR, and thus not loaded at runtime.
200    *  Usually .symtab, .strtab, .shstrtab, .debug_*, ... */
201   CIRCLEQ_HEAD(OrphanScnList, ElfuScn) orphanScnList;
202
203
204   /*! Pointer to ElfuScn containing .shstrtab.
205    *  Parsed from EHDR for convenience. */
206   ElfuScn *shstrtab;
207
208   /*! Pointer to ElfuScn containing .symtab.
209    *  Parsed from list of sections for convenience. */
210   ElfuScn *symtab;
211 } ElfuElf;
212
213 #endif