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