OSDN Git Service

715474e5ec05e4536853c8e4c26857fb124e523e
[drdeamon64/drdeamon64.git] / libgoblin / drd64_libgoblin_type.h
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11  1. Redistributions of source code must retain the above copyright notice,
12     this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.h
33 Function: Header 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #ifndef DRD64_HEADER_LIBGOBLIN_TYPE
38 #define DRD64_HEADER_LIBGOBLIN_TYPE
39
40
41 /*=====================================================================*/
42 #define DWARF_ABBREV_MAXITEMS   30
43
44 typedef struct  {
45         DWord   dw_id;
46         DWord   dw_tag;
47         Byte    b_children;
48         int             i_items;
49         DWord   dw_attribute[ DWARF_ABBREV_MAXITEMS ];
50         DWord   dw_format[ DWARF_ABBREV_MAXITEMS ];
51 } DWARF_AbbrevEntry;
52
53
54 /*=====================================================================*/
55 #define LIBGOBLIN_DWARF_INFO_TYPE_NONE          0x00
56 #define LIBGOBLIN_DWARF_INFO_TYPE_BYTE          0x01
57 #define LIBGOBLIN_DWARF_INFO_TYPE_WORD          0x02
58 #define LIBGOBLIN_DWARF_INFO_TYPE_DWORD         0x03
59 #define LIBGOBLIN_DWARF_INFO_TYPE_QWORD         0x04
60 #define LIBGOBLIN_DWARF_INFO_TYPE_INT64         0x05
61 #define LIBGOBLIN_DWARF_INFO_TYPE_POINTER       0x06
62 #define LIBGOBLIN_DWARF_INFO_TYPE_STRING        0x07
63 #define LIBGOBLIN_DWARF_INFO_TYPE_BLOCK         0x08
64 #define LIBGOBLIN_DWARF_INFO_TYPE_LINK          0x09
65
66 typedef struct  {
67         Byte    b_type;
68         QWord   qw_size;
69
70         union   {
71                 Byte    b_value;
72                 Word    w_value;
73                 DWord   dw_value;
74                 QWord   qw_value;
75                 QWord   qw_link;
76                 Int64   ii_value;
77                 void    *p_value;
78                 Byte    *pb_link;
79                 char    *pstr_value;
80                 Byte    *pb_data;               // for BlockData
81         } value;
82 } LibGoblin_DWARF_DIEValue;
83
84
85 /*=====================================================================*/
86 typedef struct  {
87         DWord                           dw_attribute;
88         LibGoblin_DWARF_DIEValue        *p_val;
89 } LibGoblin_DWARF_Attribute;
90
91
92 /*=====================================================================*/
93 typedef struct  {
94         Byte    *pb_sechdr;
95         Byte    *pb_data;               // FileLocation (Offset)
96         Word    w_index;
97         Ptr             ptr_addr;
98         QWord   qw_size;
99         QWord   qw_flag;
100         QWord   qw_entsize;
101         char    *pstr_secname;
102         int             i_binfile;
103
104         int             i_objid;
105 } LibGoblin_SectionInfo;
106
107
108 /*=====================================================================*/
109 /*typedef       struct  {
110         Ptr             ptr_address;    // Object Address
111         DWord   dw_size;                // Object Size (Address Range)
112         char    *pstr_name;             // Object Name (Param./Func./etc...)
113         //DWord dw_srcid;               // SourceInfo struct ID
114         DWord   dw_next;
115         Byte    b_elf_flags;
116         Word    w_secid;                // SectionInfo ItemIndex belong with this object.
117 } LibGoblin_AddressInfo ****OLD****   ;*/
118
119
120 /*=====================================================================*/
121 #define OBJINFO_STATUS_INVALID  0x00000000
122 #define OBJINFO_STATUS_VALID    0x00000001      // bit 0
123 #define OBJINFO_STATUS_DYNAMIC  0x00000002      // bit 1
124 #define OBJINFO_STATUS_RESOLV1  0x00000004      // bit 2 (Specified BinaryInfo & Index)
125 #define OBJINFO_STATUS_RESOLV2  0x00000008      // bit 3 (Loaded .so)
126 #define OBJINFO_STATUS_REL              0x00000100
127
128 #define OBJINFO_TYPE_NULL               0x00
129 #define OBJINFO_TYPE_PROGRAM    0x01
130 #define OBJINFO_TYPE_MASTER             0x02
131 #define OBJINFO_TYPE_PROGHDR    0x03
132 #define OBJINFO_TYPE_SECTION    0x04
133 #define OBJINFO_TYPE_FUNCTION   0x05
134 #define OBJINFO_TYPE_OBJECT             0x06
135 #define OBJINFO_TYPE_COMMON             0x07
136 #define OBJINFO_TYPE_TLS                0x08
137 #define OBJINFO_TYPE_REL                0x09
138
139 typedef struct  {
140         int             i_id;
141         Byte    b_type;
142         DWord   dw_status;
143
144         // Address & Memory-Range Info ----
145         struct  {
146                 Ptr             ptr_addr;               // Object Address
147                 //   [Section] sh_addr - Address in memory image.
148                 //   [Symbol ] st_value - Symbol value.
149                 QWord   qw_size;                // Object Size (Address Range)
150                 //   [Symbol ] st_size - Size of associated object.
151         } addr;
152
153         // Group(Parent-Child) Order Link ---
154         struct  {
155                 int             i_parent_id;    // Parent ObjectInfo
156                 int             i_child_topid;  // Child Top ObjectInfo
157                 int             i_prev_id;
158                 int             i_next_id;              // Next 
159         } grplink;
160
161         // Address Order Link ---
162         struct  {
163                 int             i_next_id;              // Next Address ObjectInfo
164                 int             i_prev_id;              // Prev Address ObjectInfo
165         } addrlink;
166
167         // File Info ---
168         struct  {
169                 int             i_binfile;
170                 void    *pv_offset;
171                 //   [Section] sh_offset - Offset in file.
172                 QWord   qw_size;
173         } file;
174
175         // ObjectInfo (DATA) ---
176         char    *pstr_name;             // Object Name (Param./Func./etc...)
177         //   [Section] = sh_name - Section name (index into the section header string table).
178         //   [Symbol ] = st_name - String table index of name.
179         DWord   dw_hash;
180         
181         union   {
182                 Byte            b_data[128];
183
184                 struct  {
185                         int             i_binfo_id;
186                 } program;
187
188                 struct  {
189                         DWord   dw_type;                // Entry type.
190                         DWord   dw_flags;               // Access permission flags.
191                         QWord   qw_align;               // Alignment in memory and file.
192                         void    *pv_proghdr;    // Program Header Pointer
193                 } proghdr;
194
195                 struct  {
196                         QWord   qw_flag;                // sh_flags - Section flags.
197                         QWord   qw_align;               // sh_addralign - Alignment in bytes.
198                         QWord   qw_entsize;             // sh_entsize - Size of each entry in section.
199                         DWord   dw_type;                // sh_type - Section type.
200                         DWord   dw_link;                // sh_link - Index of a related section.
201                         DWord   dw_info;                // sh_info - Depends on section type.
202                         void    *pv_sechdr;
203                 } section;
204
205                 struct  {
206                         Byte    b_type;                 // st_info - Type and binding information.
207                         Byte    b_binding;              // st_info - Type and binding information.
208                         Byte    b_visibility;   // st_other - Reserved (not used).
209                         Word    w_secindex;             // st_shndx - Section index of symbol.
210                 } symbol;
211
212         } info;
213
214         struct  {
215                 int             i_binfo_origin;
216                 int             i_dynsym_index;
217
218                 int             i_objid_rel;
219         } dynamic;
220
221         struct  {
222                 int             i_objid_origin;
223         } rel;
224
225         int             i_secid;
226         int             i_srcid;                // SourceInfo struct ID
227
228         Byte    b_elf_flags;
229         Word    w_secid;                // ==OLD== SectionInfo ItemIndex belong with this object.
230
231 } LibGoblin_ObjectInfo;
232
233
234 /*=====================================================================*/
235 typedef struct  {
236         Ptr             ptr_addr;
237         int             i_objid;
238 } LibGoblin_AddressInfo;
239
240 /*=====================================================================*/
241 typedef struct  {
242         int             i_id;
243         DWord   dw_hash_filename;
244         DWord   dw_hash_localpath;
245         char    str_filename[DRD64_MAX_PATH];
246         char    str_localpath[DRD64_MAX_PATH];
247         char    str_srcpath[DRD64_MAX_PATH];    // for DW_AT_name
248         char    str_buildpath[DRD64_MAX_PATH];  // for DW_AT_comp_dir (Optional)
249
250         int             i_bfile_id;
251         struct  {
252                 int                                     i_abbrevs;
253                 DWARF_AbbrevEntry       *p_abbrev;
254         } dwarf;
255
256 } LibGoblin_SrcFile;
257
258
259 /*=====================================================================*/
260 #define BINFILE_FLAGMASK_FILE                   (DWord)0x00000007
261 #define BINFILE_FLAG_FILE_MMAP                  (DWord)0x00000001
262 #define BINFILE_FLAG_FILE_EXTALLOC              (DWord)0x00000002
263 #define BINFILE_FLAG_FILE_INTALLOC              (DWord)0x00000004
264
265 #define BINFILE_FLAGMASK_RELTYPE                (DWord)0x00000010
266 #define BINFILE_FLAG_RELTYPE_REL                (DWord)0x00000000
267 #define BINFILE_FLAG_RELTYPE_RELA               (DWord)0x00000010
268
269 #define BINFILE_STATUS_NOUSE                    0x00
270 #define BINFILE_STATUS_CREATE                   0x01
271 #define BINFILE_STATUS_FILEOPEN                 0x02
272 #define BINFILE_STATUS_READSECTION              0x03
273
274 typedef struct  {
275         int                     i_id;
276         int                     i_refcount;
277
278         /* Binary-File Info. */
279         int                     i_fd;
280         DWord           dw_flag;
281         Byte            b_status;
282
283         // EXEC-program / shared lib. filename (without directry)
284         char            str_filename[DRD64_MAX_PATH];
285         char            str_localpath[DRD64_MAX_PATH];  // filepath in local machine path.(transported)
286         char            str_remotepath[DRD64_MAX_PATH]; // filepath in remote machine path.(local machine is NULL)
287
288         // .dynamic Section - rpath (.so location path - converted real-path) 
289         char            str_rpath[DRD64_MAX_PATH];
290         // .dynamic Section - runpath (.so location path - converted real-path) 
291         char            str_runpath[DRD64_MAX_PATH];
292
293         LibFileType_FileType    t_ftype;
294
295         /* Binary-File Memory Image Access Info. */
296         DWord           dw_size;
297         Byte            *pb_binary;
298
299         struct  {
300                 LibGoblin_SrcFile       *p_srcfile;
301                 int                                     i_alloc;
302                 int                                     i_max;
303                 int                                     i_now;
304         } srcfile;
305
306         struct  {
307                 int                                     i_abbrevs_max;
308                 int                                     i_abbrevs_alloc;
309                 DWARF_AbbrevEntry       *p_abbrev;
310                 QWord                           qw_abbrev_unreadsz;
311
312                 int                                     i_srcfiles;
313
314                 int                                     i_maxvals;
315         } dwarf;
316
317         /* Binary-Format Depending Info. (ELF)*/
318         void            *p_elf;
319
320         LibGoblin_SectionInfo   t_section[LIBGOBLIN_SECTION_ID_MAX];
321         int                                             i_secindex[LIBGOBLIN_SECTION_ID_MAX];
322 } LibGoblin_BinaryFile;
323
324
325 /*=====================================================================*/
326 #define LIBGOBLIN_BINFO_PHASE_INIT              0x00
327 #define LIBGOBLIN_BINFO_PHASE_ALLOCED   0x10
328 #define LIBGOBLIN_BINFO_PHASE_SETNAME   0x20
329 #define LIBGOBLIN_BINFO_PHASE_SETPROG   0x30
330 #define LIBGOBLIN_BINFO_PHASE_BINREAD   0x40
331 #define LIBGOBLIN_BINFO_PHASE_ELF1READ  0x51
332 #define LIBGOBLIN_BINFO_PHASE_ELF2READ  0x52
333 #define LIBGOBLIN_BINFO_PHASE_ANALYZED  0x50
334
335 #define LIBGOBLIN_BINFO_TYPE_NONE               0x00
336 #define LIBGOBLIN_BINFO_TYPE_ELF                0x01
337 #define LIBGOBLIN_BINFO_TYPE_ELF64              0x64
338 #define LIBGOBLIN_BINFO_TYPE_ELF32              0x32
339
340 #define isElf64(n) \
341         ((LIBGOBLIN_BINFO_TYPE_ELF64==((n)->b_type)) ? 0x01 : 0x00)
342 #define isElf32(n) \
343         ((LIBGOBLIN_BINFO_TYPE_ELF32==((n)->b_type)) ? 0x01 : 0x00)
344 #define IsBinfoType_Elf64(n) \
345         ((LIBGOBLIN_BINFO_TYPE_ELF64==((n)->b_type)) ? 0x01 : 0x00)
346 #define IsBinfoType_Elf32(n) \
347         ((LIBGOBLIN_BINFO_TYPE_ELF32==((n)->b_type)) ? 0x01 : 0x00)
348
349 #define LIBGOBLIN_BINFO_ENDIAN_NONE             0x00
350 #define LIBGOBLIN_BINFO_ENDIAN_LITTLE   0x01
351 #define LIBGOBLIN_BINFO_ENDIAN_BIG              0x02
352
353 #define LIBGOBLIN_BINFO_SECTION_TEXT    0x00
354 #define LIBGOBLIN_BINFO_SECTION_DATA    0x01
355 #define LIBGOBLIN_BINFO_SECTION_BSS             0x02
356
357 #define LIBGOBLIN_BINFO_MAXFILES                3       // Except FILE_LIBRARY
358 #define LIBGOBLIN_BINFO_FILE_EXEC               0
359 #define LIBGOBLIN_BINFO_FILE_CORE               1
360 #define LIBGOBLIN_BINFO_FILE_DEBUG              2
361 #define LIBGOBLIN_BINFO_FILE_LIBRARY    -1
362
363 typedef struct  {
364         /* BinaryInfo Struct ID */
365         int                     i_id;
366         Byte            b_phase;
367
368         /* BinaryInfo Common Info. */
369         Byte            b_type;
370         Byte            b_endian;
371         Byte            b_bits;
372
373         /* Debug-Format Depending Info. (DWarf) */
374         void            *p_debug;
375
376         /* Address Table Info. */
377 /*
378         LibGoblin_AddressInfo   *p_addrinfo;
379         DWord           dw_alloc_addrinfo;
380         DWord           dw_max_addrinfo;
381 */
382
383         /* Exec. File Info. */
384         char            str_filename[DRD64_MAX_PATH];
385         DWord           dw_hash;
386         
387         int                     i_binfile;              // binaryFile ID
388         int                     i_binfile_debug;
389
390         int                     i_pginfo;
391         int                     i_binfo_parent;
392         int                     i_binfo_next;
393
394         PtrValue        ptr_loadbase;
395
396         LibGoblin_SectionInfo   t_section[LIBGOBLIN_SECTION_ID_MAX];
397
398         /* Binary-Format Depending Info. (ELF)*/
399         //void          *p_format;
400
401         struct  {
402                 int                                                     i_maxvals;
403                 LibGoblin_DWARF_DIEValue        *p_infoval;
404         } dwarf;
405
406
407 }       LibGoblin_BinaryInfo;
408
409
410 /*=====================================================================*/
411 typedef struct  {
412
413         int                                             i_id;
414
415         // Object Table & Address Table ---
416         struct  {
417                 LibGoblin_ObjectInfo    *p_objinfo;
418                 int                                             i_empty;        // Empty ObjectInfo Chain Top-ID.
419                 int                                             i_alloced;      // Alloced ObjectInfo
420                 int                                             i_used;         // ObjectInfo Items
421                 int                                             i_topid;        // Top-Ptr ObjectInfo
422         } objinfo;
423         LibGoblin_AddressInfo   *p_addrinfo;
424         
425         Word                                    dw_flag;
426
427         int             i_binfo_id;
428         int             i_binfo_id_core;
429
430         /* Address Table Info. */
431         //LibGoblin_AddressInfo *p_addrinfo;
432         //DWord         dw_alloc_addrinfo;
433         //DWord         dw_max_addrinfo;
434
435         
436 }       LibGoblin_ProgramInfo;
437
438
439 #endif  /* DRD64_HEADER_LIBGOBLIN_TYPE*/
440
441 /* EOF of drd64_.h ----------------------------------- */