imcplugin: Set NACL_FD environment variable
[nativeclient.git] / include / elf.h
blobe3d7a99f5183757181232e220d65af5eb4b8736c
1 /*
2 * Copyright 2008, Google Inc.
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 are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* @file
35 * Minimal ELF header declaration / constants. Only Elf32* values are
36 * handled, and constants are defined only for fields that are actualy
37 * used. (Unused constants for used fields are include only for
38 * "completeness", though of course in many cases there are more
39 * values in use, e.g., the EM_* values for e_machine.)
41 * (Re)Created from the ELF specification at
42 * http://x86.ddj.com/ftp/manuals/tools/elf.pdf which is referenced
43 * from wikipedia article
44 * http://en.wikipedia.org/wki/Executable_and_Linkable_Format
47 #ifndef NATIVE_CLIENT_INCLUDE_ELF_H_
48 #define NATIVE_CLIENT_INCLUDE_ELF_H_
50 #include "native_client/include/nacl_base.h"
52 EXTERN_C_BEGIN
55 * Note that we must compile on windows, where stdint.h may be unavailable.
58 /* assumes 32-bit int, 16-bit short, 8-bit char */
60 typedef unsigned int Elf32_Addr; /* alignment 4 */
61 typedef unsigned short Elf32_Half; /* alignment 2 */
62 typedef unsigned int Elf32_Off; /* alignment 4 */
63 typedef int Elf32_Sword; /* alignment 4 */
64 typedef unsigned int Elf32_Word; /* alignment 4 */
65 /* unsigned char, size 1, alignment 1 */
67 #define EI_NIDENT 16 /* fwd, see rest of EI_* below */
69 typedef struct {
70 unsigned char e_ident[EI_NIDENT];
71 Elf32_Half e_type;
72 Elf32_Half e_machine;
73 Elf32_Word e_version;
74 Elf32_Addr e_entry;
75 Elf32_Off e_phoff;
76 Elf32_Off e_shoff;
77 Elf32_Word e_flags;
78 Elf32_Half e_ehsize;
79 Elf32_Half e_phentsize;
80 Elf32_Half e_phnum;
81 Elf32_Half e_shentsize;
82 Elf32_Half e_shnum;
83 Elf32_Half e_shstrndx;
84 } Elf32_Ehdr;
86 #define ET_NONE 0 /* no file type */
87 #define ET_REL 1 /* relocatable file */
88 #define ET_EXEC 2 /* executable file */
89 #define ET_DYN 3 /* shared object file */
90 #define ET_CORE 4 /* core file */
91 #define ET_LOPROC 0xff00 /* processor-specific */
92 #define ET_HIPROC 0xffff /* processor-specific */
94 #define EM_NONE 0 /* no machine */
95 #define EM_M32 1 /* at&t we 32100 */
96 #define EM_SPARC 2 /* sparc */
97 #define EM_386 3 /* intel architecture */
98 #define EM_68K 4 /* motorola 68000 */
99 #define EM_88K 5 /* motorola 88000 */
100 #define EM_860 7 /* intel 80860 */
101 #define EM_MIPS 9 /* mips rs3000 big-endian */
102 #define EM_MIPS_RS4_BE 10 /* mips rs4000 big-endian */
103 #define EM_LORESERVED 11
104 #define EM_HIRESERVED 16
106 #define EV_NONE 0 /* invalid version */
107 #define EV_CURRENT 1 /* current version */
109 #define EI_MAG0 0 /* file identification */
110 #define EI_MAG1 1 /* file identification */
111 #define EI_MAG2 2 /* file identification */
112 #define EI_MAG3 3 /* file identification */
113 #define EI_CLASS 4 /* file class */
114 #define EI_DATA 5 /* data encoding */
115 #define EI_VERSION 6 /* file version */
117 * EI_PAD deviates from the pdf specification, where its value is 7, since
118 * EI_OSABI and EI_ABIVERSION have been introduced. EI_OSABI and
119 * EI_OSABIVERSION are from linux elf.h for code usage compatibility.
121 #define EI_PAD 9 /* start of padding bytes */
123 #define EI_OSABI 7
124 #define EI_ABIVERSION 8
127 * ELFMAG and SELFMAG are names/values from linux elf.h, for code usage
128 * compatibility.
130 #define ELFMAG "\177ELF"
131 #define SELFMAG 4
133 /* EI_CLASS values */
134 #define ELFCLASSNONE 0
135 #define ELFCLASS32 1
136 #define ELFCLASS64 2
138 /* EI_DATA values */
139 #define ELFDATANONE 0
140 #define ELFDATA2LSB 1
141 #define ELFDATA2MSB 2
143 typedef struct {
144 Elf32_Word p_type;
145 Elf32_Off p_offset;
146 Elf32_Addr p_vaddr;
147 Elf32_Addr p_paddr;
148 Elf32_Word p_filesz;
149 Elf32_Word p_memsz;
150 Elf32_Word p_flags;
151 Elf32_Word p_align;
152 } Elf32_Phdr;
154 #define PT_NULL 0
155 #define PT_LOAD 1
156 #define PT_DYNAMIC 2
157 #define PT_INTERP 3
158 #define PT_NOTE 4
159 #define PT_SHLIB 5
160 #define PT_PHDR 6
161 #define PT_LOPROC 0x70000000
162 #define PT_HIPROC 0x7fffffff
164 * PT_TLS and PT_GNU_STACK are from linux elf.h, for code usage
165 * compatibility.
167 #define PT_TLS 7
168 #define PT_GNU_STACK 0x6474e551
170 #define PF_X 1
171 #define PF_W 2
172 #define PF_R 4
174 * PF_MASKOS is from linux elf.h, for code usage compatibility
176 #define PF_MASKOS 0x0ff00000 /* os specific */
179 * ncfileutil wants section headers, even though service runtime does
180 * not.
183 typedef struct {
184 Elf32_Word sh_name;
185 Elf32_Word sh_type;
186 Elf32_Word sh_flags;
187 Elf32_Addr sh_addr;
188 Elf32_Off sh_offset;
189 Elf32_Word sh_size;
190 Elf32_Word sh_link;
191 Elf32_Word sh_info;
192 Elf32_Word sh_addralign;
193 Elf32_Word sh_entsize;
194 } Elf32_Shdr;
196 #define SHF_WRITE 0x1
197 #define SHF_ALLOC 0x2
198 #define SHF_EXECINSTR 0x4
199 #define SHF_MASKPROC 0xf0000000
201 EXTERN_C_END
203 #endif /* NATIVE_CLIENT_INCLUDE_ELF_H_ */