2 * Copyright 2012 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifdef __i386__ /* thiscall functions are i386-specific */
21 #define THISCALL(func) __thiscall_ ## func
22 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
23 #define __thiscall __stdcall
24 #define DEFINE_THISCALL_WRAPPER(func,args) \
25 extern void THISCALL(func)(void); \
26 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
30 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
33 #define THISCALL(func) func
34 #define THISCALL_NAME(func) __ASM_NAME(#func)
35 #define __thiscall __cdecl
36 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
42 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
44 #define __ASM_VTABLE(name,funcs) \
47 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
48 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
49 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
54 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
56 #define __ASM_VTABLE(name,funcs) \
59 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
60 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
61 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
68 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
69 static const type_info name ## _type_info = { \
70 &MSVCRT_type_info_vtable, \
75 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
82 static const rtti_base_array name ## _rtti_base_array = { \
84 &name ## _rtti_base_descriptor, \
97 static const rtti_object_hierarchy name ## _hierarchy = { \
101 &name ## _rtti_base_array \
104 const rtti_object_locator name ## _rtti = { \
108 &name ## _type_info, \
109 &name ## _hierarchy \
114 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
115 static const type_info name ## _type_info = { \
116 &MSVCRT_type_info_vtable, \
121 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
128 static rtti_base_array name ## _rtti_base_array = { \
143 static rtti_object_hierarchy name ## _hierarchy = { \
150 rtti_object_locator name ## _rtti = { \
159 static void init_ ## name ## _rtti(char *base) \
161 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
162 name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
163 name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
164 name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
165 name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
166 name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
167 name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
168 name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
169 name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
170 name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
171 name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
172 name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
173 name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
174 name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
175 name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
180 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
181 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
182 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
183 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
184 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
185 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
186 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
187 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
188 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
189 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
190 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
191 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
192 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
193 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
197 typedef struct _rtti_base_descriptor
199 const type_info
*type_descriptor
;
200 int num_base_classes
;
201 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
202 unsigned int attributes
;
203 } rtti_base_descriptor
;
205 typedef struct _rtti_base_array
207 const rtti_base_descriptor
*bases
[10]; /* First element is the class itself */
210 typedef struct _rtti_object_hierarchy
212 unsigned int signature
;
213 unsigned int attributes
;
214 int array_len
; /* Size of the array pointed to by 'base_classes' */
215 const rtti_base_array
*base_classes
;
216 } rtti_object_hierarchy
;
218 typedef struct _rtti_object_locator
220 unsigned int signature
;
221 int base_class_offset
;
223 const type_info
*type_descriptor
;
224 const rtti_object_hierarchy
*type_hierarchy
;
225 } rtti_object_locator
;
231 unsigned int type_descriptor
;
232 int num_base_classes
;
233 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
234 unsigned int attributes
;
235 } rtti_base_descriptor
;
239 unsigned int bases
[10]; /* First element is the class itself */
244 unsigned int signature
;
245 unsigned int attributes
;
246 int array_len
; /* Size of the array pointed to by 'base_classes' */
247 unsigned int base_classes
;
248 } rtti_object_hierarchy
;
252 unsigned int signature
;
253 int base_class_offset
;
255 unsigned int type_descriptor
;
256 unsigned int type_hierarchy
;
257 unsigned int object_locator
;
258 } rtti_object_locator
;