xref: /reactos/sdk/tools/rsym/rsym.h (revision 8a978a17)
1 /* rsym.h */
2 
3 #pragma once
4 #include <typedefs.h>
5 #include <pecoff.h>
6 
7 typedef struct {
8   USHORT f_magic;         /* magic number             */
9   USHORT f_nscns;         /* number of sections       */
10   ULONG  f_timdat;        /* time & date stamp        */
11   ULONG  f_symptr;        /* file pointer to symtab   */
12   ULONG  f_nsyms;         /* number of symtab entries */
13   USHORT f_opthdr;        /* sizeof(optional hdr)     */
14   USHORT f_flags;         /* flags                    */
15 } FILHDR;
16 
17 typedef struct {
18   char           s_name[8];  /* section name                     */
19   ULONG  s_paddr;    /* physical address, aliased s_nlib */
20   ULONG  s_vaddr;    /* virtual address                  */
21   ULONG  s_size;     /* section size                     */
22   ULONG  s_scnptr;   /* file ptr to raw data for section */
23   ULONG  s_relptr;   /* file ptr to relocation           */
24   ULONG  s_lnnoptr;  /* file ptr to line numbers         */
25   USHORT s_nreloc;   /* number of relocation entries     */
26   USHORT s_nlnno;    /* number of line number entries    */
27   ULONG  s_flags;    /* flags                            */
28 } SCNHDR;
29 #pragma pack(4)
30 
31 typedef struct _SYMBOLFILE_HEADER {
32   ULONG SymbolsOffset;
33   ULONG SymbolsLength;
34   ULONG StringsOffset;
35   ULONG StringsLength;
36 } SYMBOLFILE_HEADER, *PSYMBOLFILE_HEADER;
37 
38 typedef struct _STAB_ENTRY {
39   ULONG n_strx;         /* index into string table of name */
40   UCHAR n_type;         /* type of symbol */
41   UCHAR n_other;        /* misc info (usually empty) */
42   USHORT n_desc;        /* description field */
43   ULONG n_value;        /* value of symbol */
44 } STAB_ENTRY, *PSTAB_ENTRY;
45 
46 /* http://www.math.utah.edu/docs/info/stabs_12.html */
47 #define N_GYSM   0x20
48 #define N_FNAME  0x22
49 #define N_FUN    0x24
50 #define N_STSYM  0x26
51 #define N_LCSYM  0x28
52 #define N_MAIN   0x2A
53 #define N_PC     0x30
54 #define N_NSYMS  0x32
55 #define N_NOMAP  0x34
56 #define N_RSYM   0x40
57 #define N_M2C    0x42
58 #define N_SLINE  0x44
59 #define N_DSLINE 0x46
60 #define N_BSLINE 0x48
61 #define N_BROWS  0x48
62 #define N_DEFD   0x4A
63 #define N_EHDECL 0x50
64 #define N_MOD2   0x50
65 #define N_CATCH  0x54
66 #define N_SSYM   0x60
67 #define N_SO     0x64
68 #define N_LSYM   0x80
69 #define N_BINCL  0x82
70 #define N_SOL    0x84
71 #define N_PSYM   0xA0
72 #define N_EINCL  0xA2
73 #define N_ENTRY  0xA4
74 #define N_LBRAC  0xC0
75 #define N_EXCL   0xC2
76 #define N_SCOPE  0xC4
77 #define N_RBRAC  0xE0
78 #define N_BCOMM  0xE2
79 #define N_ECOMM  0xE4
80 #define N_ECOML  0xE8
81 #define N_LENG   0xFE
82 
83 /* COFF symbol table */
84 
85 #define E_SYMNMLEN	8	/* # characters in a symbol name	*/
86 #define E_FILNMLEN	14	/* # characters in a file name		*/
87 #define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
88 
89 #define N_BTMASK	(0xf)
90 #define N_TMASK		(0x30)
91 #define N_BTSHFT	(4)
92 #define N_TSHIFT	(2)
93 
94 /* derived types, in e_type */
95 #define DT_NON		(0)	/* no derived type */
96 #define DT_PTR		(1)	/* pointer */
97 #define DT_FCN		(2)	/* function */
98 #define DT_ARY		(3)	/* array */
99 
100 #define BTYPE(x)	((x) & N_BTMASK)
101 
102 #define ISPTR(x)	(((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
103 #define ISFCN(x)	(((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
104 #define ISARY(x)	(((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
105 #define ISTAG(x)	((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG)
106 #define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
107 
108 #define C_EFCN		0xff	/* physical end of function	*/
109 #define C_NULL		0
110 #define C_AUTO		1	/* automatic variable		*/
111 #define C_EXT		2	/* external symbol		*/
112 #define C_STAT		3	/* static			*/
113 #define C_REG		4	/* register variable		*/
114 #define C_EXTDEF	5	/* external definition		*/
115 #define C_LABEL		6	/* label			*/
116 #define C_ULABEL	7	/* undefined label		*/
117 #define C_MOS		8	/* member of structure		*/
118 #define C_ARG		9	/* function argument		*/
119 #define C_STRTAG	10	/* structure tag		*/
120 #define C_MOU		11	/* member of union		*/
121 #define C_UNTAG		12	/* union tag			*/
122 #define C_TPDEF		13	/* type definition		*/
123 #define C_USTATIC	14	/* undefined static		*/
124 #define C_ENTAG		15	/* enumeration tag		*/
125 #define C_MOE		16	/* member of enumeration	*/
126 #define C_REGPARM	17	/* register parameter		*/
127 #define C_FIELD		18	/* bit field			*/
128 #define C_AUTOARG	19	/* auto argument		*/
129 #define C_LASTENT	20	/* dummy entry (end of block)	*/
130 #define C_BLOCK		100	/* ".bb" or ".eb"		*/
131 #define C_FCN		101	/* ".bf" or ".ef"		*/
132 #define C_EOS		102	/* end of structure		*/
133 #define C_FILE		103	/* file name			*/
134 #define C_LINE		104	/* line # reformatted as symbol table entry */
135 #define C_ALIAS	 	105	/* duplicate tag		*/
136 #define C_HIDDEN	106	/* ext symbol in dmert public lib */
137 
138 #pragma pack(1)
139 typedef struct _COFF_SYMENT
140 {
141   union
142     {
143       char e_name[E_SYMNMLEN];
144       struct
145         {
146           ULONG e_zeroes;
147           ULONG e_offset;
148         }
149       e;
150     }
151   e;
152   ULONG e_value;
153   short e_scnum;
154   USHORT e_type;
155   UCHAR e_sclass;
156   UCHAR e_numaux;
157 } COFF_SYMENT, *PCOFF_SYMENT;
158 #pragma pack(4)
159 
160 #ifdef TARGET_i386
161 typedef ULONG TARGET_ULONG_PTR;
162 #else
163 typedef ULONGLONG TARGET_ULONG_PTR;
164 #endif
165 
166 typedef struct _ROSSYM_ENTRY {
167   TARGET_ULONG_PTR Address;
168   ULONG FunctionOffset;
169   ULONG FileOffset;
170   ULONG SourceLine;
171 } ROSSYM_ENTRY, *PROSSYM_ENTRY;
172 
173 #define ROUND_UP(N, S) (((N) + (S) - 1) & ~((S) - 1))
174 
175 extern char*
176 convert_path(const char* origpath);
177 
178 extern void*
179 load_file ( const char* file_name, size_t* file_size );
180