~random-stuff/random-stuff/reicast

« back to all changes in this revision

Viewing changes to newdc/deps/libelf/elf.h

  • Committer: Stefanos Kornilios Mitsis Poiitidis
  • Date: 2013-12-28 21:28:50 UTC
  • mfrom: (8.1.19)
  • Revision ID: git-v1:f5d29677b32441c3f7870a198a1d5a8b0bdb8b9c
Merge branch 'androidui'

Conflicts:
        core/hw/pvr/spg.cpp
        core/hw/sh4/interpr/sh4_interpreter.cpp
        reicast/android/src/com/reicast/emulator/MainActivity.java

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Australian Public Licence B (OZPLB)
3
 
 * 
4
 
 * Version 1-0
5
 
 * 
6
 
 * Copyright (c) 1999-2004 University of New South Wales
7
 
 * 
8
 
 * All rights reserved. 
9
 
 * 
10
 
 * Developed by: Operating Systems and Distributed Systems Group (DiSy)
11
 
 *               University of New South Wales
12
 
 *               http://www.disy.cse.unsw.edu.au
13
 
 * 
14
 
 * Permission is granted by University of New South Wales, free of charge, to
15
 
 * any person obtaining a copy of this software and any associated
16
 
 * documentation files (the "Software") to deal with the Software without
17
 
 * restriction, including (without limitation) the rights to use, copy,
18
 
 * modify, adapt, merge, publish, distribute, communicate to the public,
19
 
 * sublicense, and/or sell, lend or rent out copies of the Software, and
20
 
 * to permit persons to whom the Software is furnished to do so, subject
21
 
 * to the following conditions:
22
 
 * 
23
 
 *     * Redistributions of source code must retain the above copyright
24
 
 *       notice, this list of conditions and the following disclaimers.
25
 
 * 
26
 
 *     * Redistributions in binary form must reproduce the above
27
 
 *       copyright notice, this list of conditions and the following
28
 
 *       disclaimers in the documentation and/or other materials provided
29
 
 *       with the distribution.
30
 
 * 
31
 
 *     * Neither the name of University of New South Wales, nor the names of its
32
 
 *       contributors, may be used to endorse or promote products derived
33
 
 *       from this Software without specific prior written permission.
34
 
 * 
35
 
 * EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
36
 
 * PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
37
 
 * NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
38
 
 * WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
39
 
 * BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
40
 
 * REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
41
 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
42
 
 * THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
43
 
 * ERRORS, WHETHER OR NOT DISCOVERABLE.
44
 
 * 
45
 
 * TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
46
 
 * NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
47
 
 * THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
48
 
 * NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
49
 
 * LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
50
 
 * OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
51
 
 * OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
52
 
 * OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
53
 
 * CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
54
 
 * CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
55
 
 * DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
56
 
 * CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
57
 
 * DAMAGES OR OTHER LIABILITY.
58
 
 * 
59
 
 * If applicable legislation implies representations, warranties, or
60
 
 * conditions, or imposes obligations or liability on University of New South
61
 
 * Wales or one of its contributors in respect of the Software that
62
 
 * cannot be wholly or partly excluded, restricted or modified, the
63
 
 * liability of University of New South Wales or the contributor is limited, to
64
 
 * the full extent permitted by the applicable legislation, at its
65
 
 * option, to:
66
 
 * a.  in the case of goods, any one or more of the following:
67
 
 * i.  the replacement of the goods or the supply of equivalent goods;
68
 
 * ii.  the repair of the goods;
69
 
 * iii. the payment of the cost of replacing the goods or of acquiring
70
 
 *  equivalent goods;
71
 
 * iv.  the payment of the cost of having the goods repaired; or
72
 
 * b.  in the case of services:
73
 
 * i.  the supplying of the services again; or
74
 
 * ii.  the payment of the cost of having the services supplied again.
75
 
 * 
76
 
 * The construction, validity and performance of this licence is governed
77
 
 * by the laws in force in New South Wales, Australia.
78
 
 */
79
 
 
80
 
