elf.h revision 82185a52
1/*
2 * Copyright 2002-2016 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _ELF_H
6#define _ELF_H
7
8
9#include <SupportDefs.h>
10#include <ByteOrder.h>
11
12
13typedef uint32 Elf32_Addr;
14typedef uint16 Elf32_Half;
15typedef uint32 Elf32_Off;
16typedef int32 Elf32_Sword;
17typedef uint32 Elf32_Word;
18
19typedef Elf32_Half Elf32_Versym;
20
21typedef uint64 Elf64_Addr;
22typedef uint64 Elf64_Off;
23typedef uint16 Elf64_Half;
24typedef uint32 Elf64_Word;
25typedef int32 Elf64_Sword;
26typedef uint64 Elf64_Xword;
27typedef int64 Elf64_Sxword;
28
29typedef Elf64_Half Elf64_Versym;
30
31
32/*** ELF header ***/
33
34#define EI_NIDENT	16
35
36typedef struct {
37	uint8		e_ident[EI_NIDENT];
38	Elf32_Half	e_type;
39	Elf32_Half	e_machine;
40	Elf32_Word	e_version;
41	Elf32_Addr	e_entry;
42	Elf32_Off	e_phoff;
43	Elf32_Off	e_shoff;
44	Elf32_Word	e_flags;
45	Elf32_Half	e_ehsize;
46	Elf32_Half	e_phentsize;
47	Elf32_Half	e_phnum;
48	Elf32_Half	e_shentsize;
49	Elf32_Half	e_shnum;
50	Elf32_Half	e_shstrndx;
51
52#ifdef __cplusplus
53	bool IsHostEndian() const;
54#endif
55} Elf32_Ehdr;
56
57typedef struct {
58	uint8		e_ident[EI_NIDENT];
59	Elf64_Half	e_type;
60	Elf64_Half	e_machine;
61	Elf64_Word	e_version;
62	Elf64_Addr	e_entry;
63	Elf64_Off	e_phoff;
64	Elf64_Off	e_shoff;
65	Elf64_Word	e_flags;
66	Elf64_Half	e_ehsize;
67	Elf64_Half	e_phentsize;
68	Elf64_Half	e_phnum;
69	Elf64_Half	e_shentsize;
70	Elf64_Half	e_shnum;
71	Elf64_Half	e_shstrndx;
72
73#ifdef __cplusplus
74	bool IsHostEndian() const;
75#endif
76} Elf64_Ehdr;
77
78#define ELF_MAGIC	"\x7f""ELF"
79
80/* e_ident[] indices */
81#define EI_MAG0		0
82#define EI_MAG1		1
83#define EI_MAG2		2
84#define EI_MAG3		3
85#define EI_CLASS	4
86#define EI_DATA		5
87#define EI_VERSION	6
88#define EI_PAD		7
89
90/* e_type (Object file type) */
91#define ET_NONE			0 /* No file type */
92#define ET_REL			1 /* Relocatable file */
93#define ET_EXEC			2 /* Executable file */
94#define ET_DYN			3 /* Shared-object file */
95#define ET_CORE			4 /* Core file */
96#define ET_LOOS			0xfe00 /* OS-specific range start */
97#define ET_HIOS			0xfeff /* OS-specific range end */
98#define ET_LOPROC		0xff00 /* Processor-specific range start */
99#define ET_HIPROC		0xffff /* Processor-specific range end */
100
101/* e_machine (Architecture) */
102#define EM_NONE			0 /* No machine */
103#define EM_M32			1 /* AT&T WE 32100 */
104#define EM_SPARC		2 /* Sparc */
105#define EM_386			3 /* Intel 80386 */
106#define EM_68K			4 /* Motorola m68k family */
107#define EM_88K			5 /* Motorola m88k family */
108#define EM_486			6 /* Intel 80486, Reserved for future use */
109#define EM_860			7 /* Intel 80860 */
110#define EM_MIPS			8 /* MIPS R3000 (officially, big-endian only) */
111#define EM_S370			9 /* IBM System/370 */
112#define EM_MIPS_RS3_LE	10 /* MIPS R3000 little-endian, Deprecated */
113#define EM_PARISC		15 /* HPPA */
114#define EM_VPP550		17 /* Fujitsu VPP500 */
115#define EM_SPARC32PLUS	18 /* Sun "v8plus" */
116#define EM_960			19 /* Intel 80960 */
117#define EM_PPC			20 /* PowerPC */
118#define EM_PPC64		21 /* 64-bit PowerPC */
119#define EM_S390			22 /* IBM S/390 */
120#define EM_V800			36 /* NEC V800 series */
121#define EM_FR20			37 /* Fujitsu FR20 */
122#define EM_RH32			38 /* TRW RH32 */
123#define EM_MCORE		39 /* Motorola M*Core */
124#define EM_RCE			39 /* Old name for MCore */
125#define EM_ARM			40 /* ARM */
126#define EM_OLD_ALPHA	41 /* Digital Alpha */
127#define EM_SH			42 /* Renesas / SuperH SH */
128#define EM_SPARCV9		43 /* SPARC v9 64-bit */
129#define EM_TRICORE		44 /* Siemens Tricore embedded processor */
130#define EM_ARC			45 /* ARC Cores */
131#define EM_H8_300		46 /* Renesas H8/300 */
132#define EM_H8_300H		47 /* Renesas H8/300H */
133#define EM_H8S			48 /* Renesas H8S */
134#define EM_H8_500		49 /* Renesas H8/500 */
135#define EM_IA_64		50 /* Intel IA-64 Processor */
136#define EM_MIPS_X		51 /* Stanford MIPS-X */
137#define EM_COLDFIRE		52 /* Motorola Coldfire */
138#define EM_68HC12		53 /* Motorola M68HC12 */
139#define EM_MMA			54 /* Fujitsu Multimedia Accelerator */
140#define EM_PCP			55 /* Siemens PCP */
141#define EM_NCPU			56 /* Sony nCPU embedded RISC processor */
142#define EM_NDR1			57 /* Denso NDR1 microprocesspr */
143#define EM_STARCORE		58 /* Motorola Star*Core processor */
144#define EM_ME16			59 /* Toyota ME16 processor */
145#define EM_ST100		60 /* STMicroelectronics ST100 processor */
146#define EM_TINYJ		61 /* Advanced Logic Corp. TinyJ embedded processor */
147#define EM_X86_64		62 /* Advanced Micro Devices X86-64 processor */
148
149/* architecture class (EI_CLASS) */
150#define ELFCLASS32	1
151#define ELFCLASS64	2
152/* endian (EI_DATA) */
153#define ELFDATA2LSB	1	/* little endian */
154#define ELFDATA2MSB	2	/* big endian */
155
156/* ELF version (EI_VERSION) */
157#define EV_NONE		0	/* invalid */
158#define EV_CURRENT	1	/* current version */
159
160/*** section header ***/
161
162typedef struct {
163	Elf32_Word	sh_name;
164	Elf32_Word	sh_type;
165	Elf32_Word	sh_flags;
166	Elf32_Addr	sh_addr;
167	Elf32_Off	sh_offset;
168	Elf32_Word	sh_size;
169	Elf32_Word	sh_link;
170	Elf32_Word	sh_info;
171	Elf32_Word	sh_addralign;
172	Elf32_Word	sh_entsize;
173} Elf32_Shdr;
174
175typedef struct {
176	Elf64_Word	sh_name;
177	Elf64_Word	sh_type;
178	Elf64_Xword	sh_flags;
179	Elf64_Addr	sh_addr;
180	Elf64_Off	sh_offset;
181	Elf64_Xword	sh_size;
182	Elf64_Word	sh_link;
183	Elf64_Word	sh_info;
184	Elf64_Xword	sh_addralign;
185	Elf64_Xword	sh_entsize;
186} Elf64_Shdr;
187
188/* special section indices */
189#define SHN_UNDEF		0
190#define SHN_LORESERVE	0xff00
191#define SHN_LOPROC		0xff00
192#define SHN_HIPROC		0xff1f
193#define SHN_ABS			0xfff1
194#define SHN_COMMON		0xfff2
195#define SHN_HIRESERVE	0xffff
196
197/* section header type */
198#define SHT_NULL		0
199#define SHT_PROGBITS	1
200#define SHT_SYMTAB		2
201#define SHT_STRTAB		3
202#define SHT_RELA		4
203#define SHT_HASH		5
204#define SHT_DYNAMIC		6
205#define SHT_NOTE		7
206#define SHT_NOBITS		8
207#define SHT_REL			9
208#define SHT_SHLIB		10
209#define SHT_DYNSYM		11
210
211#define SHT_GNU_verdef	0x6ffffffd    /* version definition section */
212#define SHT_GNU_verneed	0x6ffffffe    /* version needs section */
213#define SHT_GNU_versym	0x6fffffff    /* version symbol table */
214
215#define SHT_LOPROC		0x70000000
216#define SHT_HIPROC		0x7fffffff
217#define SHT_LOUSER		0x80000000
218#define SHT_HIUSER		0xffffffff
219
220/* section header flags */
221#define SHF_WRITE		1
222#define SHF_ALLOC		2
223#define SHF_EXECINSTR	4
224
225#define SHF_MASKPROC	0xf0000000
226
227
228/*** program header ***/
229
230typedef struct {
231	Elf32_Word	p_type;
232	Elf32_Off	p_offset;	/* offset from the beginning of the file of the segment */
233	Elf32_Addr	p_vaddr;	/* virtual address for the segment in memory */
234	Elf32_Addr	p_paddr;
235	Elf32_Word	p_filesz;	/* the size of the segment in the file */
236	Elf32_Word	p_memsz;	/* the size of the segment in memory */
237	Elf32_Word	p_flags;
238	Elf32_Word	p_align;
239
240#ifdef __cplusplus
241	bool IsReadWrite() const;
242	bool IsExecutable() const;
243#endif
244} Elf32_Phdr;
245
246typedef struct {
247	Elf64_Word	p_type;
248	Elf64_Word	p_flags;
249	Elf64_Off	p_offset;	/* offset from the beginning of the file of the segment */
250	Elf64_Addr	p_vaddr;	/* virtual address for the segment in memory */
251	Elf64_Addr	p_paddr;
252	Elf64_Xword	p_filesz;	/* the size of the segment in the file */
253	Elf64_Xword	p_memsz;	/* the size of the segment in memory */
254	Elf64_Xword	p_align;
255
256#ifdef __cplusplus
257	bool IsReadWrite() const;
258	bool IsExecutable() const;
259#endif
260} Elf64_Phdr;
261
262/* program header segment types */
263#define PT_NULL			0
264#define PT_LOAD			1
265#define PT_DYNAMIC		2
266#define PT_INTERP		3
267#define PT_NOTE			4
268#define PT_SHLIB		5
269#define PT_PHDR			6
270#define PT_TLS			7
271#define PT_STACK		0x6474e551
272#define PT_RELRO		0x6474e552
273
274#define PT_LOPROC		0x70000000
275#define PT_ARM_UNWIND	0x70000001
276#define PT_HIPROC		0x7fffffff
277
278/* program header segment flags */
279#define PF_EXECUTE	0x1
280#define PF_WRITE	0x2
281#define PF_READ		0x4
282#define PF_PROTECTION_MASK (PF_EXECUTE | PF_WRITE | PF_READ)
283
284#define PF_MASKPROC	0xf0000000
285
286
287/* symbol table entry */
288
289typedef struct {
290	Elf32_Word	st_name;
291	Elf32_Addr	st_value;
292	Elf32_Word	st_size;
293	uint8		st_info;
294	uint8 		st_other;
295	Elf32_Half	st_shndx;
296
297#ifdef __cplusplus
298	uint8 Bind() const;
299	uint8 Type() const;
300	void SetInfo(uint8 bind, uint8 type);
301#endif
302} Elf32_Sym;
303
304typedef struct {
305	Elf64_Word	st_name;
306	uint8		st_info;
307	uint8		st_other;
308	Elf64_Half	st_shndx;
309	Elf64_Addr	st_value;
310	Elf64_Xword	st_size;
311
312#ifdef __cplusplus
313	uint8 Bind() const;
314	uint8 Type() const;
315	void SetInfo(uint8 bind, uint8 type);
316#endif
317} Elf64_Sym;
318
319#define ELF32_ST_BIND(i) ((i) >> 4)
320#define ELF32_ST_TYPE(i) ((i) & 0xf)
321#define ELF32_ST_INFO(b, t) (((b) << 4) + ((t) & 0xf))
322
323#define ELF64_ST_BIND(i) ((i) >> 4)
324#define ELF64_ST_TYPE(i) ((i) & 0xf)
325#define ELF64_ST_INFO(b, t) (((b) << 4) + ((t) & 0xf))
326
327/* symbol types */
328#define STT_NOTYPE 0
329#define STT_OBJECT 1
330#define STT_FUNC 2
331#define STT_SECTION 3
332#define STT_FILE 4
333#define STT_TLS		6
334#define STT_LOPROC 13
335#define STT_HIPROC 15
336
337/* symbol binding */
338#define STB_LOCAL 0
339#define STB_GLOBAL 1
340#define STB_WEAK 2
341#define STB_LOPROC 13
342#define STB_HIPROC 15
343
344/* special symbol indices */
345#define STN_UNDEF 0
346
347
348/* relocation table entry */
349
350typedef struct {
351	Elf32_Addr r_offset;
352	Elf32_Word r_info;
353
354#ifdef __cplusplus
355	uint8 SymbolIndex() const;
356	uint8 Type() const;
357#endif
358} Elf32_Rel;
359
360typedef struct {
361	Elf64_Addr	r_offset;
362	Elf64_Xword	r_info;
363
364#ifdef __cplusplus
365	uint8 SymbolIndex() const;
366	uint8 Type() const;
367#endif
368} Elf64_Rel;
369
370#ifdef __cplusplus
371typedef struct Elf32_Rela : public Elf32_Rel {
372#else
373typedef struct {
374	Elf32_Addr r_offset;
375	Elf32_Word r_info;
376#endif
377	Elf32_Sword r_addend;
378} Elf32_Rela;
379
380#ifdef __cplusplus
381typedef struct Elf64_Rela : public Elf64_Rel {
382#else
383typedef struct {
384	Elf64_Addr		r_offset;
385	Elf64_Xword		r_info;
386#endif
387	Elf64_Sxword	r_addend;
388} Elf64_Rela;
389
390#define ELF32_R_SYM(i) ((i) >> 8)
391#define ELF32_R_TYPE(i) ((unsigned char)(i))
392#define ELF32_R_INFO(s, t) (((s) << 8) + (unsigned char)(t))
393
394#define ELF64_R_SYM(i) ((i) >> 32)
395#define ELF64_R_TYPE(i) ((i) & 0xffffffffL)
396#define ELF64_R_INFO(s, t) ((((Elf64_Xword)(s)) << 32) + ((t) & 0xffffffffL))
397
398
399/* dynamic section entry */
400
401typedef struct {
402	Elf32_Sword d_tag;
403	union {
404		Elf32_Word d_val;
405		Elf32_Addr d_ptr;
406	} d_un;
407} Elf32_Dyn;
408
409typedef struct {
410	Elf64_Sxword d_tag;
411	union {
412		Elf64_Xword	d_val;
413		Elf64_Addr	d_ptr;
414	} d_un;
415} Elf64_Dyn;
416
417/* dynamic entry type */
418#define DT_NULL				0
419#define DT_NEEDED			1
420#define DT_PLTRELSZ			2
421#define DT_PLTGOT			3
422#define DT_HASH				4
423#define DT_STRTAB			5
424#define DT_SYMTAB			6
425#define DT_RELA				7
426#define DT_RELASZ			8
427#define DT_RELAENT			9
428#define DT_STRSZ			10
429#define DT_SYMENT			11
430#define DT_INIT				12
431#define DT_FINI				13
432#define DT_SONAME			14
433#define DT_RPATH			15
434#define DT_SYMBOLIC			16
435#define DT_REL				17
436#define DT_RELSZ			18
437#define DT_RELENT			19
438#define DT_PLTREL			20
439#define DT_DEBUG			21
440#define DT_TEXTREL			22
441#define DT_JMPREL			23
442#define DT_BIND_NOW			24	/* no lazy binding */
443#define DT_INIT_ARRAY		25	/* init function array */
444#define DT_FINI_ARRAY		26	/* termination function array */
445#define DT_INIT_ARRAYSZ		27	/* init function array size */
446#define DT_FINI_ARRAYSZ		28	/* termination function array size */
447#define DT_RUNPATH			29	/* library search path (supersedes DT_RPATH) */
448#define DT_FLAGS			30	/* flags (see below) */
449#define DT_ENCODING			32
450#define DT_PREINIT_ARRAY	32	/* preinitialization array */
451#define DT_PREINIT_ARRAYSZ	33	/* preinitialization array size */
452
453#define DT_VERSYM       0x6ffffff0	/* symbol version table */
454#define DT_VERDEF		0x6ffffffc	/* version definition table */
455#define DT_VERDEFNUM	0x6ffffffd	/* number of version definitions */
456#define DT_VERNEED		0x6ffffffe 	/* table with needed versions */
457#define DT_VERNEEDNUM	0x6fffffff	/* number of needed versions */
458
459#define DT_LOPROC		0x70000000
460#define DT_HIPROC		0x7fffffff
461
462/* DT_FLAGS values */
463#define DF_ORIGIN		0x01
464#define DF_SYMBOLIC		0x02
465#define DF_TEXTREL		0x04
466#define DF_BIND_NOW		0x08
467#define DF_STATIC_TLS	0x10
468
469
470/* version definition section */
471
472typedef struct {
473	Elf32_Half	vd_version;		/* version revision */
474	Elf32_Half	vd_flags;		/* version information flags */
475	Elf32_Half	vd_ndx;			/* version index as specified in the
476								   symbol version table */
477	Elf32_Half	vd_cnt;			/* number of associated verdaux entries */
478	Elf32_Word	vd_hash;		/* version name hash value */
479	Elf32_Word	vd_aux;			/* byte offset to verdaux array */
480	Elf32_Word	vd_next;		/* byte offset to next verdef entry */
481} Elf32_Verdef;
482
483typedef struct {
484	Elf64_Half	vd_version;		/* version revision */
485	Elf64_Half	vd_flags;		/* version information flags */
486	Elf64_Half	vd_ndx;			/* version index as specified in the
487								   symbol version table */
488	Elf64_Half	vd_cnt;			/* number of associated verdaux entries */
489	Elf64_Word	vd_hash;		/* version name hash value */
490	Elf64_Word	vd_aux;			/* byte offset to verdaux array */
491	Elf64_Word	vd_next;		/* byte offset to next verdef entry */
492} Elf64_Verdef;
493
494/* values for vd_version (version revision) */
495#define VER_DEF_NONE		0		/* no version */
496#define VER_DEF_CURRENT		1		/* current version */
497#define VER_DEF_NUM			2		/* given version number */
498
499/* values for vd_flags (version information flags) */
500#define VER_FLG_BASE		0x1		/* version definition of file itself */
501#define VER_FLG_WEAK		0x2 	/* weak version identifier */
502
503/* values for versym symbol index */
504#define VER_NDX_LOCAL		0		/* symbol is local */
505#define VER_NDX_GLOBAL		1		/* symbol is global/unversioned */
506#define VER_NDX_INITIAL		2		/* initial version -- that's the one given
507									   to symbols when a library becomes
508									   versioned; handled by the linker (and
509									   runtime loader) similar to
510									   VER_NDX_GLOBAL */
511#define VER_NDX_LORESERVE	0xff00	/* beginning of reserved entries */
512#define VER_NDX_ELIMINATE	0xff01	/* symbol is to be eliminated */
513
514#define VER_NDX_FLAG_HIDDEN	0x8000	/* flag: version is hidden */
515#define VER_NDX_MASK		0x7fff	/* mask to get the actual version index */
516#define VER_NDX(x)			((x) & VER_NDX_MASK)
517
518
519/* auxiliary version information */
520
521typedef struct {
522	Elf32_Word	vda_name;		/* string table offset to version or dependency
523								   name */
524	Elf32_Word	vda_next;		/* byte offset to next verdaux entry */
525} Elf32_Verdaux;
526
527typedef struct {
528	Elf64_Word	vda_name;		/* string table offset to version or dependency
529								   name */
530	Elf64_Word	vda_next;		/* byte offset to next verdaux entry */
531} Elf64_Verdaux;
532
533
534/* version dependency section */
535
536typedef struct {
537	Elf32_Half	vn_version;		/* version of structure */
538	Elf32_Half	vn_cnt;			/* number of associated vernaux entries */
539	Elf32_Word	vn_file;		/* byte offset to file name for this
540								   dependency */
541	Elf32_Word	vn_aux;			/* byte offset to vernaux array */
542	Elf32_Word	vn_next;		/* byte offset to next verneed entry */
543} Elf32_Verneed;
544
545typedef struct {
546	Elf64_Half	vn_version;		/* version of structure */
547	Elf64_Half	vn_cnt;			/* number of associated vernaux entries */
548	Elf64_Word	vn_file;		/* byte offset to file name for this
549								   dependency */
550	Elf64_Word	vn_aux;			/* byte offset to vernaux array */
551	Elf64_Word	vn_next;		/* byte offset to next verneed entry */
552} Elf64_Verneed;
553
554/* values for vn_version (version revision) */
555#define VER_NEED_NONE		0	/* no version */
556#define VER_NEED_CURRENT	1	/* current version */
557#define VER_NEED_NUM		2	/* given version number */
558
559
560/* auxiliary needed version information */
561
562typedef struct {
563	Elf32_Word	vna_hash;		/* dependency name hash value */
564	Elf32_Half	vna_flags;		/* dependency specific information flags */
565	Elf32_Half	vna_other;		/* version index as specified in the symbol
566								   version table */
567	Elf32_Word	vna_name;		/* string table offset to dependency name */
568	Elf32_Word	vna_next;		/* byte offset to next vernaux entry */
569} Elf32_Vernaux;
570
571typedef struct {
572	Elf64_Word	vna_hash;		/* dependency name hash value */
573	Elf64_Half	vna_flags;		/* dependency specific information flags */
574	Elf64_Half	vna_other;		/* version index as specified in the symbol
575								   version table */
576	Elf64_Word	vna_name;		/* string table offset to dependency name */
577	Elf64_Word	vna_next;		/* byte offset to next vernaux entry */
578} Elf64_Vernaux;
579
580/* values for vna_flags */
581#define VER_FLG_WEAK	0x2		/* weak version identifier */
582
583
584/*** core files ***/
585
586/* note section header */
587
588typedef struct {
589	Elf32_Word n_namesz;		/* length of the note's name */
590	Elf32_Word n_descsz;		/* length of the note's descriptor */
591	Elf32_Word n_type;			/* note type */
592} Elf32_Nhdr;
593
594typedef struct {
595	Elf64_Word n_namesz;		/* length of the note's name */
596	Elf64_Word n_descsz;		/* length of the note's descriptor */
597	Elf64_Word n_type;			/* note type */
598} Elf64_Nhdr;
599
600/* values for note name */
601#define ELF_NOTE_CORE		"CORE"
602#define ELF_NOTE_HAIKU		"Haiku"
603
604/* values for note type (n_type) */
605/* ELF_NOTE_CORE/... */
606#define NT_FILE				0x46494c45 /* mapped files */
607
608/* ELF_NOTE_HAIKU/... */
609#define NT_TEAM				0x7465616d 	/* team */
610#define NT_AREAS			0x61726561 	/* areas */
611#define NT_IMAGES			0x696d6167 	/* images */
612#define NT_THREADS			0x74687264 	/* threads */
613
614/* NT_TEAM: uint32 entrySize; Elf32_Note_Team; char[] args */
615typedef struct {
616	int32		nt_id;				/* team ID */
617	int32		nt_uid;				/* team owner ID */
618	int32		nt_gid;				/* team group ID */
619} Elf32_Note_Team;
620
621typedef Elf32_Note_Team Elf64_Note_Team;
622
623/* NT_AREAS:
624 * uint32 count;
625 * uint32 entrySize;
626 * Elf32_Note_Area_Entry[count];
627 * char[] names
628 */
629typedef struct {
630	int32		na_id;				/* area ID */
631	uint32		na_lock;			/* lock type (B_NO_LOCK, ...) */
632	uint32		na_protection;		/* protection (B_READ_AREA | ...) */
633	uint32		na_base;			/* area base address */
634	uint32		na_size;			/* area size */
635	uint32		na_ram_size;		/* physical memory used */
636} Elf32_Note_Area_Entry;
637
638/* NT_AREAS:
639 * uint32 count;
640 * uint32 entrySize;
641 * Elf64_Note_Area_Entry[count];
642 * char[] names
643 */
644typedef struct {
645	int32		na_id;				/* area ID */
646	uint32		na_lock;			/* lock type (B_NO_LOCK, ...) */
647	uint32		na_protection;		/* protection (B_READ_AREA | ...) */
648	uint32		na_pad1;
649	uint64		na_base;			/* area base address */
650	uint64		na_size;			/* area size */
651	uint64		na_ram_size;		/* physical memory used */
652} Elf64_Note_Area_Entry;
653
654/* NT_IMAGES:
655 * uint32 count;
656 * uint32 entrySize;
657 * Elf32_Note_Image_Entry[count];
658 * char[] names
659 */
660typedef struct {
661	int32		ni_id;				/* image ID */
662	int32		ni_type;			/* image type (B_APP_IMAGE, ...) */
663	uint32		ni_init_routine;	/* address of init function */
664	uint32		ni_term_routine;	/* address of termination function */
665	int32		ni_device;			/* device ID of mapped file */
666	int64		ni_node;			/* node ID of mapped file */
667	uint32		ni_text_base;		/* base address of text segment */
668	uint32		ni_text_size;		/* size of text segment */
669	uint32		ni_data_base;		/* base address of data segment */
670	uint32		ni_data_size;		/* size of data segment */
671} Elf32_Note_Image_Entry;
672
673/* NT_IMAGES:
674 * uint32 count;
675 * uint32 entrySize;
676 * Elf64_Note_Image_Entry[count];
677 * char[] names
678 */
679typedef struct {
680	int32		ni_id;				/* image ID */
681	int32		ni_type;			/* image type (B_APP_IMAGE, ...) */
682	uint64		ni_init_routine;	/* address of init function */
683	uint64		ni_term_routine;	/* address of termination function */
684	uint32		ni_pad1;
685	int32		ni_device;			/* device ID of mapped file */
686	int64		ni_node;			/* node ID of mapped file */
687	uint64		ni_text_base;		/* base address of text segment */
688	uint64		ni_text_size;		/* size of text segment */
689	uint64		ni_data_base;		/* base address of data segment */
690	uint64		ni_data_size;		/* size of data segment */
691} Elf64_Note_Image_Entry;
692
693/* NT_THREADS:
694 * uint32 count;
695 * uint32 entrySize;
696 * uint32 cpuStateSize;
697 * {Elf32_Note_Thread_Entry, uint8[cpuStateSize] cpuState}[count];
698 * char[] names
699 */
700typedef struct {
701	int32		nth_id;				/* thread ID */
702	int32		nth_state;			/* thread state (B_THREAD_RUNNING, ...) */
703	int32		nth_priority;		/* thread priority */
704	uint32		nth_stack_base;		/* thread stack base address */
705	uint32		nth_stack_end;		/* thread stack end address */
706} Elf32_Note_Thread_Entry;
707
708/* NT_THREADS:
709 * uint32 count;
710 * uint32 entrySize;
711 * uint32 cpuStateSize;
712 * {Elf64_Note_Thread_Entry, uint8[cpuStateSize] cpuState}[count];
713 * char[] names
714 */
715typedef struct {
716	int32		nth_id;				/* thread ID */
717	int32		nth_state;			/* thread state (B_THREAD_RUNNING, ...) */
718	int32		nth_priority;		/* thread priority */
719	uint32		nth_pad1;
720	uint64		nth_stack_base;		/* thread stack base address */
721	uint64		nth_stack_end;		/* thread stack end address */
722} Elf64_Note_Thread_Entry;
723
724
725/*** inline functions ***/
726
727#ifdef __cplusplus
728
729inline bool
730Elf32_Ehdr::IsHostEndian() const
731{
732#if B_HOST_IS_LENDIAN
733	return e_ident[EI_DATA] == ELFDATA2LSB;
734#elif B_HOST_IS_BENDIAN
735	return e_ident[EI_DATA] == ELFDATA2MSB;
736#endif
737}
738
739
740inline bool
741Elf64_Ehdr::IsHostEndian() const
742{
743#if B_HOST_IS_LENDIAN
744	return e_ident[EI_DATA] == ELFDATA2LSB;
745#elif B_HOST_IS_BENDIAN
746	return e_ident[EI_DATA] == ELFDATA2MSB;
747#endif
748}
749
750
751inline bool
752Elf32_Phdr::IsReadWrite() const
753{
754	return !(~p_flags & (PF_READ | PF_WRITE));
755}
756
757
758inline bool
759Elf32_Phdr::IsExecutable() const
760{
761	return (p_flags & PF_EXECUTE) != 0;
762}
763
764
765inline bool
766Elf64_Phdr::IsReadWrite() const
767{
768	return !(~p_flags & (PF_READ | PF_WRITE));
769}
770
771
772inline bool
773Elf64_Phdr::IsExecutable() const
774{
775	return (p_flags & PF_EXECUTE) != 0;
776}
777
778
779inline uint8
780Elf32_Sym::Bind() const
781{
782	return ELF32_ST_BIND(st_info);
783}
784
785
786inline uint8
787Elf32_Sym::Type() const
788{
789	return ELF32_ST_TYPE(st_info);
790}
791
792
793inline void
794Elf32_Sym::SetInfo(uint8 bind, uint8 type)
795{
796	st_info = ELF32_ST_INFO(bind, type);
797}
798
799
800inline uint8
801Elf64_Sym::Bind() const
802{
803	return ELF64_ST_BIND(st_info);
804}
805
806
807inline uint8
808Elf64_Sym::Type() const
809{
810	return ELF64_ST_TYPE(st_info);
811}
812
813
814inline void
815Elf64_Sym::SetInfo(uint8 bind, uint8 type)
816{
817	st_info = ELF64_ST_INFO(bind, type);
818}
819
820
821inline uint8
822Elf32_Rel::SymbolIndex() const
823{
824	return ELF32_R_SYM(r_info);
825}
826
827
828inline uint8
829Elf32_Rel::Type() const
830{
831	return ELF32_R_TYPE(r_info);
832}
833
834
835inline uint8
836Elf64_Rel::SymbolIndex() const
837{
838	return ELF64_R_SYM(r_info);
839}
840
841
842inline uint8
843Elf64_Rel::Type() const
844{
845	return ELF64_R_TYPE(r_info);
846}
847
848#endif	/* __cplusplus */
849
850
851#endif	/* _ELF_H */
852