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
23 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
25 #define __ASM_VTABLE(name,funcs) \
28 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
29 "\t.globl " __ASM_NAME(#name "_vtable") "\n" \
30 __ASM_NAME(#name "_vtable") ":\n" \
35 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
37 #define __ASM_VTABLE(name,funcs) \
40 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
41 "\t.globl " __ASM_NAME(#name "_vtable") "\n" \
42 __ASM_NAME(#name "_vtable") ":\n" \
49 #define DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
50 static type_info name ## _type_info = { \
56 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
63 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
64 DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
66 static const rtti_base_array name ## _rtti_base_array = { \
68 &name ## _rtti_base_descriptor, \
81 static const rtti_object_hierarchy name ## _hierarchy = { \
85 &name ## _rtti_base_array \
88 const rtti_object_locator name ## _rtti = { \
92 &name ## _type_info, \
96 #define DEFINE_CXX_TYPE_INFO(type) \
97 static const cxx_type_info type ## _cxx_type_info = { \
99 & type ##_type_info, \
102 (cxx_copy_ctor)THISCALL(type ##_copy_ctor) \
105 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, cl3, cl4, dtor) \
106 DEFINE_CXX_TYPE_INFO(type) \
108 static const cxx_type_info_table type ## _cxx_type_table = { \
111 & type ## _cxx_type_info, \
119 static const cxx_exception_type type ## _cxx_type = { \
121 (cxx_copy_ctor)THISCALL(dtor), \
123 & type ## _cxx_type_table \
128 #define __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
129 static type_info name ## _type_info = { \
135 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
142 #define DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
143 __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
145 static void init_ ## name ## _rtti(char *base) \
147 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
150 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
151 __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
153 static rtti_base_array name ## _rtti_base_array = { \
168 static rtti_object_hierarchy name ## _hierarchy = { \
175 rtti_object_locator name ## _rtti = { \
184 static void init_ ## name ## _rtti(char *base) \
186 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
187 name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
188 name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
189 name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
190 name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
191 name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
192 name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
193 name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
194 name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
195 name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
196 name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
197 name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
198 name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
199 name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
200 name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
203 #define DEFINE_CXX_TYPE_INFO(type) \
204 static cxx_type_info type ## _cxx_type_info = { \
212 static void init_ ## type ## _cxx_type_info(char *base) \
214 type ## _cxx_type_info.type_info = (char *)&type ## _type_info - base; \
215 type ## _cxx_type_info.copy_ctor = (char *)type ## _copy_ctor - base; \
218 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, cl3, cl4, dtor) \
220 DEFINE_CXX_TYPE_INFO(type) \
222 static cxx_type_info_table type ## _cxx_type_table = { \
233 static cxx_exception_type type ##_cxx_type = { \
240 static void init_ ## type ## _cxx(char *base) \
242 init_ ## type ## _cxx_type_info(base); \
243 type ## _cxx_type_table.info[0] = (char *)&type ## _cxx_type_info - base; \
244 type ## _cxx_type_table.info[1] = (char *)cl1 - base; \
245 type ## _cxx_type_table.info[2] = (char *)cl2 - base; \
246 type ## _cxx_type_table.info[3] = (char *)cl3 - base; \
247 type ## _cxx_type_table.info[4] = (char *)cl4 - base; \
248 type ## _cxx_type.destructor = (char *)dtor - base; \
249 type ## _cxx_type.type_info_table = (char *)&type ## _cxx_type_table - base; \
254 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
255 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
256 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
257 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
258 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
259 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
260 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
261 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
262 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
263 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
264 #define DEFINE_RTTI_DATA5(name, off, cl1, cl2, cl3, cl4, cl5, mangled_name) \
265 DEFINE_RTTI_DATA(name, off, 5, cl1, cl2, cl3, cl4, cl5, NULL, NULL, NULL, NULL, mangled_name)
266 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
267 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
268 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
269 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
271 #define DEFINE_CXX_DATA0(name, dtor) \
272 DEFINE_CXX_DATA(name, 0, NULL, NULL, NULL, NULL, dtor)
273 #define DEFINE_CXX_DATA1(name, cl1, dtor) \
274 DEFINE_CXX_DATA(name, 1, cl1, NULL, NULL, NULL, dtor)
275 #define DEFINE_CXX_DATA2(name, cl1, cl2, dtor) \
276 DEFINE_CXX_DATA(name, 2, cl1, cl2, NULL, NULL, dtor)
277 #define DEFINE_CXX_DATA3(name, cl1, cl2, cl3, dtor) \
278 DEFINE_CXX_DATA(name, 3, cl1, cl2, cl3, NULL, dtor)
279 #define DEFINE_CXX_DATA4(name, cl1, cl2, cl3, cl4, dtor) \
280 DEFINE_CXX_DATA(name, 4, cl1, cl2, cl3, cl4, dtor)
282 #ifdef __ASM_USE_THISCALL_WRAPPER
284 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
286 extern void *vtbl_wrapper_0
;
287 extern void *vtbl_wrapper_4
;
288 extern void *vtbl_wrapper_8
;
289 extern void *vtbl_wrapper_12
;
290 extern void *vtbl_wrapper_16
;
291 extern void *vtbl_wrapper_20
;
292 extern void *vtbl_wrapper_24
;
293 extern void *vtbl_wrapper_28
;
294 extern void *vtbl_wrapper_32
;
295 extern void *vtbl_wrapper_36
;
296 extern void *vtbl_wrapper_40
;
297 extern void *vtbl_wrapper_44
;
298 extern void *vtbl_wrapper_48
;
299 extern void *vtbl_wrapper_52
;
300 extern void *vtbl_wrapper_56
;
304 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__thiscall***)type)this)[0][off/4]args
308 /* exception object */
309 typedef void (*vtable_ptr
)(void);
310 typedef struct __exception
312 const vtable_ptr
*vtable
;
313 char *name
; /* Name of this exception, always a new copy for each object */
314 int do_free
; /* Whether to free 'name' in our dtor */
318 typedef struct __type_info
320 const vtable_ptr
*vtable
;
321 char *name
; /* Unmangled name, allocated lazily */
322 char mangled
[128]; /* Variable length, but we declare it large enough for static RTTI */
325 extern const vtable_ptr type_info_vtable
;
327 /* offsets for computing the this pointer */
330 int this_offset
; /* offset of base class this pointer from start of object */
331 int vbase_descr
; /* offset of virtual base class descriptor */
332 int vbase_offset
; /* offset of this pointer offset in virtual base class descriptor */
335 /* dlls/msvcrt/cppexcept.h */
336 typedef void (*cxx_copy_ctor
)(void);
340 typedef struct _rtti_base_descriptor
342 const type_info
*type_descriptor
;
343 int num_base_classes
;
344 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
345 unsigned int attributes
;
346 } rtti_base_descriptor
;
348 typedef struct _rtti_base_array
350 const rtti_base_descriptor
*bases
[10]; /* First element is the class itself */
353 typedef struct _rtti_object_hierarchy
355 unsigned int signature
;
356 unsigned int attributes
;
357 int array_len
; /* Size of the array pointed to by 'base_classes' */
358 const rtti_base_array
*base_classes
;
359 } rtti_object_hierarchy
;
361 typedef struct _rtti_object_locator
363 unsigned int signature
;
364 int base_class_offset
;
366 const type_info
*type_descriptor
;
367 const rtti_object_hierarchy
*type_hierarchy
;
368 } rtti_object_locator
;
373 const type_info
*type_info
;
374 this_ptr_offsets offsets
;
376 cxx_copy_ctor copy_ctor
;
382 const cxx_type_info
*info
[5];
383 } cxx_type_info_table
;
388 void (*destructor
)(void);
389 void* /*cxx_exc_custom_handler*/ custom_handler
;
390 const cxx_type_info_table
*type_info_table
;
391 } cxx_exception_type
;
397 unsigned int type_descriptor
;
398 int num_base_classes
;
399 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
400 unsigned int attributes
;
401 } rtti_base_descriptor
;
405 unsigned int bases
[10]; /* First element is the class itself */
410 unsigned int signature
;
411 unsigned int attributes
;
412 int array_len
; /* Size of the array pointed to by 'base_classes' */
413 unsigned int base_classes
;
414 } rtti_object_hierarchy
;
418 unsigned int signature
;
419 int base_class_offset
;
421 unsigned int type_descriptor
;
422 unsigned int type_hierarchy
;
423 unsigned int object_locator
;
424 } rtti_object_locator
;
429 unsigned int type_info
;
430 this_ptr_offsets offsets
;
432 unsigned int copy_ctor
;
438 unsigned int info
[5];
439 } cxx_type_info_table
;
444 unsigned int destructor
;
445 unsigned int custom_handler
;
446 unsigned int type_info_table
;
447 } cxx_exception_type
;
451 #define CREATE_TYPE_INFO_VTABLE \
452 DEFINE_THISCALL_WRAPPER(type_info_vector_dtor,8) \
453 void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags) \
457 /* we have an array, with the number of elements stored before the first object */ \
458 INT_PTR i, *ptr = (INT_PTR *)_this - 1; \
460 for (i = *ptr - 1; i >= 0; i--) free(_this[i].name); \
466 if (flags & 1) free(_this); \
471 DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" ) \
473 __ASM_BLOCK_BEGIN(type_info_vtables) \
474 __ASM_VTABLE(type_info, \
475 VTABLE_ADD_FUNC(type_info_vector_dtor)); \