/*
81
 
  Authors: Luke Deller, Ben Leslie
82
 
  Created: 24/Sep/1999
83
 
*/
84
 
 
85
 
/**
86
 
\file
87
 
 
88
 
\brief Generic ELF library
89
 
 
90
 
The ELF library is designed to make the task of parsing and getting information
91
 
out of an ELF file easier.
92
 
 
93
 
It provides function to obtain the various different fields in the ELF header, and
94
 
the program and segment information.
95
 
 
96
 
Also importantly, it provides a function elf_loadFile which will load a given
97
 
ELF file into memory.
98
 
 
99
 
*/
100
 
 
101
 
#ifndef __ELF_ELF_H__
102
 
#define __ELF_ELF_H__
103
 
 
104
 
#include <stdint.h>
105
 
#include <stdio.h>
106
 
 
107
 
#include "elf32.h"
108
 
#include "elf64.h"
109
 
 
110
 
struct elf_symbol {
111
 
  uint32_t st_name;               // Symbol name (string table index)
112
 
  uint32_t st_value;              // Symbol value
113
 
  uint32_t st_size;               // Symbol size
114
 
  uint8_t  st_info;               // Symbol type and binding
115
 
  uint8_t  st_other;              // No defined meaning, 0 
116
 
  uint16_t st_shndx;              // Section index
117
 
};
118
 
 
119
 
/*
120
 
 * constants for Elf32_Phdr.p_flags 
121
 
 */
122
 
#define PF_X            1       /* readable segment */
123
 
#define PF_W            2       /* writeable segment */
124
 
#define PF_R            4       /* executable segment */
125
 
 
126
 
/*
127
 
 * constants for indexing into Elf64_Header_t.e_ident 
128
 
 */
129
 
#define EI_MAG0         0
130
 
#define EI_MAG1         1
131
 
#define EI_MAG2         2
132
 
#define EI_MAG3         3
133
 
#define EI_CLASS        4
134
 
#define EI_DATA         5
135
 
#define EI_VERSION      6
136
 
 
137
 
#define ELFMAG0         '\177'
138
 
#define ELFMAG1         'E'
139
 
#define ELFMAG2         'L'
140
 
#define ELFMAG3         'F'
141
 
 
142
 
#define ELFCLASS32      1
143
 
#define ELFCLASS64      2
144
 
 
145
 
#define PT_NULL 0
146
 
#define PT_LOAD 1
147
 
#define PT_DYNAMIC 2
148
 
#define PT_INTERP 3
149
 
#define PT_NOTE 4
150
 
 
151
 
#define ELFDATA2LSB 1
152
 
#define ELFDATA2MSB 2
153
 
 
154
 
/* Section Header type bits */
155
 
#define SHT_PROGBITS 1
156
 
#define SHT_SYMTAB 2
157
 
#define SHT_NOBITS 8
158
 
#define SHT_REL 9
159
 
 
160
 
/* Section Header flag bits */
161
 
#define SHF_WRITE 1
162
 
#define SHF_ALLOC 2
163
 
#define SHF_EXECINSTR  4
164
 
 
165
 
/**/
166
 
#define ELF_PRINT_PROGRAM_HEADERS 1
167
 
#define ELF_PRINT_SECTIONS 2
168
 
#define ELF_PRINT_ALL (ELF_PRINT_PROGRAM_HEADERS | ELF_PRINT_SECTIONS)
169
 
 
170
 
/**
171
 
 * Checks that elfFile points to a valid elf file. 
172
 
 *
173
 
 * @param elfFile Potential ELF file to check
174
 
 *
175
 
 * \return 0 on success. -1 if not and elf, -2 if not 32 bit.
176
 
 */
177
 
int elf_checkFile(void *elfFile);
178
 
 
179
 
/**
180
 
 * Determine number of sections in an ELF file.
181
 
 *
182
 
 * @param elfFile Pointer to a valid ELF header.
183
 
 *
184
 
 * \return Number of sections in the ELF file.
185
 
 */
186
 
unsigned elf_getNumSections(void *elfFile);
187
 
 
188
 
