OSDN Git Service

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