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