/**
189
 
 * Determine number of program headers in an ELF file.
190
 
 *
191
 
 * @param elfFile Pointer to a valid ELF header.
192
 
 *
193
 
 * \return Number of program headers in the ELF file.
194
 
 */
195
 
uint16_t elf_getNumProgramHeaders(void *elfFile);
196
 
 
197
 
/**
198
 
 * Return the base physical address of given program header in an ELF file
199
 
 *
200
 
 * @param elfFile Pointer to a valid ELF header
201
 
 * @param ph Index of the program header
202
 
 *
203
 
 * \return The memory size of the specified program header
204
 
 */
205
 
uint64_t elf_getProgramHeaderPaddr(void *elfFile, uint16_t ph);
206
 
 
207
 
/**
208
 
 * Return the base virtual address of given program header in an ELF file
209
 
 *
210
 
 * @param elfFile Pointer to a valid ELF header
211
 
 * @param ph Index of the program header
212
 
 *
213
 
 * \return The memory size of the specified program header
214
 
 */
215
 
uint64_t elf_getProgramHeaderVaddr(void *elfFile, uint16_t ph);
216
 
 
217
 
/**
218
 
 * Return the memory size of a given program header in an ELF file
219
 
 *
220
 
 * @param elfFile Pointer to a valid ELF header
221
 
 * @param ph Index of the program header
222
 
 *
223
 
 * \return The memory size of the specified program header
224
 
 */
225
 
uint64_t elf_getProgramHeaderMemorySize(void *elfFile, uint16_t ph);
226
 
 
227
 
/**
228
 
 * Return the file size of a given program header in an ELF file
229
 
 *
230
 
 * @param elfFile Pointer to a valid ELF header
231
 
 * @param ph Index of the program header
232
 
 *
233
 
 * \return The file size of the specified program header
234
 
 */
235
 
uint64_t elf_getProgramHeaderFileSize(void *elfFile, uint16_t ph);
236
 
 
237
 
/**
238
 
 * Return the start offset of he file
239
 
 *
240
 
 * @param elfFile Pointer to a valid ELF header
241
 
 * @param ph Index of the program header
242
 
 *
243
 
 * \return The offset of this program header with relation to the start
244
 
 * of the elfFile.
245
 
 */
246
 
uint64_t elf_getProgramHeaderOffset(void *elfFile, uint16_t ph);
247
 
 
248
 
/**
249
 
 * Return the flags for a given program header
250
 
 *
251
 
 * @param elfFile Pointer to a valid ELF header
252
 
 * @param ph Index of the program header
253
 
 *
254
 
 * \return The flags of a given program header
255
 
 */
256
 
uint32_t elf_getProgramHeaderFlags(void *elfFile, uint16_t ph);
257
 
 
258
 
/**
259
 
 * Return the type for a given program header
260
 
 *
261
 
 * @param elfFile Pointer to a valid ELF header
262
 
 * @param ph Index of the program header
263
 
 *
264
 
 * \return The type of a given program header
265
 
 */
266
 
uint32_t elf_getProgramHeaderType(void *elfFile, uint16_t ph);
267
 
 
268
 
/**
269
 
 * Return the physical translation of a physical address, with respect
270
 
 * to a given program header
271
 
 *
272
 
 */
273
 
uint64_t elf_vtopProgramHeader(void *elfFile, uint16_t ph, uint64_t vaddr);
274
 
 
275
 
 
276
 
/**
277
 
 * 
278
 
 * \return true if the address in in this program header
279
 
 */
280
 
bool elf_vaddrInProgramHeader(void *elfFile, uint16_t ph, uint64_t vaddr);
281
 
 
282
 
/**
283
 
 * Determine the memory bounds of an ELF file
284
 
 *
285
 
 * @param elfFile Pointer to a valid ELF header
286
 
 * @param phys If true return bounds of physical memory, otherwise return
287
 
 *   bounds of virtual memory
288
 
 * @param min Pointer to return value of the minimum
289
 
 * @param max Pointer to return value of the maximum
290
 
 *
291
 
 * \return true on success. false on failure, if for example, it is an invalid ELF file 
292
 
 */
