raddr2line utility
[reactos.git] / reactos / tools / rsym.h
1 /* rsym.h */
2
3 #ifndef RSYM_H
4 #define RSYM_H
5
6 #define IMAGE_DOS_MAGIC 0x5a4d
7 #define IMAGE_PE_MAGIC 0x00004550
8
9 #define IMAGE_SIZEOF_SHORT_NAME 8
10
11 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
12
13 typedef unsigned char BYTE;
14 typedef unsigned short WORD;
15 typedef unsigned long DWORD;
16 typedef signed long LONG;
17 typedef unsigned long ULONG;
18 #if defined(_WIN64)
19 typedef unsigned __int64 ULONG_PTR;
20 #else
21 typedef unsigned long ULONG_PTR;
22 #endif
23
24 #pragma pack(push,2)
25 typedef struct _IMAGE_DOS_HEADER {
26 WORD e_magic;
27 WORD e_cblp;
28 WORD e_cp;
29 WORD e_crlc;
30 WORD e_cparhdr;
31 WORD e_minalloc;
32 WORD e_maxalloc;
33 WORD e_ss;
34 WORD e_sp;
35 WORD e_csum;
36 WORD e_ip;
37 WORD e_cs;
38 WORD e_lfarlc;
39 WORD e_ovno;
40 WORD e_res[4];
41 WORD e_oemid;
42 WORD e_oeminfo;
43 WORD e_res2[10];
44 LONG e_lfanew;
45 } IMAGE_DOS_HEADER,*PIMAGE_DOS_HEADER;
46 #pragma pack(pop)
47
48 #define IMAGE_FILE_LINE_NUMS_STRIPPED 4
49 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 8
50 #define IMAGE_FILE_DEBUG_STRIPPED 512
51
52 #pragma pack(push,4)
53 typedef struct _IMAGE_FILE_HEADER {
54 WORD Machine;
55 WORD NumberOfSections;
56 DWORD TimeDateStamp;
57 DWORD PointerToSymbolTable;
58 DWORD NumberOfSymbols;
59 WORD SizeOfOptionalHeader;
60 WORD Characteristics;
61 } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
62
63 typedef struct _IMAGE_DATA_DIRECTORY {
64 DWORD VirtualAddress;
65 DWORD Size;
66 } IMAGE_DATA_DIRECTORY,*PIMAGE_DATA_DIRECTORY;
67
68 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5
69
70 typedef struct _IMAGE_OPTIONAL_HEADER {
71 WORD Magic;
72 BYTE MajorLinkerVersion;
73 BYTE MinorLinkerVersion;
74 DWORD SizeOfCode;
75 DWORD SizeOfInitializedData;
76 DWORD SizeOfUninitializedData;
77 DWORD AddressOfEntryPoint;
78 DWORD BaseOfCode;
79 DWORD BaseOfData;
80 DWORD ImageBase;
81 DWORD SectionAlignment;
82 DWORD FileAlignment;
83 WORD MajorOperatingSystemVersion;
84 WORD MinorOperatingSystemVersion;
85 WORD MajorImageVersion;
86 WORD MinorImageVersion;
87 WORD MajorSubsystemVersion;
88 WORD MinorSubsystemVersion;
89 DWORD Reserved1;
90 DWORD SizeOfImage;
91 DWORD SizeOfHeaders;
92 DWORD CheckSum;
93 WORD Subsystem;
94 WORD DllCharacteristics;
95 DWORD SizeOfStackReserve;
96 DWORD SizeOfStackCommit;
97 DWORD SizeOfHeapReserve;
98 DWORD SizeOfHeapCommit;
99 DWORD LoaderFlags;
100 DWORD NumberOfRvaAndSizes;
101 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
102 } IMAGE_OPTIONAL_HEADER,*PIMAGE_OPTIONAL_HEADER;
103
104 #define IMAGE_SCN_TYPE_NOLOAD 0x00000002
105 #define IMAGE_SCN_LNK_REMOVE 0x00000800
106 #define IMAGE_SCN_MEM_READ 0x40000000
107 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
108
109 typedef struct _IMAGE_SECTION_HEADER {
110 BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
111 union {
112 DWORD PhysicalAddress;
113 DWORD VirtualSize;
114 } Misc;
115 DWORD VirtualAddress;
116 DWORD SizeOfRawData;
117 DWORD PointerToRawData;
118 DWORD PointerToRelocations;
119 DWORD PointerToLinenumbers;
120 WORD NumberOfRelocations;
121 WORD NumberOfLinenumbers;
122 DWORD Characteristics;
123 } IMAGE_SECTION_HEADER,*PIMAGE_SECTION_HEADER;
124
125 typedef struct _IMAGE_BASE_RELOCATION {
126 DWORD VirtualAddress;
127 DWORD SizeOfBlock;
128 } IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
129
130
131 typedef struct {
132 unsigned short f_magic; /* magic number */
133 unsigned short f_nscns; /* number of sections */
134 unsigned long f_timdat; /* time & date stamp */
135 unsigned long f_symptr; /* file pointer to symtab */
136 unsigned long f_nsyms; /* number of symtab entries */
137 unsigned short f_opthdr; /* sizeof(optional hdr) */
138 unsigned short f_flags; /* flags */
139 } FILHDR;
140
141 typedef struct {
142 char s_name[8]; /* section name */
143 unsigned long s_paddr; /* physical address, aliased s_nlib */
144 unsigned long s_vaddr; /* virtual address */
145 unsigned long s_size; /* section size */
146 unsigned long s_scnptr; /* file ptr to raw data for section */
147 unsigned long s_relptr; /* file ptr to relocation */
148 unsigned long s_lnnoptr; /* file ptr to line numbers */
149 unsigned short s_nreloc; /* number of relocation entries */
150 unsigned short s_nlnno; /* number of line number entries */
151 unsigned long s_flags; /* flags */
152 } SCNHDR;
153 #pragma pack(pop)
154
155 typedef struct _SYMBOLFILE_HEADER {
156 unsigned long SymbolsOffset;
157 unsigned long SymbolsLength;
158 unsigned long StringsOffset;
159 unsigned long StringsLength;
160 } SYMBOLFILE_HEADER, *PSYMBOLFILE_HEADER;
161
162 typedef struct _STAB_ENTRY {
163 unsigned long n_strx; /* index into string table of name */
164 unsigned char n_type; /* type of symbol */
165 unsigned char n_other; /* misc info (usually empty) */
166 unsigned short n_desc; /* description field */
167 unsigned long n_value; /* value of symbol */
168 } STAB_ENTRY, *PSTAB_ENTRY;
169
170 #define N_FUN 0x24
171 #define N_SLINE 0x44
172 #define N_SO 0x64
173
174 /* COFF symbol table */
175
176 #define E_SYMNMLEN 8 /* # characters in a symbol name */
177 #define E_FILNMLEN 14 /* # characters in a file name */
178 #define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
179
180 #define N_BTMASK (0xf)
181 #define N_TMASK (0x30)
182 #define N_BTSHFT (4)
183 #define N_TSHIFT (2)
184
185 /* derived types, in e_type */
186 #define DT_NON (0) /* no derived type */
187 #define DT_PTR (1) /* pointer */
188 #define DT_FCN (2) /* function */
189 #define DT_ARY (3) /* array */
190
191 #define BTYPE(x) ((x) & N_BTMASK)
192
193 #define ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
194 #define ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
195 #define ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
196 #define ISTAG(x) ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
197 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
198
199 #define C_EFCN 0xff /* physical end of function */
200 #define C_NULL 0
201 #define C_AUTO 1 /* automatic variable */
202 #define C_EXT 2 /* external symbol */
203 #define C_STAT 3 /* static */
204 #define C_REG 4 /* register variable */
205 #define C_EXTDEF 5 /* external definition */
206 #define C_LABEL 6 /* label */
207 #define C_ULABEL 7 /* undefined label */
208 #define C_MOS 8 /* member of structure */
209 #define C_ARG 9 /* function argument */
210 #define C_STRTAG 10 /* structure tag */
211 #define C_MOU 11 /* member of union */
212 #define C_UNTAG 12 /* union tag */
213 #define C_TPDEF 13 /* type definition */
214 #define C_USTATIC 14 /* undefined static */
215 #define C_ENTAG 15 /* enumeration tag */
216 #define C_MOE 16 /* member of enumeration */
217 #define C_REGPARM 17 /* register parameter */
218 #define C_FIELD 18 /* bit field */
219 #define C_AUTOARG 19 /* auto argument */
220 #define C_LASTENT 20 /* dummy entry (end of block) */
221 #define C_BLOCK 100 /* ".bb" or ".eb" */
222 #define C_FCN 101 /* ".bf" or ".ef" */
223 #define C_EOS 102 /* end of structure */
224 #define C_FILE 103 /* file name */
225 #define C_LINE 104 /* line # reformatted as symbol table entry */
226 #define C_ALIAS 105 /* duplicate tag */
227 #define C_HIDDEN 106 /* ext symbol in dmert public lib */
228
229 #pragma pack(push,1)
230 typedef struct _COFF_SYMENT
231 {
232 union
233 {
234 char e_name[E_SYMNMLEN];
235 struct
236 {
237 unsigned long e_zeroes;
238 unsigned long e_offset;
239 }
240 e;
241 }
242 e;
243 unsigned long e_value;
244 short e_scnum;
245 unsigned short e_type;
246 unsigned char e_sclass;
247 unsigned char e_numaux;
248 } COFF_SYMENT, *PCOFF_SYMENT;
249 #pragma pack(pop)
250
251 typedef struct _ROSSYM_ENTRY {
252 ULONG_PTR Address;
253 ULONG FunctionOffset;
254 ULONG FileOffset;
255 ULONG SourceLine;
256 } ROSSYM_ENTRY, *PROSSYM_ENTRY;
257
258 #define ROUND_UP(N, S) (((N) + (S) - 1) & ~((S) - 1))
259
260 extern char*
261 convert_path(const char* origpath);
262
263 extern void*
264 load_file ( const char* file_name, size_t* file_size );
265
266 #endif/*RSYM_H*/