file_cmds-60.tar.gz
[apple/file_cmds.git] / file / readelf.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /* $OpenBSD: readelf.h,v 1.1 1997/02/09 23:58:34 millert Exp $ */
25
26 /*
27 * readelf.h
28 *
29 * Provide elf data structures for non-elf machines, allowing file
30 * non-elf hosts to determine if an elf binary is stripped.
31 * Note: cobbled from the linux header file, with modifications
32 */
33 #ifndef __fake_elf_h__
34 #define __fake_elf_h__
35
36 typedef unsigned int Elf32_Addr;
37 typedef unsigned short Elf32_Half;
38 typedef unsigned int Elf32_Off;
39 typedef unsigned int Elf32_Word;
40 typedef unsigned char Elf32_Char;
41
42 /* XXX: We need 64 bit numbers here */
43 typedef unsigned int Elf64_Addr[2];
44 typedef unsigned short Elf64_Half;
45 typedef unsigned int Elf64_Off[2];
46 typedef unsigned int Elf64_Word;
47 typedef unsigned char Elf64_Char;
48
49 #define EI_NIDENT 16
50
51 typedef struct {
52 Elf32_Char e_ident[EI_NIDENT];
53 Elf32_Half e_type;
54 Elf32_Half e_machine;
55 Elf32_Word e_version;
56 Elf32_Addr e_entry; /* Entry point */
57 Elf32_Off e_phoff;
58 Elf32_Off e_shoff;
59 Elf32_Word e_flags;
60 Elf32_Half e_ehsize;
61 Elf32_Half e_phentsize;
62 Elf32_Half e_phnum;
63 Elf32_Half e_shentsize;
64 Elf32_Half e_shnum;
65 Elf32_Half e_shstrndx;
66 } Elf32_Ehdr;
67
68 typedef struct {
69 Elf64_Char e_ident[EI_NIDENT];
70 Elf64_Half e_type;
71 Elf64_Half e_machine;
72 Elf64_Word e_version;
73 Elf64_Addr e_entry; /* Entry point */
74 Elf64_Off e_phoff;
75 Elf64_Off e_shoff;
76 Elf64_Word e_flags;
77 Elf64_Half e_ehsize;
78 Elf64_Half e_phentsize;
79 Elf64_Half e_phnum;
80 Elf64_Half e_shentsize;
81 Elf64_Half e_shnum;
82 Elf64_Half e_shstrndx;
83 } Elf64_Ehdr;
84
85 /* e_type */
86 #define ET_EXEC 2
87 #define ET_CORE 4
88
89 /* sh_type */
90 #define SHT_SYMTAB 2
91 #define SHT_NOTE 7
92
93 /* elf type */
94 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
95 #define ELFDATA2LSB 1
96 #define ELFDATA2MSB 2
97
98 /* elf class */
99 #define ELFCLASSNONE 0
100 #define ELFCLASS32 1
101 #define ELFCLASS64 2
102
103 /* magic number */
104 #define EI_MAG0 0 /* e_ident[] indexes */
105 #define EI_MAG1 1
106 #define EI_MAG2 2
107 #define EI_MAG3 3
108 #define EI_CLASS 4
109 #define EI_DATA 5
110 #define EI_VERSION 6
111 #define EI_PAD 7
112
113 #define ELFMAG0 0x7f /* EI_MAG */
114 #define ELFMAG1 'E'
115 #define ELFMAG2 'L'
116 #define ELFMAG3 'F'
117 #define ELFMAG "\177ELF"
118
119 typedef struct {
120 Elf32_Word p_type;
121 Elf32_Off p_offset;
122 Elf32_Addr p_vaddr;
123 Elf32_Addr p_paddr;
124 Elf32_Word p_filesz;
125 Elf32_Word p_memsz;
126 Elf32_Word p_flags;
127 Elf32_Word p_align;
128 } Elf32_Phdr;
129
130 #define PT_NULL 0 /* p_type */
131 #define PT_LOAD 1
132 #define PT_DYNAMIC 2
133 #define PT_INTERP 3
134 #define PT_NOTE 4
135 #define PT_SHLIB 5
136 #define PT_PHDR 6
137 #define PT_NUM 7
138
139 typedef struct {
140 Elf32_Word sh_name;
141 Elf32_Word sh_type;
142 Elf32_Word sh_flags;
143 Elf32_Addr sh_addr;
144 Elf32_Off sh_offset;
145 Elf32_Word sh_size;
146 Elf32_Word sh_link;
147 Elf32_Word sh_info;
148 Elf32_Word sh_addralign;
149 Elf32_Word sh_entsize;
150 } Elf32_Shdr;
151
152 typedef struct {
153 Elf64_Word sh_name;
154 Elf64_Word sh_type;
155 Elf64_Off sh_flags;
156 Elf64_Addr sh_addr;
157 Elf64_Off sh_offset;
158 Elf64_Off sh_size;
159 Elf64_Word sh_link;
160 Elf64_Word sh_info;
161 Elf64_Off sh_addralign;
162 Elf64_Off sh_entsize;
163 } Elf64_Shdr;
164
165 /* Notes used in ET_CORE */
166 #define NT_PRSTATUS 1
167 #define NT_PRFPREG 2
168 #define NT_PRPSINFO 3
169 #define NT_TASKSTRUCT 4
170
171 /* Note header in a PT_NOTE section */
172 typedef struct elf_note {
173 Elf32_Word n_namesz; /* Name size */
174 Elf32_Word n_descsz; /* Content size */
175 Elf32_Word n_type; /* Content type */
176 } Elf32_Nhdr;
177
178 typedef struct {
179 Elf64_Word n_namesz;
180 Elf64_Word n_descsz;
181 Elf64_Word n_type;
182 } Elf64_Nhdr;
183
184 #define NT_PRSTATUS 1
185 #define NT_PRFPREG 2
186 #define NT_PRPSINFO 3
187 #define NT_PRXREG 4
188 #define NT_PLATFORM 5
189 #define NT_AUXV 6
190
191 #endif