293
 
bool elf_getMemoryBounds(void *elfFile, bool phys, uint64_t *min, uint64_t *max);
294
 
 
295
 
/**
296
 
 * Find the entry point of an ELF file.
297
 
 *
298
 
 * @param elfFile Pointer to a valid ELF header
299
 
 *
300
 
 * \return The entry point address as a 64-bit integer.
301
 
 */
302
 
uint64_t elf_getEntryPoint(void *elfFile);
303
 
 
304
 
/**
305
 
 * Load an ELF file into memory
306
 
 *
307
 
 * @param elfFile Pointer to a valid ELF file
308
 
 * @param phys If true load using the physical address, otherwise using the virtual addresses
309
 
 *
310
 
 * \return true on success, false on failure.
311
 
 *
312
 
 * The function assumes that the ELF file is loaded in memory at some
313
 
 * address different to the target address at which it will be loaded.
314
 
 * It also assumes direct access to the source and destination address, i.e:
315
 
 * Memory must be ale to me loaded with a simple memcpy.
316
 
 *
317
 
 * Obviously this also means that if we are loading a 64bit ELF on a 32bit
318
 
 * platform, we assume that any memory address are within the first 4GB.
319
 
 *
320
 
 */
321
 
bool elf_loadFile(void *elfFile, bool phys);
322
 
 
323
 
char *elf_getStringTable(void *elfFile, int string_segment);
324
 
char *elf_getSegmentStringTable(void *elfFile);
325
 
void *elf_getSectionNamed(void *elfFile, char *str);
326
 
char *elf_getSectionName(void *elfFile, int i);
327
 
uint64_t elf_getSectionSize(void *elfFile, int i);
328
 
uint64_t elf_getSectionLink(void *elfFile, int i);
329
 
uint64_t elf_getSectionAddr(void *elfFile, int i);
330
 
 
331
 
/**
332
 
 * Return the flags for a given sections
333
 
 *
334
 
 * @param elfFile Pointer to a valid ELF header
335
 
 * @param i Index of the sections
336
 
 *
337
 
 * \return The flags of a given section
338
 
 */
339
 
uint32_t elf_getSectionFlags(void *elfFile, int i);
340
 
 
341
 
/**
342
 
 * Return the type for a given sections
343
 
 *
344
 
 * @param elfFile Pointer to a valid ELF header
345
 
 * @param i Index of the sections
346
 
 *
347
 
 * \return The type of a given section
348
 
 */
349
 
uint32_t elf_getSectionType(void *elfFile, int i);
350
 
 
351
 
void *elf_getSection(void *elfFile, int i);
352
 
void elf_getProgramHeaderInfo(void *elfFile, uint16_t ph, uint64_t *p_vaddr, 
353
 
                              uint64_t *p_paddr, uint64_t *p_filesz, 
354
 
                              uint64_t *p_offset, uint64_t *p_memsz);
355
 
 
356
 
 
357
 
/**
358
 
 * output the details of an ELF file to the stream f
359
 
 */
360
 
void elf_fprintf(FILE *f, void *elfFile, int size, const char *name, int flags);
361
 
 
362
 
#define SHT_DYNSYM 0xB
363
 
#if 0
364
 
/*
365
 
 * Returns a pointer to the program segment table, which is an array of
366
 
 * ELF64_Phdr_t structs.  The size of the array can be found by calling
367
 
 * getNumProgramSegments. 
368
 
 */
369
 
struct Elf32_Phdr *elf_getProgramSegmentTable(void *elfFile);
370
 
#endif
371
 
#if 0
372
 
/**
373
 
 * Returns a pointer to the program segment table, which is an array of
374
 
 * ELF64_Phdr_t structs.  The size of the array can be found by calling
375
 
 * getNumProgramSegments. 
376
 
 */
377
 
struct Elf32_Shdr *elf_getSectionTable(void *elfFile);
378
 
#endif
379
 
 
380
 
#endif