Debian Codegraph @

src/lib/libdwarf/dwarf_machoread.h

raw
1 /*
2 Copyright (c) 2018-2023, David Anderson
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with
6 or without modification, are permitted provided that the
7 following conditions are met:
8
9 Redistributions of source code must retain the above
10 copyright notice, this list of conditions and the following
11 disclaimer.
12
13 Redistributions in binary form must reproduce the above
14 copyright notice, this list of conditions and the following
15 disclaimer in the documentation and/or other materials
16 provided with the distribution.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 */
33 #ifndef DWARF_MACHOREAD_H
34 #define DWARF_MACHOREAD_H
35
36 struct Dwarf_Universal_Arch_s;
37 struct Dwarf_Universal_Head_s {
38 Dwarf_Unsigned au_magic;
39 Dwarf_Unsigned au_count;
40 Dwarf_Unsigned au_filesize; /* physical file size */
41 struct Dwarf_Universal_Arch_s * au_arches;
42
43 };
44 struct Dwarf_Universal_Arch_s {
45 Dwarf_Unsigned au_cputype;
46 Dwarf_Unsigned au_cpusubtype;
47 Dwarf_Unsigned au_offset;
48 Dwarf_Unsigned au_size;
49 Dwarf_Unsigned au_align;
50 Dwarf_Unsigned au_reserved;
51 };
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif /* __cplusplus */
56
57 struct generic_macho_header {
58 Dwarf_Unsigned magic;
59 Dwarf_Unsigned cputype;
60 Dwarf_Unsigned cpusubtype;
61 Dwarf_Unsigned filetype;
62 Dwarf_Unsigned ncmds; /* number of load commands */
63
64 /* the size of all the load commands */
65 Dwarf_Unsigned sizeofcmds;
66
67 Dwarf_Unsigned flags;
68 Dwarf_Unsigned reserved;
69 };
70 struct generic_macho_command {
71 Dwarf_Unsigned cmd;
72 Dwarf_Unsigned cmdsize;
73 Dwarf_Unsigned offset_this_command;
74 };
75
76 struct generic_macho_segment_command {
77 Dwarf_Unsigned cmd;
78 Dwarf_Unsigned cmdsize;
79 char segname[24];
80 Dwarf_Unsigned vmaddr;
81 Dwarf_Unsigned vmsize;
82 Dwarf_Unsigned fileoff;
83 Dwarf_Unsigned filesize;
84 Dwarf_Unsigned maxprot;
85 Dwarf_Unsigned initprot;
86 Dwarf_Unsigned nsects;
87 Dwarf_Unsigned flags;
88
89 /* our index into mo_commands */
90 Dwarf_Unsigned macho_command_index;
91 Dwarf_Unsigned sectionsoffset;
92 };
93
94 struct generic_macho_section {
95 /* Larger than in file, room for NUL guaranteed */
96 char sectname[24];
97 char segname[24];
98 const char * dwarfsectname;
99 Dwarf_Unsigned addr;
100 Dwarf_Unsigned size;
101 Dwarf_Unsigned offset;
102 Dwarf_Unsigned align;
103 Dwarf_Unsigned reloff;
104 Dwarf_Unsigned nreloc;
105 Dwarf_Unsigned flags;
106 Dwarf_Unsigned reserved1;
107 Dwarf_Unsigned reserved2;
108 Dwarf_Unsigned reserved3;
109 Dwarf_Unsigned generic_segment_num;
110 Dwarf_Unsigned offset_of_sec_rec;
111 Dwarf_Small* loaded_data;
112 };
113
114 /* ident[0] == 'M' means this is a macho header.
115 ident[1] will be 1 indicating version 1.
116 Other bytes in ident not defined, should be zero. */
117 typedef struct dwarf_macho_filedata_s {
118 char mo_ident[8];
119 const char * mo_path; /* libdwarf must free.*/
120 int mo_fd;
121 int mo_destruct_close_fd; /*aka: lib owns fd */
122 Dwarf_Unsigned mo_filesize;
123 Dwarf_Unsigned mo_machine;
124 Dwarf_Unsigned mo_flags;
125 Dwarf_Unsigned mo_inner_offset; /* for universal inner */
126 Dwarf_Small mo_offsetsize; /* 32 or 64 section data */
127 Dwarf_Small mo_pointersize;
128 int mo_ftype;
129 Dwarf_Small mo_endian;
130 unsigned mo_uninumber; /* for universal binary */
131 unsigned mo_universal_count; /* for universal binary*/
132 /*Dwarf_Small mo_machine; */
133 void (*mo_copy_word) (void *, const void *, unsigned long);
134
135 /* Used to hold 32 and 64 header data */
136 struct generic_macho_header mo_header;
137
138 unsigned mo_command_count;
139 Dwarf_Unsigned mo_command_start_offset;
140 struct generic_macho_command *mo_commands;
141 Dwarf_Unsigned mo_offset_after_commands;
142
143 Dwarf_Unsigned mo_segment_count;
144 struct generic_macho_segment_command *mo_segment_commands;
145
146 Dwarf_Unsigned mo_dwarf_sectioncount;
147 struct generic_macho_section *mo_dwarf_sections;
148 } dwarf_macho_object_access_internals_t;
149
150 int _dwarf_load_macho_header(
151 dwarf_macho_object_access_internals_t * mfp,
152 int *errcode);
153 int _dwarf_load_macho_commands(
154 dwarf_macho_object_access_internals_t * mfp,
155 int *errcode);
156
157 #ifdef __cplusplus
158 }
159 #endif /* __cplusplus */
160 #endif /* DWARF_MACHOREAD_H */