imgact_elf.h revision 22975
1/*-
2 * Copyright (c) 1995-1996 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer
10 *    in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software withough specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 *	$Id$
29 */
30
31#ifndef _IMGACT_ELF_H_
32#define _IMGACT_ELF_H_
33
34typedef u_int32_t Elf32_Addr;
35typedef u_int32_t Elf32_Off;
36typedef int32_t   Elf32_Sword;
37typedef u_int32_t Elf32_Word;
38typedef u_int16_t Elf32_Half;
39
40extern int elf_trace;
41
42#define EI_NINDENT	16
43typedef struct {
44        unsigned char   e_ident[EI_NINDENT];    /* file id */
45        Elf32_Half      e_type;                 /* type */
46        Elf32_Half      e_machine;              /* machine type */
47        Elf32_Word      e_version;              /* version number */
48        Elf32_Addr      e_entry;                /* entry point */
49        Elf32_Off       e_phoff;                /* program hdr offset */
50        Elf32_Off       e_shoff;                /* section hdr offset */
51        Elf32_Word      e_flags;                /* flags */
52        Elf32_Half      e_ehsize;               /* sizeof ehdr */
53        Elf32_Half      e_phentsize;            /* program header entry size */
54        Elf32_Half      e_phnum;                /* number of program headers */
55        Elf32_Half      e_shentsize;            /* section header entry size */
56        Elf32_Half      e_shnum;                /* number of section headers */
57        Elf32_Half      e_shstrndx;             /* string table index */
58} Elf32_Ehdr;
59
60/*
61 * Values for e_indent entry in struct Elf32_Ehdr.
62 */
63#define EI_MAG0		0
64#define EI_MAG1		1
65#define EI_MAG2		2
66#define EI_MAG3		3
67#define EI_CLASS	4
68#define EI_DATA		5
69#define EI_VERSION	6
70#define EI_SPARE	8
71#define EI_BRAND	8
72
73
74#define ELFMAG0		'\177'
75#define ELFMAG1		'E'
76#define ELFMAG2		'L'
77#define ELFMAG3		'F'
78#define ELFCLASSNONE	0	/* invalid class */
79#define ELFCLASS32	1	/* 32bit object class */
80#define ELFCLASS64	2	/* 64bit object class */
81#define ELFDATANONE	0	/* invalid data encoding */
82#define ELFDATA2LSB	1	/* little endian */
83#define ELFDATA2MSB	2	/* big endian */
84
85/*
86 * Values for e_version entry in struct Elf32_Ehdr.
87 */
88#define EV_NONE		0	/* invalid version */
89#define EV_CURRENT	1	/* current version */
90
91/*
92 * Values for e_type entry in struct Elf32_Ehdr.
93 */
94#define ET_NONE   	0
95#define ET_REL    	1
96#define ET_EXEC   	2
97#define ET_DYN    	3
98#define ET_CORE   	4
99#define ET_LOPROC 	5
100#define ET_HIPROC 	6
101
102/*
103 * Values for e_machine entry in struct Elf32_Ehdr.
104 */
105#define EM_NONE  	0
106#define EM_M32   	1
107#define EM_SPARC 	2
108#define EM_386   	3
109#define EM_68K   	4
110#define EM_88K   	5
111#define EM_486   	6
112#define EM_860   	7
113
114
115typedef struct {
116        Elf32_Word      p_type;         /* entry type */
117        Elf32_Off       p_offset;       /* offset */
118        Elf32_Addr      p_vaddr;        /* virtual address */
119        Elf32_Addr      p_paddr;        /* physical address */
120        Elf32_Word      p_filesz;       /* file size */
121        Elf32_Word      p_memsz;        /* memory size */
122        Elf32_Word      p_flags;        /* flags */
123        Elf32_Word      p_align;        /* memory & file alignment */
124} Elf32_Phdr;
125
126/*
127 * Values for p_type entry in struct Elf32_Phdr.
128 */
129#define PT_NULL    	0
130#define PT_LOAD    	1
131#define PT_DYNAMIC 	2
132#define PT_INTERP  	3
133#define PT_NOTE    	4
134#define PT_SHLIB   	5
135#define PT_PHDR    	6
136#define PT_LOPROC  	0x70000000
137#define PT_HIPROC  	0x7fffffff
138
139/*
140 * Values for p_flags entry in struct Elf32_Phdr.
141 */
142#define PF_X		0x1
143#define PF_W		0x2
144#define PF_R		0x4
145#define PF_MASKPROC	0xf0000000
146
147/*
148 * Auxiliary vector entry on initial stack.
149 */
150typedef struct {
151	Elf32_Sword	a_type;
152	Elf32_Word	a_val;
153} Elf32_Auxinfo;
154
155#define AUXARGS_ENTRY(pos, id, val) {suword(pos++, id); suword(pos++, val);}
156
157/*
158 * Values for a_type in struct Elf32_Auxinfo.
159 */
160#define AT_NULL		0	/* Terminates the vector */
161#define AT_IGNORE	1	/* Ignored */
162#define AT_EXECFD	2	/* File descriptor of program to load */
163#define AT_PHDR		3	/* Program header of program already loaded */
164#define AT_PHENT	4	/* Size of each program header entry */
165#define AT_PHNUM	5	/* Number of program header entries */
166#define AT_PAGESZ	6	/* Page size in bytes */
167#define AT_BASE		7	/* Interpreter's base address */
168#define AT_FLAGS	8	/* Flags (unused for i386) */
169#define AT_ENTRY	9	/* Where interpreter should transfer control */
170
171/*
172 * The following non-standard values are used for passing information
173 * to the (FreeBSD ELF) dynamic linker. Will probably go away soon....
174 */
175#define AT_BRK		10	/* Starting point for sbrk and brk */
176#define AT_DEBUG	11	/* Debugging level */
177#define AT_COUNT	15
178
179/*
180 * The following non-standard values are used in Linux ELF binaries.
181 */
182#define AT_NOTELF	10	/* Program is not ELF ?? */
183#define AT_UID		11	/* Real uid */
184#define AT_EUID		12	/* Effective uid */
185#define AT_GID		13	/* Real gid */
186#define AT_EGID		14	/* Effective gid */
187
188/*
189 * Structure used to pass infomation from the loader to the
190 * stack fixup routine.
191 */
192typedef struct {
193	Elf32_Sword	execfd;
194	Elf32_Word	phdr;
195	Elf32_Word	phent;
196	Elf32_Word	phnum;
197	Elf32_Word	pagesz;
198	Elf32_Word	base;
199	Elf32_Word	flags;
200	Elf32_Word	entry;
201	Elf32_Word	trace;
202} Elf32_Auxargs;
203
204typedef struct {
205	char *brand;
206	char *emul_path;
207	char *interp_path;
208        struct sysentvec *sysvec;
209} Elf32_Brandinfo;
210
211#define MAX_BRANDS      8
212
213int elf_insert_brand_entry __P((Elf32_Brandinfo *entry));
214int elf_remove_brand_entry __P((Elf32_Brandinfo *entry));
215
216#endif /* _IMGACT_ELF_H_ */
217