OSDN Git Service

(LibGoblin)
[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 typedef struct  {
43         QWord   qw_unitsize;
44         Word    w_version;
45         Byte    b_pointersize;
46         Byte    b_bits;
47         Byte    b_offsetsize;
48         QWord   qw_abbrev_offset;
49         Byte    *pb_custart;
50
51         QWord   qw_type_signature;      // for DWARF4
52         QWord   qw_type_offset;         // for DWARF4
53 } LibGoblin_DWARF_Info_CUHeader;
54
55
56 /*=====================================================================*/
57 #define DWARF_ABBREV_MAXITEMS   30
58
59 typedef struct  {
60         DWord   dw_id;
61         DWord   dw_tag;
62         Byte    b_children;
63         int             i_items;
64         DWord   dw_attribute[ DWARF_ABBREV_MAXITEMS ];
65         DWord   dw_format[ DWARF_ABBREV_MAXITEMS ];
66 } DWARF_AbbrevEntry;
67
68
69 /*=====================================================================*/
70 #define LIBGOBLIN_DWARF_INFO_TYPE_NONE          0x00
71 #define LIBGOBLIN_DWARF_INFO_TYPE_BYTE          0x01
72 #define LIBGOBLIN_DWARF_INFO_TYPE_WORD          0x02
73 #define LIBGOBLIN_DWARF_INFO_TYPE_DWORD         0x03
74 #define LIBGOBLIN_DWARF_INFO_TYPE_QWORD         0x04
75 #define LIBGOBLIN_DWARF_INFO_TYPE_INT64         0x05
76 #define LIBGOBLIN_DWARF_INFO_TYPE_POINTER       0x06
77 #define LIBGOBLIN_DWARF_INFO_TYPE_STRING        0x07
78 #define LIBGOBLIN_DWARF_INFO_TYPE_BLOCK         0x08
79 #define LIBGOBLIN_DWARF_INFO_TYPE_LINK          0x09
80
81 typedef struct  {
82         Byte    b_type;
83         QWord   qw_size;
84         DWord   dw_format;
85
86         union   {
87                 Byte    b_value;
88                 Word    w_value;
89                 DWord   dw_value;
90                 QWord   qw_value;
91                 QWord   qw_link;
92                 Int64   ii_value;
93                 void    *p_value;
94                 Byte    *pb_link;
95                 char    *pstr_value;
96                 Byte    *pb_data;               // for BlockData
97         } value;
98 } LibGoblin_DWARF_DIEValue;
99
100
101 /*=====================================================================*/
102 typedef struct  {
103         DWord                           dw_attribute;
104         LibGoblin_DWARF_DIEValue        *p_val;
105 } LibGoblin_DWARF_Attribute;
106
107
108 /*=====================================================================*/
109 typedef struct  {
110         Byte    *pb_sechdr;
111         Byte    *pb_data;               // FileLocation (Offset)
112         Word    w_index;
113         Ptr             ptr_addr;
114         QWord   qw_size;
115         QWord   qw_flag;
116         QWord   qw_entsize;
117         char    *pstr_secname;
118         int             i_binfile;
119
120         int             i_objid;
121 } LibGoblin_SectionInfo;
122
123
124 /*=====================================================================*/
125 /*typedef       struct  {
126         Ptr             ptr_address;    // Object Address
127         DWord   dw_size;                // Object Size (Address Range)
128         char    *pstr_name;             // Object Name (Param./Func./etc...)
129         //DWord dw_srcid;               // SourceInfo struct ID
130         DWord   dw_next;
131         Byte    b_elf_flags;
132         Word    w_secid;                // SectionInfo ItemIndex belong with this object.
133 } LibGoblin_AddressInfo ****OLD****   ;*/
134
135
136 /*=====================================================================*/
137 #define OBJINFO_STATUS_INVALID  0x00000000
138 #define OBJINFO_STATUS_VALID    0x00000001      // bit 0
139 #define OBJINFO_STATUS_DYNAMIC  0x00000002      // bit 1
140 #define OBJINFO_STATUS_RESOLV1  0x00000004      // bit 2 (Specified BinaryInfo & Index)
141 #define OBJINFO_STATUS_RESOLV2  0x00000008      // bit 3 (Loaded .so)
142 #define OBJINFO_STATUS_REL              0x00000100
143
144 #define OBJINFO_TYPE_NULL               0x00
145 #define OBJINFO_TYPE_PROGRAM    0x01
146 #define OBJINFO_TYPE_MASTER             0x02
147 #define OBJINFO_TYPE_PROGHDR    0x03
148 #define OBJINFO_TYPE_SECTION    0x04
149 #define OBJINFO_TYPE_FUNCTION   0x05
150 #define OBJINFO_TYPE_OBJECT             0x06
151 #define OBJINFO_TYPE_COMMON             0x07
152 #define OBJINFO_TYPE_TLS                0x08
153 #define OBJINFO_TYPE_REL                0x09
154
155 typedef struct  {
156         int             i_id;
157         Byte    b_type;
158         DWord   dw_status;
159
160         // Address & Memory-Range Info ----
161         struct  {
162                 Ptr             ptr_addr;               // Object Address
163                 //   [Section] sh_addr - Address in memory image.
164                 //   [Symbol ] st_value - Symbol value.
165                 QWord   qw_size;                // Object Size (Address Range)
166                 //   [Symbol ] st_size - Size of associated object.
167         } addr;
168
169         // Group(Parent-Child) Order Link ---
170         struct  {
171                 int             i_parent_id;    // Parent ObjectInfo
172                 int             i_child_topid;  // Child Top ObjectInfo
173                 int             i_prev_id;
174                 int             i_next_id;              // Next 
175         } grplink;
176
177         // Address Order Link ---
178         struct  {
179                 int             i_next_id;              // Next Address ObjectInfo
180                 int             i_prev_id;              // Prev Address ObjectInfo
181         } addrlink;
182
183         // File Info ---
184         struct  {
185                 int             i_binfile;
186                 void    *pv_offset;
187                 //   [Section] sh_offset - Offset in file.
188                 QWord   qw_size;
189         } file;
190
191         // ObjectInfo (DATA) ---
192         char    *pstr_name;             // Object Name (Param./Func./etc...)
193         //   [Section] = sh_name - Section name (index into the section header string table).
194         //   [Symbol ] = st_name - String table index of name.
195         DWord   dw_hash;
196         
197         union   {
198                 Byte            b_data[128];
199
200                 struct  {
201                         int             i_binfo_id;
202                 } program;
203
204                 struct  {
205                         DWord   dw_type;                // Entry type.
206                         DWord   dw_flags;               // Access permission flags.
207                         QWord   qw_align;               // Alignment in memory and file.
208                         void    *pv_proghdr;    // Program Header Pointer
209                 } proghdr;
210
211                 struct  {
212                         QWord   qw_flag;                // sh_flags - Section flags.
213                         QWord   qw_align;               // sh_addralign - Alignment in bytes.
214                         QWord   qw_entsize;             // sh_entsize - Size of each entry in section.
215                         DWord   dw_type;                // sh_type - Section type.
216                         DWord   dw_link;                // sh_link - Index of a related section.
217                         DWord   dw_info;                // sh_info - Depends on section type.
218                         void    *pv_sechdr;
219                 } section;
220
221                 struct  {
222                         Byte    b_type;                 // st_info - Type and binding information.
223                         Byte    b_binding;              // st_info - Type and binding information.
224                         Byte    b_visibility;   // st_other - Reserved (not used).
225                         Word    w_secindex;             // st_shndx - Section index of symbol.
226                 } symbol;
227
228         } info;
229
230         struct  {
231                 int             i_binfo_origin;
232                 int             i_dynsym_index;
233
234                 int             i_objid_rel;
235         } dynamic;
236
237         struct  {
238                 int             i_objid_origin;
239         } rel;
240
241         int             i_secid;
242         int             i_srcid;                // SourceInfo struct ID
243
244         Byte    b_elf_flags;
245         Word    w_secid;                // ==OLD== SectionInfo ItemIndex belong with this object.
246
247 } LibGoblin_ObjectInfo;
248
249
250 /*=====================================================================*/
251 typedef struct  {
252         Ptr             ptr_addr;
253         int             i_objid;
254 } LibGoblin_AddressInfo;
255
256 /*=====================================================================*/
257 typedef struct  {
258         int             i_id;
259         DWord   dw_hash_filename;
260         DWord   dw_hash_localpath;
261         char    str_filename[DRD64_MAX_PATH];
262         char    str_localpath[DRD64_MAX_PATH];
263         char    str_srcpath[DRD64_MAX_PATH];    // for DW_AT_name
264         char    str_buildpath[DRD64_MAX_PATH];  // for DW_AT_comp_dir (Optional)
265
266         int             i_bfile_id;
267         struct  {
268                 int                                     i_abbrevs;
269                 DWARF_AbbrevEntry       *p_abbrev;
270         } dwarf;
271
272 } LibGoblin_SrcFile;
273
274
275 /*=====================================================================*/
276 #define BINFILE_FLAGMASK_FILE                   (DWord)0x00000007
277 #define BINFILE_FLAG_FILE_MMAP                  (DWord)0x00000001
278 #define BINFILE_FLAG_FILE_EXTALLOC              (DWord)0x00000002
279 #define BINFILE_FLAG_FILE_INTALLOC              (DWord)0x00000004
280
281 #define BINFILE_FLAGMASK_RELTYPE                (DWord)0x00000010
282 #define BINFILE_FLAG_RELTYPE_REL                (DWord)0x00000000
283 #define BINFILE_FLAG_RELTYPE_RELA               (DWord)0x00000010
284
285 #define BINFILE_STATUS_NOUSE                    0x00
286 #define BINFILE_STATUS_CREATE                   0x01
287 #define BINFILE_STATUS_FILEOPEN                 0x02
288 #define BINFILE_STATUS_READSECTION              0x03
289
290 typedef struct  {
291         int                     i_id;
292         int                     i_refcount;
293
294         /* Binary-File Info. */
295         int                     i_fd;
296         DWord           dw_flag;
297         Byte            b_status;
298
299         // EXEC-program / shared lib. filename (without directry)
300         char            str_filename[DRD64_MAX_PATH];
301         char            str_localpath[DRD64_MAX_PATH];  // filepath in local machine path.(transported)
302         char            str_remotepath[DRD64_MAX_PATH]; // filepath in remote machine path.(local machine is NULL)
303
304         // .dynamic Section - rpath (.so location path - converted real-path) 
305         char            str_rpath[DRD64_MAX_PATH];
306         // .dynamic Section - runpath (.so location path - converted real-path) 
307         char            str_runpath[DRD64_MAX_PATH];
308
309         LibFileType_FileType    t_ftype;
310
311         /* Binary-File Memory Image Access Info. */
312         DWord           dw_size;
313         Byte            *pb_binary;
314
315         struct  {
316                 LibGoblin_SrcFile       *p_srcfile;
317                 int                                     i_alloc;
318                 int                                     i_max;
319                 int                                     i_now;
320         } srcfile;
321
322         struct  {
323                 int                                     i_abbrevs_max;
324                 int                                     i_abbrevs_alloc;
325                 DWARF_AbbrevEntry       *p_abbrev;
326                 QWord                           qw_abbrev_unreadsz;
327
328                 int                                     i_srcfiles;
329
330                 int                                     i_maxvals;
331         } dwarf;
332
333         /* Binary-Format Depending Info. (ELF)*/
334         void            *p_elf;
335
336         LibGoblin_SectionInfo   t_section[LIBGOBLIN_SECTION_ID_MAX];
337         int                                             i_secindex[LIBGOBLIN_SECTION_ID_MAX];
338 } LibGoblin_BinaryFile;
339
340
341 /*=====================================================================*/
342 #define LIBGOBLIN_BINFO_PHASE_INIT              0x00
343 #define LIBGOBLIN_BINFO_PHASE_ALLOCED   0x10
344 #define LIBGOBLIN_BINFO_PHASE_SETNAME   0x20
345 #define LIBGOBLIN_BINFO_PHASE_SETPROG   0x30
346 #define LIBGOBLIN_BINFO_PHASE_BINREAD   0x40
347 #define LIBGOBLIN_BINFO_PHASE_ELF1READ  0x51
348 #define LIBGOBLIN_BINFO_PHASE_ELF2READ  0x52
349 #define LIBGOBLIN_BINFO_PHASE_ANALYZED  0x50
350
351 #define LIBGOBLIN_BINFO_TYPE_NONE               0x00
352 #define LIBGOBLIN_BINFO_TYPE_ELF                0x01
353 #define LIBGOBLIN_BINFO_TYPE_ELF64              0x64
354 #define LIBGOBLIN_BINFO_TYPE_ELF32              0x32
355
356 #define isElf64(n) \
357         ((LIBGOBLIN_BINFO_TYPE_ELF64==((n)->b_type)) ? 0x01 : 0x00)
358 #define isElf32(n) \
359         ((LIBGOBLIN_BINFO_TYPE_ELF32==((n)->b_type)) ? 0x01 : 0x00)
360 #define IsBinfoType_Elf64(n) \
361         ((LIBGOBLIN_BINFO_TYPE_ELF64==((n)->b_type)) ? 0x01 : 0x00)
362 #define IsBinfoType_Elf32(n) \
363         ((LIBGOBLIN_BINFO_TYPE_ELF32==((n)->b_type)) ? 0x01 : 0x00)
364
365 #define LIBGOBLIN_BINFO_ENDIAN_NONE             0x00
366 #define LIBGOBLIN_BINFO_ENDIAN_LITTLE   0x01
367 #define LIBGOBLIN_BINFO_ENDIAN_BIG              0x02
368
369 #define LIBGOBLIN_BINFO_SECTION_TEXT    0x00
370 #define LIBGOBLIN_BINFO_SECTION_DATA    0x01
371 #define LIBGOBLIN_BINFO_SECTION_BSS             0x02
372
373 #define LIBGOBLIN_BINFO_MAXFILES                3       // Except FILE_LIBRARY
374 #define LIBGOBLIN_BINFO_FILE_EXEC               0
375 #define LIBGOBLIN_BINFO_FILE_CORE               1
376 #define LIBGOBLIN_BINFO_FILE_DEBUG              2
377 #define LIBGOBLIN_BINFO_FILE_LIBRARY    -1
378
379 #define LIBGOBLIN_DWARF_ATTR_DEF_MAX    0x6f
380 #define LIBGOBLIN_DWARF_ATTR_EXT_MAX    53
381 #define LIBGOBLIN_DWARF_ATTR_MAX                (LIBGOBLIN_DWARF_ATTR_DEF_MAX + LIBGOBLIN_DWARF_ATTR_EXT_MAX)
382
383
384 typedef struct  {
385         /* BinaryInfo Struct ID */
386         int                     i_id;
387         Byte            b_phase;
388
389         /* BinaryInfo Common Info. */
390         Byte            b_type;
391         Byte            b_endian;
392         Byte            b_bits;
393
394         /* Debug-Format Depending Info. (DWarf) */
395         void            *p_debug;
396
397         /* Address Table Info. */
398 /*
399         LibGoblin_AddressInfo   *p_addrinfo;
400         DWord           dw_alloc_addrinfo;
401         DWord           dw_max_addrinfo;
402 */
403
404         /* Exec. File Info. */
405         char            str_filename[DRD64_MAX_PATH];
406         DWord           dw_hash;
407         
408         int                     i_binfile;              // binaryFile ID
409         int                     i_binfile_debug;
410
411         int                     i_pginfo;
412         int                     i_binfo_parent;
413         int                     i_binfo_next;
414
415         PtrValue        ptr_loadbase;
416
417         LibGoblin_SectionInfo   t_section[LIBGOBLIN_SECTION_ID_MAX];
418
419         /* Binary-Format Depending Info. (ELF)*/
420         //void          *p_format;
421
422         struct  {
423                 int                                                     i_maxvals;
424                 LibGoblin_DWARF_DIEValue        *p_infoval;
425
426                 int                                                     i_extattrs;
427                 LibGoblin_DWARF_Attribute       t_attr[LIBGOBLIN_DWARF_ATTR_MAX+1];
428         } dwarf;
429
430
431 }       LibGoblin_BinaryInfo;
432
433
434 /*=====================================================================*/
435 typedef struct  {
436
437         int                                             i_id;
438
439         // Object Table & Address Table ---
440         struct  {
441                 LibGoblin_ObjectInfo    *p_objinfo;
442                 int                                             i_empty;        // Empty ObjectInfo Chain Top-ID.
443                 int                                             i_alloced;      // Alloced ObjectInfo
444                 int                                             i_used;         // ObjectInfo Items
445                 int                                             i_topid;        // Top-Ptr ObjectInfo
446         } objinfo;
447         LibGoblin_AddressInfo   *p_addrinfo;
448         
449         Word                                    dw_flag;
450
451         int             i_binfo_id;
452         int             i_binfo_id_core;
453
454         /* Address Table Info. */
455         //LibGoblin_AddressInfo *p_addrinfo;
456         //DWord         dw_alloc_addrinfo;
457         //DWord         dw_max_addrinfo;
458
459         
460 }       LibGoblin_ProgramInfo;
461
462
463 #endif  /* DRD64_HEADER_LIBGOBLIN_TYPE*/
464
465 /* EOF of drd64_.h ----------------------------------- */