blob: ec54a601ac9d415a582de4b8c39bc52197e74a61 [file] [log] [blame]
Elliott Hughese4d792a2013-10-28 14:19:05 -07001/* $NetBSD: exec_elf.h,v 1.129 2013/09/10 16:24:02 matt Exp $ */
Elliott Hughesa6a3ac52013-01-29 15:02:50 -08002
3/*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08009 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080018 *
Elliott Hughesa6a3ac52013-01-29 15:02:50 -080019 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080030 */
31
32#ifndef _SYS_EXEC_ELF_H_
33#define _SYS_EXEC_ELF_H_
34
Elliott Hughesa6a3ac52013-01-29 15:02:50 -080035/*
36 * The current ELF ABI specification is available at:
37 * http://www.sco.com/developers/gabi/
38 *
39 * Current header definitions are in:
40 * http://www.sco.com/developers/gabi/latest/ch4.eheader.html
41 */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042
Elliott Hughesa6a3ac52013-01-29 15:02:50 -080043#if defined(_KERNEL) || defined(_STANDALONE)
44#include <sys/types.h>
45#else
46#include <inttypes.h>
47#endif /* _KERNEL || _STANDALONE */
48
49#if HAVE_NBTOOL_CONFIG_H
50#include <nbinclude/machine/elf_machdep.h>
51#else
52#include <machine/elf_machdep.h>
53#endif
54
55typedef uint8_t Elf_Byte;
56
57typedef uint32_t Elf32_Addr;
58#define ELF32_FSZ_ADDR 4
59typedef uint32_t Elf32_Off;
60typedef int32_t Elf32_SOff;
61#define ELF32_FSZ_OFF 4
62typedef int32_t Elf32_Sword;
63#define ELF32_FSZ_SWORD 4
64typedef uint32_t Elf32_Word;
65#define ELF32_FSZ_WORD 4
66typedef uint16_t Elf32_Half;
67#define ELF32_FSZ_HALF 2
68typedef uint64_t Elf32_Lword;
69#define ELF32_FSZ_LWORD 8
70
71typedef uint64_t Elf64_Addr;
72#define ELF64_FSZ_ADDR 8
73typedef uint64_t Elf64_Off;
74typedef int64_t Elf64_SOff;
75#define ELF64_FSZ_OFF 8
76typedef int32_t Elf64_Shalf;
77#define ELF64_FSZ_SHALF 4
78
79typedef int32_t Elf64_Sword;
80#define ELF64_FSZ_SWORD 4
81typedef uint32_t Elf64_Word;
82#define ELF64_FSZ_WORD 4
83
84typedef int64_t Elf64_Sxword;
85#define ELF64_FSZ_SXWORD 8
86typedef uint64_t Elf64_Xword;
87#define ELF64_FSZ_XWORD 8
88typedef uint64_t Elf64_Lword;
89#define ELF64_FSZ_LWORD 8
90typedef uint16_t Elf64_Half;
91#define ELF64_FSZ_HALF 2
92
93/*
94 * ELF Header
95 */
96#define ELF_NIDENT 16
97
98typedef struct {
99 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
100 Elf32_Half e_type; /* file type */
101 Elf32_Half e_machine; /* machine type */
102 Elf32_Word e_version; /* version number */
103 Elf32_Addr e_entry; /* entry point */
104 Elf32_Off e_phoff; /* Program hdr offset */
105 Elf32_Off e_shoff; /* Section hdr offset */
106 Elf32_Word e_flags; /* Processor flags */
107 Elf32_Half e_ehsize; /* sizeof ehdr */
108 Elf32_Half e_phentsize; /* Program header entry size */
109 Elf32_Half e_phnum; /* Number of program headers */
110 Elf32_Half e_shentsize; /* Section header entry size */
111 Elf32_Half e_shnum; /* Number of section headers */
112 Elf32_Half e_shstrndx; /* String table index */
113} Elf32_Ehdr;
114
115typedef struct {
116 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
117 Elf64_Half e_type; /* file type */
118 Elf64_Half e_machine; /* machine type */
119 Elf64_Word e_version; /* version number */
120 Elf64_Addr e_entry; /* entry point */
121 Elf64_Off e_phoff; /* Program hdr offset */
122 Elf64_Off e_shoff; /* Section hdr offset */
123 Elf64_Word e_flags; /* Processor flags */
124 Elf64_Half e_ehsize; /* sizeof ehdr */
125 Elf64_Half e_phentsize; /* Program header entry size */
126 Elf64_Half e_phnum; /* Number of program headers */
127 Elf64_Half e_shentsize; /* Section header entry size */
128 Elf64_Half e_shnum; /* Number of section headers */
129 Elf64_Half e_shstrndx; /* String table index */
130} Elf64_Ehdr;
131
132/* e_ident offsets */
133#define EI_MAG0 0 /* '\177' */
134#define EI_MAG1 1 /* 'E' */
135#define EI_MAG2 2 /* 'L' */
136#define EI_MAG3 3 /* 'F' */
137#define EI_CLASS 4 /* File class */
138#define EI_DATA 5 /* Data encoding */
139#define EI_VERSION 6 /* File version */
140#define EI_OSABI 7 /* Operating system/ABI identification */
141#define EI_ABIVERSION 8 /* ABI version */
142#define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/
143#define EI_NIDENT 16 /* First non-ident header byte */
144
145/* e_ident[EI_MAG0,EI_MAG3] */
146#define ELFMAG0 0x7f
147#define ELFMAG1 'E'
148#define ELFMAG2 'L'
149#define ELFMAG3 'F'
150#define ELFMAG "\177ELF"
151#define SELFMAG 4
152
153/* e_ident[EI_CLASS] */
154#define ELFCLASSNONE 0 /* Invalid class */
155#define ELFCLASS32 1 /* 32-bit objects */
156#define ELFCLASS64 2 /* 64-bit objects */
157#define ELFCLASSNUM 3
158
159/* e_ident[EI_DATA] */
160#define ELFDATANONE 0 /* Invalid data encoding */
161#define ELFDATA2LSB 1 /* 2's complement values, LSB first */
162#define ELFDATA2MSB 2 /* 2's complement values, MSB first */
163
164/* e_ident[EI_VERSION] */
165#define EV_NONE 0 /* Invalid version */
166#define EV_CURRENT 1 /* Current version */
167#define EV_NUM 2
168
169/* e_ident[EI_OSABI] */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800170#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
171#define ELFOSABI_HPUX 1 /* HP-UX operating system */
172#define ELFOSABI_NETBSD 2 /* NetBSD */
173#define ELFOSABI_LINUX 3 /* GNU/Linux */
174#define ELFOSABI_HURD 4 /* GNU/Hurd */
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800175#define ELFOSABI_86OPEN 5 /* 86Open */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800176#define ELFOSABI_SOLARIS 6 /* Solaris */
177#define ELFOSABI_MONTEREY 7 /* Monterey */
178#define ELFOSABI_IRIX 8 /* IRIX */
179#define ELFOSABI_FREEBSD 9 /* FreeBSD */
180#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
181#define ELFOSABI_MODESTO 11 /* Novell Modesto */
182#define ELFOSABI_OPENBSD 12 /* OpenBSD */
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800183#define ELFOSABI_OPENVMS 13 /* OpenVMS */
184#define ELFOSABI_NSK 14 /* HP Non-Stop Kernel */
185#define ELFOSABI_AROS 15 /* Amiga Research OS */
186/* Unofficial OSABIs follow */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800187#define ELFOSABI_ARM 97 /* ARM */
188#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
189
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800190#define ELFOSABI_NONE ELFOSABI_SYSV
191#define ELFOSABI_AIX ELFOSABI_MONTEREY
192
193/* e_type */
194#define ET_NONE 0 /* No file type */
195#define ET_REL 1 /* Relocatable file */
196#define ET_EXEC 2 /* Executable file */
197#define ET_DYN 3 /* Shared object file */
198#define ET_CORE 4 /* Core file */
199#define ET_NUM 5
200
201#define ET_LOOS 0xfe00 /* Operating system specific range */
202#define ET_HIOS 0xfeff
203#define ET_LOPROC 0xff00 /* Processor-specific range */
204#define ET_HIPROC 0xffff
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800205
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800206/* e_machine */
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800207#define EM_NONE 0 /* No machine */
208#define EM_M32 1 /* AT&T WE 32100 */
209#define EM_SPARC 2 /* SPARC */
210#define EM_386 3 /* Intel 80386 */
211#define EM_68K 4 /* Motorola 68000 */
212#define EM_88K 5 /* Motorola 88000 */
213#define EM_486 6 /* Intel 80486 */
214#define EM_860 7 /* Intel 80860 */
215#define EM_MIPS 8 /* MIPS I Architecture */
216#define EM_S370 9 /* Amdahl UTS on System/370 */
217#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
218 /* 11-14 - Reserved */
219#define EM_RS6000 11 /* IBM RS/6000 XXX reserved */
220#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */
221#define EM_NCUBE 16 /* NCube XXX reserved */
222#define EM_VPP500 17 /* Fujitsu VPP500 */
223#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
224#define EM_960 19 /* Intel 80960 */
225#define EM_PPC 20 /* PowerPC */
226#define EM_PPC64 21 /* 64-bit PowerPC */
227 /* 22-35 - Reserved */
228#define EM_S390 22 /* System/390 XXX reserved */
229#define EM_V800 36 /* NEC V800 */
230#define EM_FR20 37 /* Fujitsu FR20 */
231#define EM_RH32 38 /* TRW RH-32 */
232#define EM_RCE 39 /* Motorola RCE */
233#define EM_ARM 40 /* Advanced RISC Machines ARM */
234#define EM_ALPHA 41 /* DIGITAL Alpha */
235#define EM_SH 42 /* Hitachi Super-H */
236#define EM_SPARCV9 43 /* SPARC Version 9 */
237#define EM_TRICORE 44 /* Siemens Tricore */
238#define EM_ARC 45 /* Argonaut RISC Core */
239#define EM_H8_300 46 /* Hitachi H8/300 */
240#define EM_H8_300H 47 /* Hitachi H8/300H */
241#define EM_H8S 48 /* Hitachi H8S */
242#define EM_H8_500 49 /* Hitachi H8/500 */
243#define EM_IA_64 50 /* Intel Merced Processor */
244#define EM_MIPS_X 51 /* Stanford MIPS-X */
245#define EM_COLDFIRE 52 /* Motorola Coldfire */
246#define EM_68HC12 53 /* Motorola MC68HC12 */
247#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */
248#define EM_PCP 55 /* Siemens PCP */
249#define EM_NCPU 56 /* Sony nCPU embedded RISC processor */
250#define EM_NDR1 57 /* Denso NDR1 microprocessor */
251#define EM_STARCORE 58 /* Motorola Star*Core processor */
252#define EM_ME16 59 /* Toyota ME16 processor */
253#define EM_ST100 60 /* STMicroelectronics ST100 processor */
254#define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded family processor */
255#define EM_X86_64 62 /* AMD x86-64 architecture */
256#define EM_PDSP 63 /* Sony DSP Processor */
257#define EM_PDP10 64 /* Digital Equipment Corp. PDP-10 */
258#define EM_PDP11 65 /* Digital Equipment Corp. PDP-11 */
259#define EM_FX66 66 /* Siemens FX66 microcontroller */
260#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */
261#define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */
262#define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */
263#define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */
264#define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */
265#define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */
266#define EM_SVX 73 /* Silicon Graphics SVx */
267#define EM_ST19 74 /* STMicroelectronics ST19 8-bit CPU */
268#define EM_VAX 75 /* Digital VAX */
269#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
270#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded CPU */
271#define EM_FIREPATH 78 /* Element 14 64-bit DSP processor */
272#define EM_ZSP 79 /* LSI Logic's 16-bit DSP processor */
273#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */
274#define EM_HUANY 81 /* Harvard's machine-independent format */
275#define EM_PRISM 82 /* SiTera Prism */
276#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
277#define EM_FR30 84 /* Fujitsu FR30 */
278#define EM_D10V 85 /* Mitsubishi D10V */
279#define EM_D30V 86 /* Mitsubishi D30V */
280#define EM_V850 87 /* NEC v850 */
281#define EM_M32R 88 /* Mitsubishi M32R */
282#define EM_MN10300 89 /* Matsushita MN10300 */
283#define EM_MN10200 90 /* Matsushita MN10200 */
284#define EM_PJ 91 /* picoJava */
285#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
286#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */
287#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */
288#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor */
289#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Processor */
290#define EM_NS32K 97 /* National Semiconductor 32000 series */
291#define EM_TPC 98 /* Tenor Network TPC processor */
292#define EM_SNP1K 99 /* Trebia SNP 1000 processor */
293#define EM_ST200 100 /* STMicroelectronics ST200 microcontroller */
294#define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family */
295#define EM_MAX 102 /* MAX processor */
296#define EM_CR 103 /* National Semiconductor CompactRISC micorprocessor */
297#define EM_F2MC16 104 /* Fujitsu F2MC16 */
298#define EM_MSP430 105 /* Texas Instruments MSP430 */
299#define EM_BLACKFIN 106 /* Analog Devices Blackfin DSP */
300#define EM_SE_C33 107 /* Seiko Epson S1C33 family */
301#define EM_SEP 108 /* Sharp embedded microprocessor */
302#define EM_ARCA 109 /* Arca RISC microprocessor */
303#define EM_UNICORE 110 /* UNICORE from PKU-Unity Ltd. and MPRC Peking University */
304
305/* Unofficial machine types follow */
306#define EM_AVR32 6317 /* used by NetBSD/avr32 */
307#define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */
308#define EM_NUM 36903
309
310/*
311 * Program Header
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800312 */
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800313typedef struct {
314 Elf32_Word p_type; /* entry type */
315 Elf32_Off p_offset; /* offset */
316 Elf32_Addr p_vaddr; /* virtual address */
317 Elf32_Addr p_paddr; /* physical address */
318 Elf32_Word p_filesz; /* file size */
319 Elf32_Word p_memsz; /* memory size */
320 Elf32_Word p_flags; /* flags */
321 Elf32_Word p_align; /* memory & file alignment */
322} Elf32_Phdr;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800323
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800324typedef struct {
325 Elf64_Word p_type; /* entry type */
326 Elf64_Word p_flags; /* flags */
327 Elf64_Off p_offset; /* offset */
328 Elf64_Addr p_vaddr; /* virtual address */
329 Elf64_Addr p_paddr; /* physical address */
330 Elf64_Xword p_filesz; /* file size */
331 Elf64_Xword p_memsz; /* memory size */
332 Elf64_Xword p_align; /* memory & file alignment */
333} Elf64_Phdr;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800334
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800335/* p_type */
336#define PT_NULL 0 /* Program header table entry unused */
337#define PT_LOAD 1 /* Loadable program segment */
338#define PT_DYNAMIC 2 /* Dynamic linking information */
339#define PT_INTERP 3 /* Program interpreter */
340#define PT_NOTE 4 /* Auxiliary information */
341#define PT_SHLIB 5 /* Reserved, unspecified semantics */
342#define PT_PHDR 6 /* Entry for header table itself */
343#define PT_TLS 7 /* TLS initialisation image */
344#define PT_NUM 8
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800345
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800346#define PT_LOOS 0x60000000 /* OS-specific range */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800347
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800348/* GNU-specific */
349#define PT_GNU_EH_FRAME 0x6474e550 /* EH frame segment */
350#define PT_GNU_STACK 0x6474e551 /* Indicate executable stack */
351#define PT_GNU_RELRO 0x6474e552 /* Make read-only after relocation */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800352
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800353#define PT_HIOS 0x6fffffff
354#define PT_LOPROC 0x70000000 /* Processor-specific range */
355#define PT_HIPROC 0x7fffffff
Nick Kralevich9ec0f032012-02-28 10:40:00 -0800356
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800357#define PT_MIPS_REGINFO 0x70000000
358
359/* p_flags */
360#define PF_R 0x4 /* Segment is readable */
361#define PF_W 0x2 /* Segment is writable */
362#define PF_X 0x1 /* Segment is executable */
363
364#define PF_MASKOS 0x0ff00000 /* Operating system specific values */
365#define PF_MASKPROC 0xf0000000 /* Processor-specific values */
366
367/* Extended program header index. */
368#define PN_XNUM 0xffff
369
370/*
371 * Section Headers
372 */
373typedef struct {
374 Elf32_Word sh_name; /* section name (.shstrtab index) */
375 Elf32_Word sh_type; /* section type */
376 Elf32_Word sh_flags; /* section flags */
377 Elf32_Addr sh_addr; /* virtual address */
378 Elf32_Off sh_offset; /* file offset */
379 Elf32_Word sh_size; /* section size */
380 Elf32_Word sh_link; /* link to another */
381 Elf32_Word sh_info; /* misc info */
382 Elf32_Word sh_addralign; /* memory alignment */
383 Elf32_Word sh_entsize; /* table entry size */
384} Elf32_Shdr;
385
386typedef struct {
387 Elf64_Word sh_name; /* section name (.shstrtab index) */
388 Elf64_Word sh_type; /* section type */
389 Elf64_Xword sh_flags; /* section flags */
390 Elf64_Addr sh_addr; /* virtual address */
391 Elf64_Off sh_offset; /* file offset */
392 Elf64_Xword sh_size; /* section size */
393 Elf64_Word sh_link; /* link to another */
394 Elf64_Word sh_info; /* misc info */
395 Elf64_Xword sh_addralign; /* memory alignment */
396 Elf64_Xword sh_entsize; /* table entry size */
397} Elf64_Shdr;
398
399/* sh_type */
400#define SHT_NULL 0 /* Section header table entry unused */
401#define SHT_PROGBITS 1 /* Program information */
402#define SHT_SYMTAB 2 /* Symbol table */
403#define SHT_STRTAB 3 /* String table */
404#define SHT_RELA 4 /* Relocation information w/ addend */
405#define SHT_HASH 5 /* Symbol hash table */
406#define SHT_DYNAMIC 6 /* Dynamic linking information */
407#define SHT_NOTE 7 /* Auxiliary information */
408#define SHT_NOBITS 8 /* No space allocated in file image */
409#define SHT_REL 9 /* Relocation information w/o addend */
410#define SHT_SHLIB 10 /* Reserved, unspecified semantics */
411#define SHT_DYNSYM 11 /* Symbol table for dynamic linker */
412#define SHT_INIT_ARRAY 14 /* Initialization function pointers */
413#define SHT_FINI_ARRAY 15 /* Termination function pointers */
414#define SHT_PREINIT_ARRAY 16 /* Pre-initialization function ptrs */
415#define SHT_GROUP 17 /* Section group */
416#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX) */
417#define SHT_NUM 19
418
419#define SHT_LOOS 0x60000000 /* Operating system specific range */
420#define SHT_GNU_HASH 0x6ffffff6 /* GNU style symbol hash table */
421#define SHT_SUNW_move 0x6ffffffa
422#define SHT_SUNW_syminfo 0x6ffffffc
423#define SHT_SUNW_verdef 0x6ffffffd /* Versions defined by file */
424#define SHT_GNU_verdef SHT_SUNW_verdef
425#define SHT_SUNW_verneed 0x6ffffffe /* Versions needed by file */
426#define SHT_GNU_verneed SHT_SUNW_verneed
427#define SHT_SUNW_versym 0x6fffffff /* Symbol versions */
428#define SHT_GNU_versym SHT_SUNW_versym
429#define SHT_HIOS 0x6fffffff
430#define SHT_LOPROC 0x70000000 /* Processor-specific range */
431#define SHT_AMD64_UNWIND 0x70000001 /* unwind information */
Elliott Hughese4d792a2013-10-28 14:19:05 -0700432#define SHT_ARM_EXIDX 0x70000001 /* exception index table */
433#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking
434 * pre-emption map */
435#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility
436 * attributes */
437#define SHT_ARM_DEBUGOVERLAY 0x70000004 /* See DBGOVL for details */
438#define SHT_ARM_OVERLAYSECTION 0x70000005
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800439#define SHT_HIPROC 0x7fffffff
440#define SHT_LOUSER 0x80000000 /* Application-specific range */
441#define SHT_HIUSER 0xffffffff
442
443/* sh_flags */
444#define SHF_WRITE 0x00000001 /* Contains writable data */
445#define SHF_ALLOC 0x00000002 /* Occupies memory */
446#define SHF_EXECINSTR 0x00000004 /* Contains executable insns */
447#define SHF_MERGE 0x00000010 /* Might be merged */
448#define SHF_STRINGS 0x00000020 /* Contains nul terminated strings */
449#define SHF_INFO_LINK 0x00000040 /* "sh_info" contains SHT index */
450#define SHF_LINK_ORDER 0x00000080 /* Preserve order after combining */
451#define SHF_OS_NONCONFORMING 0x00000100 /* OS specific handling required */
452#define SHF_GROUP 0x00000200 /* Is member of a group */
453#define SHF_TLS 0x00000400 /* Holds thread-local data */
454#define SHF_MASKOS 0x0ff00000 /* Operating system specific values */
455#define SHF_MASKPROC 0xf0000000 /* Processor-specific values */
456#define SHF_ORDERED 0x40000000 /* Ordering requirement (Solaris) */
457#define SHF_EXCLUDE 0x80000000 /* Excluded unless unles ref/alloc
458 (Solaris).*/
459/*
460 * Symbol Table
461 */
462typedef struct {
463 Elf32_Word st_name; /* Symbol name (.strtab index) */
464 Elf32_Word st_value; /* value of symbol */
465 Elf32_Word st_size; /* size of symbol */
466 Elf_Byte st_info; /* type / binding attrs */
467 Elf_Byte st_other; /* unused */
468 Elf32_Half st_shndx; /* section index of symbol */
469} Elf32_Sym;
470
471typedef struct {
472 Elf64_Word st_name; /* Symbol name (.strtab index) */
473 Elf_Byte st_info; /* type / binding attrs */
474 Elf_Byte st_other; /* unused */
475 Elf64_Half st_shndx; /* section index of symbol */
476 Elf64_Addr st_value; /* value of symbol */
477 Elf64_Xword st_size; /* size of symbol */
478} Elf64_Sym;
479
480/* Symbol Table index of the undefined symbol */
481#define ELF_SYM_UNDEFINED 0
482
483#define STN_UNDEF 0 /* undefined index */
484
485/* st_info: Symbol Bindings */
486#define STB_LOCAL 0 /* local symbol */
487#define STB_GLOBAL 1 /* global symbol */
488#define STB_WEAK 2 /* weakly defined global symbol */
489#define STB_NUM 3
490
491#define STB_LOOS 10 /* Operating system specific range */
492#define STB_HIOS 12
493#define STB_LOPROC 13 /* Processor-specific range */
494#define STB_HIPROC 15
495
496/* st_info: Symbol Types */
497#define STT_NOTYPE 0 /* Type not specified */
498#define STT_OBJECT 1 /* Associated with a data object */
499#define STT_FUNC 2 /* Associated with a function */
500#define STT_SECTION 3 /* Associated with a section */
501#define STT_FILE 4 /* Associated with a file name */
502#define STT_COMMON 5 /* Uninitialised common block */
503#define STT_TLS 6 /* Thread local data object */
504#define STT_NUM 7
505
506#define STT_LOOS 10 /* Operating system specific range */
507#define STT_HIOS 12
508#define STT_LOPROC 13 /* Processor-specific range */
509#define STT_HIPROC 15
510
511/* st_other: Visibility Types */
512#define STV_DEFAULT 0 /* use binding type */
513#define STV_INTERNAL 1 /* not referenced from outside */
514#define STV_HIDDEN 2 /* not visible, may be used via ptr */
515#define STV_PROTECTED 3 /* visible, not preemptible */
516#define STV_EXPORTED 4
517#define STV_SINGLETON 5
518#define STV_ELIMINATE 6
519
520/* st_info/st_other utility macros */
521#define ELF_ST_BIND(info) ((uint32_t)(info) >> 4)
522#define ELF_ST_TYPE(info) ((uint32_t)(info) & 0xf)
523#define ELF_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | \
524 ((type) & 0xf)))
525#define ELF_ST_VISIBILITY(other) ((uint32_t)(other) & 3)
526
527/*
528 * Special section indexes
529 */
530#define SHN_UNDEF 0 /* Undefined section */
531
532#define SHN_LORESERVE 0xff00 /* Reserved range */
533#define SHN_ABS 0xfff1 /* Absolute symbols */
534#define SHN_COMMON 0xfff2 /* Common symbols */
535#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere */
536#define SHN_HIRESERVE 0xffff
537
538#define SHN_LOPROC 0xff00 /* Processor-specific range */
539#define SHN_HIPROC 0xff1f
540#define SHN_LOOS 0xff20 /* Operating system specific range */
541#define SHN_HIOS 0xff3f
542
543#define SHN_MIPS_ACOMMON 0xff00
544#define SHN_MIPS_TEXT 0xff01
545#define SHN_MIPS_DATA 0xff02
546#define SHN_MIPS_SCOMMON 0xff03
547
548/*
549 * Relocation Entries
550 */
551typedef struct {
552 Elf32_Word r_offset; /* where to do it */
553 Elf32_Word r_info; /* index & type of relocation */
554} Elf32_Rel;
555
556typedef struct {
557 Elf32_Word r_offset; /* where to do it */
558 Elf32_Word r_info; /* index & type of relocation */
559 Elf32_Sword r_addend; /* adjustment value */
560} Elf32_Rela;
561
562/* r_info utility macros */
563#define ELF32_R_SYM(info) ((info) >> 8)
564#define ELF32_R_TYPE(info) ((info) & 0xff)
565#define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
566
567typedef struct {
568 Elf64_Addr r_offset; /* where to do it */
569 Elf64_Xword r_info; /* index & type of relocation */
570} Elf64_Rel;
571
572typedef struct {
573 Elf64_Addr r_offset; /* where to do it */
574 Elf64_Xword r_info; /* index & type of relocation */
575 Elf64_Sxword r_addend; /* adjustment value */
576} Elf64_Rela;
577
578/* r_info utility macros */
579#define ELF64_R_SYM(info) ((info) >> 32)
580#define ELF64_R_TYPE(info) ((info) & 0xffffffff)
581#define ELF64_R_INFO(sym,type) (((sym) << 32) + (type))
582
583/*
584 * Move entries
585 */
586typedef struct {
587 Elf32_Lword m_value; /* symbol value */
588 Elf32_Word m_info; /* size + index */
589 Elf32_Word m_poffset; /* symbol offset */
590 Elf32_Half m_repeat; /* repeat count */
591 Elf32_Half m_stride; /* stride info */
592} Elf32_Move;
593
594#define ELF32_M_SYM(info) ((info) >> 8)
595#define ELF32_M_SIZE(info) ((info) & 0xff)
596#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
597
598typedef struct {
599 Elf64_Lword m_value; /* symbol value */
600 Elf64_Xword m_info; /* size + index */
601 Elf64_Xword m_poffset; /* symbol offset */
602 Elf64_Word m_repeat; /* repeat count */
603 Elf64_Word m_stride; /* stride info */
604} Elf64_Move;
605
606#define ELF64_M_SYM(info) ((info) >> 8)
607#define ELF64_M_SIZE(info) ((info) & 0xff)
608#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))
609
610/*
611 * Hardware/software capabilities entry
612 */
613typedef struct {
614 Elf32_Word c_tag; /* entry tag value */
615 union {
616 Elf32_Addr c_ptr;
617 Elf32_Word c_val;
618 } c_un;
619} Elf32_Cap;
620
621typedef struct {
622 Elf64_Xword c_tag; /* entry tag value */
623 union {
624 Elf64_Addr c_ptr;
625 Elf64_Xword c_val;
626 } c_un;
627} Elf64_Cap;
628
629/*
630 * Dynamic Section structure array
631 */
632typedef struct {
633 Elf32_Word d_tag; /* entry tag value */
634 union {
635 Elf32_Addr d_ptr;
636 Elf32_Word d_val;
637 } d_un;
638} Elf32_Dyn;
639
640typedef struct {
641 Elf64_Xword d_tag; /* entry tag value */
642 union {
643 Elf64_Addr d_ptr;
644 Elf64_Xword d_val;
645 } d_un;
646} Elf64_Dyn;
647
648/* d_tag */
649#define DT_NULL 0 /* Marks end of dynamic array */
650#define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */
651#define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */
652#define DT_PLTGOT 3 /* Address of PLT and/or GOT */
653#define DT_HASH 4 /* Address of symbol hash table */
654#define DT_STRTAB 5 /* Address of string table */
655#define DT_SYMTAB 6 /* Address of symbol table */
656#define DT_RELA 7 /* Address of Rela relocation table */
657#define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */
658#define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */
659#define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */
660#define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */
661#define DT_INIT 12 /* Address of initialization function */
662#define DT_FINI 13 /* Address of termination function */
663#define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */
664#define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */
665#define DT_SYMBOLIC 16 /* Start symbol search within local object */
666#define DT_REL 17 /* Address of Rel relocation table */
667#define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */
668#define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */
669#define DT_PLTREL 20 /* Type of PLT relocation entries */
670#define DT_DEBUG 21 /* Used for debugging; unspecified */
671#define DT_TEXTREL 22 /* Relocations might modify non-writable seg */
672#define DT_JMPREL 23 /* Address of relocations associated with PLT */
673#define DT_BIND_NOW 24 /* Process all relocations at load-time */
674#define DT_INIT_ARRAY 25 /* Address of initialization function array */
675#define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */
676#define DT_INIT_ARRAYSZ 27 /* Address of termination function array */
677#define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/
Elliott Hughese4d792a2013-10-28 14:19:05 -0700678#define DT_RUNPATH 29 /* overrides DT_RPATH */
679#define DT_FLAGS 30 /* Encodes ORIGIN, SYMBOLIC, TEXTREL, BIND_NOW, STATIC_TLS */
680#define DT_ENCODING 31 /* ??? */
681#define DT_PREINIT_ARRAY 32 /* Address of pre-init function array */
682#define DT_PREINIT_ARRAYSZ 33 /* Size, in bytes, of DT_PREINIT_ARRAY array */
683#define DT_NUM 34
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800684
685#define DT_LOOS 0x60000000 /* Operating system specific range */
686#define DT_VERSYM 0x6ffffff0 /* Symbol versions */
687#define DT_FLAGS_1 0x6ffffffb /* ELF dynamic flags */
688#define DT_VERDEF 0x6ffffffc /* Versions defined by file */
689#define DT_VERDEFNUM 0x6ffffffd /* Number of versions defined by file */
690#define DT_VERNEED 0x6ffffffe /* Versions needed by file */
691#define DT_VERNEEDNUM 0x6fffffff /* Number of versions needed by file */
692#define DT_HIOS 0x6fffffff
693#define DT_LOPROC 0x70000000 /* Processor-specific range */
694#define DT_HIPROC 0x7fffffff
695
696/* Flag values for DT_FLAGS_1 (incomplete) */
697#define DF_1_BIND_NOW 0x00000001 /* Same as DF_BIND_NOW */
698#define DF_1_NODELETE 0x00000008 /* Set the RTLD_NODELETE for object */
699#define DF_1_INITFIRST 0x00000020 /* Object's init/fini take priority */
700#define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */
701
702/*
703 * Auxiliary Vectors
704 */
705typedef struct {
706 Elf32_Word a_type; /* 32-bit id */
707 Elf32_Word a_v; /* 32-bit id */
708} Aux32Info;
709
710typedef struct {
711 Elf64_Word a_type; /* 32-bit id */
712 Elf64_Xword a_v; /* 64-bit id */
713} Aux64Info;
714
Elliott Hughes6fe67c32013-01-29 17:49:12 -0800715/* BEGIN android-changed: these constants should come from <linux/auxvec.h>. */
716#if 0
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800717/* a_type */
718#define AT_NULL 0 /* Marks end of array */
719#define AT_IGNORE 1 /* No meaning, a_un is undefined */
720#define AT_EXECFD 2 /* Open file descriptor of object file */
721#define AT_PHDR 3 /* &phdr[0] */
722#define AT_PHENT 4 /* sizeof(phdr[0]) */
723#define AT_PHNUM 5 /* # phdr entries */
724#define AT_PAGESZ 6 /* PAGESIZE */
725#define AT_BASE 7 /* Interpreter base addr */
726#define AT_FLAGS 8 /* Processor flags */
727#define AT_ENTRY 9 /* Entry address of executable */
728#define AT_DCACHEBSIZE 10 /* Data cache block size */
729#define AT_ICACHEBSIZE 11 /* Instruction cache block size */
730#define AT_UCACHEBSIZE 12 /* Unified cache block size */
731#define AT_STACKBASE 13 /* Base address of the main thread */
732
733 /* Vendor specific */
734#define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */
735
736#define AT_EUID 2000 /* euid (solaris compatible numbers) */
737#define AT_RUID 2001 /* ruid (solaris compatible numbers) */
738#define AT_EGID 2002 /* egid (solaris compatible numbers) */
739#define AT_RGID 2003 /* rgid (solaris compatible numbers) */
740
741 /* Solaris kernel specific */
742#define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */
743#define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */
744#define AT_SUN_LDNAME 2006 /* dynamic linker's name */
745#define AT_SUN_LPGSIZE 2007 /* large pagesize */
746
747 /* Other information */
748#define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */
749#define AT_SUN_HWCAP 2009 /* process hardware capabilities */
750#define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */
751#define AT_SUN_CPU 2011 /* CPU name */
752 /* ibcs2 emulation band aid */
753#define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */
754#define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
755 /* Executable's fully resolved name */
756#define AT_SUN_EXECNAME 2014
Elliott Hughes6fe67c32013-01-29 17:49:12 -0800757#endif
758/* END android-changed */
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800759
760/*
761 * Note Headers
762 */
763typedef struct {
764 Elf32_Word n_namesz;
765 Elf32_Word n_descsz;
766 Elf32_Word n_type;
767} Elf32_Nhdr;
768
769typedef struct {
770 Elf64_Word n_namesz;
771 Elf64_Word n_descsz;
772 Elf64_Word n_type;
773} Elf64_Nhdr;
774
775#define ELF_NOTE_GNU_NAMESZ 4
776#define ELF_NOTE_GNU_NAME "GNU\0"
777
778/*
779 * GNU-specific note type: ABI tag
780 * name: GNU\0
781 * namesz: 4
782 * desc:
783 * word[0]: OS tag
784 * word[1]: major version
785 * word[2]: minor version
786 * word[3]: teeny version
787 * descsz: 16
788 */
789/* GNU-specific note name and description sizes */
790#define ELF_NOTE_TYPE_ABI_TAG 1
791#define ELF_NOTE_ABI_NAME ELF_NOTE_GNU_NAME
792#define ELF_NOTE_ABI_NAMESZ ELF_NOTE_GNU_NAMESZ
793#define ELF_NOTE_ABI_DESCSZ 16
794/* GNU-specific OS/version value stuff */
795#define ELF_NOTE_ABI_OS_LINUX 0
796#define ELF_NOTE_ABI_OS_HURD 1
797#define ELF_NOTE_ABI_OS_SOLARIS 2
798#define ELF_NOTE_ABI_OS_KFREEBSD 3
799#define ELF_NOTE_ABI_OS_KNETBSD 4
800
801/*
802 * GNU-specific note type: Hardware capabilities
803 * name: GNU\0
804 * namesz: 4
805 * desc:
806 * word[0]: Number of entries
807 * word[1]: Bitmask of enabled entries
808 * Followed by a byte id, and a NUL terminated string per entry
809 * descsz: variable
810 */
811#define ELF_NOTE_TYPE_GNU_HWCAP 2
812
813/*
814 * GNU-specific note type: Build ID generated by ld
815 * name: GNU\0
816 * desc:
Elliott Hughese4d792a2013-10-28 14:19:05 -0700817 * word[0..4] SHA1 [default]
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800818 * or
819 * word[0..3] md5 or uuid
820 * descsz: 16 or 20
821 */
822#define ELF_NOTE_TYPE_GNU_BUILD_ID 3
823
824/* SuSE-specific note type: ABI
825 * name: SuSE\0
826 * namesz: 5
827 * desc:
828 * half[0] = MMmm
829 *
830 * M = product major version
831 * m = product minor version
832 * descsz: 2
833 */
834#define ELF_NOTE_TYPE_SUSE_TAG 1
835/* SuSE-specific note name and description sizes */
836#define ELF_NOTE_SUSE_NAMESZ 5
837#define ELF_NOTE_SUSE_DESCSZ 2
838/* SuSE-specific note name */
839#define ELF_NOTE_SUSE_NAME "SuSE\0"
840
841/* SuSE-specific note type: version
842 * name: SuSE\0\0\0\0
843 * namesz: 8
Elliott Hughese4d792a2013-10-28 14:19:05 -0700844 * desc:
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800845 * word[0] = VVTTMMmm
846 *
847 * V = version of following data
848 * T = product type: [box, sles, nld, whatever]
849 * M = product major version
850 * m = product minor version
851 * descsz: 8
852 */
853#define ELF_NOTE_TYPE_SUSE_VERSION_TAG 0x45537553 /* SuSE in LE */
854/* SuSE-specific note name and description sizes */
855#define ELF_NOTE_SUSE_VERSION_NAMESZ 8
856#define ELF_NOTE_SUSE_VERSION_DESCSZ 8
857/* SuSE-specific note name */
858#define ELF_NOTE_SUSE_VERSION_NAME "SuSE\0\0\0\0"
859
860/* NetBSD-specific note type: Emulation name.
861 * name: NetBSD\0\0
862 * namesz: 8
Elliott Hughese4d792a2013-10-28 14:19:05 -0700863 * desc:
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800864 * word[0]: MMmmrrpp00
865 *
866 * M = major version
867 * m = minor version
868 * r = release ["",A-Z,Z[A-Z] but numeric]
869 * p = patchlevel
870 * descsz: 4
871 */
872#define ELF_NOTE_TYPE_NETBSD_TAG 1
873/* NetBSD-specific note name and description sizes */
874#define ELF_NOTE_NETBSD_NAMESZ 7
875#define ELF_NOTE_NETBSD_DESCSZ 4
876/* NetBSD-specific note name */
877#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0"
878
Elliott Hughese4d792a2013-10-28 14:19:05 -0700879/* NetBSD-specific note type: Checksum.
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800880 * There should be 1 NOTE per PT_LOAD section.
881 * name: ???
882 * namesz: ???
883 * desc:
884 * a tuple of <phnum>(16),<chk-type>(16),<chk-value>.
885 * descsz: ???
886 */
887#define ELF_NOTE_TYPE_CHECKSUM_TAG 2
888#define ELF_NOTE_CHECKSUM_CRC32 1
889#define ELF_NOTE_CHECKSUM_MD5 2
890#define ELF_NOTE_CHECKSUM_SHA1 3
891#define ELF_NOTE_CHECKSUM_SHA256 4
892
893/*
894 * NetBSD-specific note type: PaX.
895 * There should be 1 NOTE per executable.
896 * name: PaX\0
897 * namesz: 4
898 * desc:
899 * word[0]: capability bitmask
900 * descsz: 4
901 */
902#define ELF_NOTE_TYPE_PAX_TAG 3
903#define ELF_NOTE_PAX_MPROTECT 0x01 /* Force enable Mprotect */
904#define ELF_NOTE_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */
905#define ELF_NOTE_PAX_GUARD 0x04 /* Force enable Segvguard */
906#define ELF_NOTE_PAX_NOGUARD 0x08 /* Force disable Servguard */
907#define ELF_NOTE_PAX_ASLR 0x10 /* Force enable ASLR */
908#define ELF_NOTE_PAX_NOASLR 0x20 /* Force disable ASLR */
909#define ELF_NOTE_PAX_NAMESZ 4
910#define ELF_NOTE_PAX_NAME "PaX\0"
911#define ELF_NOTE_PAX_DESCSZ 4
912
913/*
914 * NetBSD-specific core file information.
915 *
916 * NetBSD ELF core files use notes to provide information about
917 * the process's state. The note name is "NetBSD-CORE" for
918 * information that is global to the process, and "NetBSD-CORE@nn",
919 * where "nn" is the lwpid of the LWP that the information belongs
920 * to (such as register state).
921 *
922 * We use the following note identifiers:
923 *
924 * ELF_NOTE_NETBSD_CORE_PROCINFO
925 * Note is a "netbsd_elfcore_procinfo" structure.
926 *
927 * We also use ptrace(2) request numbers (the ones that exist in
928 * machine-dependent space) to identify register info notes. The
929 * info in such notes is in the same format that ptrace(2) would
930 * export that information.
931 *
932 * Please try to keep the members of this structure nicely aligned,
933 * and if you add elements, add them to the end and bump the version.
934 */
935
936#define ELF_NOTE_NETBSD_CORE_NAME "NetBSD-CORE"
937
938#define ELF_NOTE_NETBSD_CORE_PROCINFO 1
939
940#define NETBSD_ELFCORE_PROCINFO_VERSION 1
941
942struct netbsd_elfcore_procinfo {
943 /* Version 1 fields start here. */
944 uint32_t cpi_version; /* our version */
945 uint32_t cpi_cpisize; /* sizeof(this struct) */
946 uint32_t cpi_signo; /* killing signal */
947 uint32_t cpi_sigcode; /* signal code */
948 uint32_t cpi_sigpend[4]; /* pending signals */
949 uint32_t cpi_sigmask[4]; /* blocked signals */
950 uint32_t cpi_sigignore[4]; /* ignored signals */
951 uint32_t cpi_sigcatch[4]; /* caught signals */
952 int32_t cpi_pid; /* process ID */
953 int32_t cpi_ppid; /* parent process ID */
954 int32_t cpi_pgrp; /* process group ID */
955 int32_t cpi_sid; /* session ID */
956 uint32_t cpi_ruid; /* real user ID */
957 uint32_t cpi_euid; /* effective user ID */
958 uint32_t cpi_svuid; /* saved user ID */
959 uint32_t cpi_rgid; /* real group ID */
960 uint32_t cpi_egid; /* effective group ID */
961 uint32_t cpi_svgid; /* saved group ID */
962 uint32_t cpi_nlwps; /* number of LWPs */
963 int8_t cpi_name[32]; /* copy of p->p_comm */
964 /* Add version 2 fields below here. */
965 int32_t cpi_siglwp; /* LWP target of killing signal */
966};
967
Elliott Hughese4d792a2013-10-28 14:19:05 -0700968/*
969 * NetBSD-specific note type: MACHINE_ARCH.
970 * There should be 1 NOTE per executable.
971 * name: NetBSD\0
972 * namesz: 7
973 * desc: string
974 * descsz: variable
975 */
976#define ELF_NOTE_TYPE_MARCH_TAG 5
977/* NetBSD-specific note name and description sizes */
978#define ELF_NOTE_MARCH_NAMESZ ELF_NOTE_NETBSD_NAMESZ
979/* NetBSD-specific note name */
980#define ELF_NOTE_MARCH_NAME ELF_NOTE_NETBSD_NAME
981
Elliott Hughesa6a3ac52013-01-29 15:02:50 -0800982#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
983#define ELFSIZE ARCH_ELFSIZE
984#endif
985
986#if defined(ELFSIZE)
987#define CONCAT(x,y) __CONCAT(x,y)
988#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
989#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
990#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE))
991#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
992#endif
993
994#if defined(ELFSIZE) && (ELFSIZE == 32)
995#define Elf_Ehdr Elf32_Ehdr
996#define Elf_Phdr Elf32_Phdr
997#define Elf_Shdr Elf32_Shdr
998#define Elf_Sym Elf32_Sym
999#define Elf_Rel Elf32_Rel
1000#define Elf_Rela Elf32_Rela
1001#define Elf_Dyn Elf32_Dyn
1002#define Elf_Word Elf32_Word
1003#define Elf_Sword Elf32_Sword
1004#define Elf_Half Elf32_Half
1005#define Elf_Addr Elf32_Addr
1006#define Elf_Off Elf32_Off
1007#define Elf_SOff Elf32_SOff
1008#define Elf_Nhdr Elf32_Nhdr
1009#define Elf_Verdef Elf32_Verdef
1010#define Elf_Verdaux Elf32_Verdaux
1011#define Elf_Verneed Elf32_Verneed
1012#define Elf_Vernaux Elf32_Vernaux
1013#define Elf_Versym Elf32_Versym
1014
1015#define ELF_R_SYM ELF32_R_SYM
1016#define ELF_R_TYPE ELF32_R_TYPE
1017#define ELFCLASS ELFCLASS32
1018
1019#define AuxInfo Aux32Info
1020#elif defined(ELFSIZE) && (ELFSIZE == 64)
1021#define Elf_Ehdr Elf64_Ehdr
1022#define Elf_Phdr Elf64_Phdr
1023#define Elf_Shdr Elf64_Shdr
1024#define Elf_Sym Elf64_Sym
1025#define Elf_Rel Elf64_Rel
1026#define Elf_Rela Elf64_Rela
1027#define Elf_Dyn Elf64_Dyn
1028#define Elf_Word Elf64_Word
1029#define Elf_Sword Elf64_Sword
1030#define Elf_Half Elf64_Half
1031#define Elf_Addr Elf64_Addr
1032#define Elf_Off Elf64_Off
1033#define Elf_SOff Elf64_SOff
1034#define Elf_Nhdr Elf64_Nhdr
1035#define Elf_Verdef Elf64_Verdef
1036#define Elf_Verdaux Elf64_Verdaux
1037#define Elf_Verneed Elf64_Verneed
1038#define Elf_Vernaux Elf64_Vernaux
1039#define Elf_Versym Elf64_Versym
1040
1041#define ELF_R_SYM ELF64_R_SYM
1042#define ELF_R_TYPE ELF64_R_TYPE
1043#define ELFCLASS ELFCLASS64
1044
1045#define AuxInfo Aux64Info
1046#endif
1047
1048#ifndef Elf_Symindx
1049#define Elf_Symindx uint32_t
1050#endif
1051
1052#define ELF32_ST_BIND(info) ELF_ST_BIND(info)
1053#define ELF32_ST_TYPE(info) ELF_ST_TYPE(info)
1054#define ELF32_ST_INFO(bind,type) ELF_ST_INFO(bind,type)
1055#define ELF32_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other)
1056
1057#define ELF64_ST_BIND(info) ELF_ST_BIND(info)
1058#define ELF64_ST_TYPE(info) ELF_ST_TYPE(info)
1059#define ELF64_ST_INFO(bind,type) ELF_ST_INFO(bind,type)
1060#define ELF64_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other)
1061
1062typedef struct {
1063 Elf32_Half si_boundto; /* direct bindings - symbol bound to */
1064 Elf32_Half si_flags; /* per symbol flags */
1065} Elf32_Syminfo;
1066
1067typedef struct {
1068 Elf64_Word si_boundto; /* direct bindings - symbol bound to */
1069 Elf64_Word si_flags; /* per symbol flags */
1070} Elf64_Syminfo;
1071
1072#define SYMINFO_FLG_DIRECT 0x0001 /* symbol ref has direct association
1073 to object containing definition */
1074#define SYMINFO_FLG_PASSTHRU 0x0002 /* ignored - see SYMINFO_FLG_FILTER */
1075#define SYMINFO_FLG_COPY 0x0004 /* symbol is a copy-reloc */
1076#define SYMINFO_FLG_LAZYLOAD 0x0008 /* object containing defn should be
1077 lazily-loaded */
1078#define SYMINFO_FLG_DIRECTBIND 0x0010 /* ref should be bound directly to
1079 object containing definition */
1080#define SYMINFO_FLG_NOEXTDIRECT 0x0020 /* don't let an external reference
1081 directly bind to this symbol */
1082#define SYMINFO_FLG_FILTER 0x0002 /* symbol ref is associated to a */
1083#define SYMINFO_FLG_AUXILIARY 0x0040 /* standard or auxiliary filter */
1084
1085#define SYMINFO_BT_SELF 0xffff /* symbol bound to self */
1086#define SYMINFO_BT_PARENT 0xfffe /* symbol bound to parent */
1087#define SYMINFO_BT_NONE 0xfffd /* no special symbol binding */
1088#define SYMINFO_BT_EXTERN 0xfffc /* symbol defined as external */
1089#define SYMINFO_BT_LOWRESERVE 0xff00 /* beginning of reserved entries */
1090
1091#define SYMINFO_NONE 0 /* Syminfo version */
1092#define SYMINFO_CURRENT 1
1093#define SYMINFO_NUM 2
1094
1095/*
Elliott Hughese4d792a2013-10-28 14:19:05 -07001096 * These constants are used for Elf32_Verdef struct's version number.
Elliott Hughesa6a3ac52013-01-29 15:02:50 -08001097 */
1098#define VER_DEF_NONE 0
1099#define VER_DEF_CURRENT 1
1100
1101/*
1102 * These constants are used for Elf32_Verdef struct's vd_ndx.
1103 */
1104#define VER_DEF_IDX(x) VER_NDX(x)
1105
1106/*
Elliott Hughese4d792a2013-10-28 14:19:05 -07001107 * These constants are used for Elf32_Verdef struct's vd_flags.
Elliott Hughesa6a3ac52013-01-29 15:02:50 -08001108 */
1109#define VER_FLG_BASE 0x1
1110#define VER_FLG_WEAK 0x2
1111
1112/*
1113 * These are used in an Elf32_Versym field.
1114 */
1115#define VER_NDX_LOCAL 0
1116#define VER_NDX_GLOBAL 1
1117#define VER_NDX_GIVEN 2
1118
1119/*
Elliott Hughese4d792a2013-10-28 14:19:05 -07001120 * These constants are used for Elf32_Verneed struct's version number.
Elliott Hughesa6a3ac52013-01-29 15:02:50 -08001121 */
1122#define VER_NEED_NONE 0
1123#define VER_NEED_CURRENT 1
1124
1125/*
1126 * These constants are used for Elf32_Vernaux struct's vna_other.
1127 */
1128#define VER_NEED_HIDDEN VER_NDX_HIDDEN
1129#define VER_NEED_IDX(x) VER_NDX(x)
1130
1131/* index */
1132#define VER_NDX_HIDDEN 0x8000
1133#define VER_NDX(x) ((x) & ~VER_NDX_HIDDEN)
1134
1135/*
1136 * GNU Extension hidding symbol
1137 */
1138#define VERSYM_HIDDEN 0x8000
1139#define VERSYM_VERSION 0x7fff
1140
1141#define ELF_VER_CHR '@'
1142
1143/*
1144 * These are current size independent.
1145 */
1146
1147typedef struct {
1148 Elf32_Half vd_version; /* version number of structure */
1149 Elf32_Half vd_flags; /* flags (VER_FLG_*) */
1150 Elf32_Half vd_ndx; /* version index */
1151 Elf32_Half vd_cnt; /* number of verdaux entries */
1152 Elf32_Word vd_hash; /* hash of name */
1153 Elf32_Word vd_aux; /* offset to verdaux entries */
1154 Elf32_Word vd_next; /* offset to next verdef */
1155} Elf32_Verdef;
1156typedef Elf32_Verdef Elf64_Verdef;
1157
1158typedef struct {
1159 Elf32_Word vda_name; /* string table offset of name */
1160 Elf32_Word vda_next; /* offset to verdaux */
1161} Elf32_Verdaux;
1162typedef Elf32_Verdaux Elf64_Verdaux;
1163
1164typedef struct {
1165 Elf32_Half vn_version; /* version number of structure */
1166 Elf32_Half vn_cnt; /* number of vernaux entries */
1167 Elf32_Word vn_file; /* string table offset of library name*/
1168 Elf32_Word vn_aux; /* offset to vernaux entries */
1169 Elf32_Word vn_next; /* offset to next verneed */
1170} Elf32_Verneed;
1171typedef Elf32_Verneed Elf64_Verneed;
1172
1173typedef struct {
1174 Elf32_Word vna_hash; /* Hash of dependency name */
1175 Elf32_Half vna_flags; /* flags (VER_FLG_*) */
1176 Elf32_Half vna_other; /* unused */
1177 Elf32_Word vna_name; /* string table offset to version name*/
1178 Elf32_Word vna_next; /* offset to next vernaux */
1179} Elf32_Vernaux;
1180typedef Elf32_Vernaux Elf64_Vernaux;
1181
1182typedef struct {
1183 Elf32_Half vs_vers;
1184} Elf32_Versym;
1185typedef Elf32_Versym Elf64_Versym;
1186
1187#ifdef _KERNEL
1188
1189#define ELF_AUX_ENTRIES 15 /* Max size of aux array passed to loader */
1190#define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
1191#define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */
1192#define ELF64_NO_ADDR (~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
1193#define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */
1194
1195#if defined(ELFSIZE) && (ELFSIZE == 64)
1196#define ELF_NO_ADDR ELF64_NO_ADDR
1197#define ELF_LINK_ADDR ELF64_LINK_ADDR
1198#elif defined(ELFSIZE) && (ELFSIZE == 32)
1199#define ELF_NO_ADDR ELF32_NO_ADDR
1200#define ELF_LINK_ADDR ELF32_LINK_ADDR
1201#endif
1202
1203#ifndef ELF32_EHDR_FLAGS_OK
1204#define ELF32_EHDR_FLAGS_OK(eh) 1
1205#endif
1206
1207#ifndef ELF64_EHDR_FLAGS_OK
1208#define ELF64_EHDR_FLAGS_OK(eh) 1
1209#endif
1210
1211#if defined(ELFSIZE) && (ELFSIZE == 64)
1212#define ELF_EHDR_FLAGS_OK(eh) ELF64_EHDR_FLAGS_OK(eh)
1213#else
1214#define ELF_EHDR_FLAGS_OK(eh) ELF32_EHDR_FLAGS_OK(eh)
1215#endif
1216
1217#if defined(ELFSIZE)
1218struct elf_args {
1219 Elf_Addr arg_entry; /* program entry point */
1220 Elf_Addr arg_interp; /* Interpreter load address */
1221 Elf_Addr arg_phaddr; /* program header address */
1222 Elf_Addr arg_phentsize; /* Size of program header */
1223 Elf_Addr arg_phnum; /* Number of program headers */
1224};
1225#endif
1226
1227#ifdef _KERNEL_OPT
1228#include "opt_execfmt.h"
1229#endif
1230
1231struct ps_strings;
1232
1233#ifdef EXEC_ELF32
1234int exec_elf32_makecmds(struct lwp *, struct exec_package *);
1235int elf32_copyargs(struct lwp *, struct exec_package *,
1236 struct ps_strings *, char **, void *);
1237
1238int coredump_elf32(struct lwp *, void *);
1239int coredump_writenote_elf32(struct proc *, void *, Elf32_Nhdr *,
1240 const char *, void *);
1241
1242int elf32_check_header(Elf32_Ehdr *, int);
1243#endif
1244
1245#ifdef EXEC_ELF64
1246int exec_elf64_makecmds(struct lwp *, struct exec_package *);
1247int elf64_copyargs(struct lwp *, struct exec_package *,
1248 struct ps_strings *, char **, void *);
1249
1250int coredump_elf64(struct lwp *, void *);
1251int coredump_writenote_elf64(struct proc *, void *, Elf64_Nhdr *,
1252 const char *, void *);
1253
1254int elf64_check_header(Elf64_Ehdr *, int);
1255#endif
1256
1257#endif /* _KERNEL */
1258
1259#endif /* !_SYS_EXEC_ELF_H_ */