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 #include "cppexcept.h"
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, \
98 #define __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
99 static type_info name ## _type_info = { \
105 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
112 #define DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
113 __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
115 static void init_ ## name ## _rtti(char *base) \
117 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
120 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
121 __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
123 static rtti_base_array name ## _rtti_base_array = { \
138 static rtti_object_hierarchy name ## _hierarchy = { \
145 rtti_object_locator name ## _rtti = { \
154 static void init_ ## name ## _rtti(char *base) \
156 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
157 name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
158 name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
159 name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
160 name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
161 name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
162 name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
163 name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
164 name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
165 name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
166 name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
167 name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
168 name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
169 name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
170 name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
175 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
176 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
177 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
178 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
179 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
180 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
181 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
182 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
183 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
184 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
185 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
186 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
187 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
188 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
192 typedef struct _rtti_base_descriptor
194 const type_info
*type_descriptor
;
195 int num_base_classes
;
196 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
197 unsigned int attributes
;
198 } rtti_base_descriptor
;
200 typedef struct _rtti_base_array
202 const rtti_base_descriptor
*bases
[10]; /* First element is the class itself */
205 typedef struct _rtti_object_hierarchy
207 unsigned int signature
;
208 unsigned int attributes
;
209 int array_len
; /* Size of the array pointed to by 'base_classes' */
210 const rtti_base_array
*base_classes
;
211 } rtti_object_hierarchy
;
213 typedef struct _rtti_object_locator
215 unsigned int signature
;
216 int base_class_offset
;
218 const type_info
*type_descriptor
;
219 const rtti_object_hierarchy
*type_hierarchy
;
220 } rtti_object_locator
;
226 unsigned int type_descriptor
;
227 int num_base_classes
;
228 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
229 unsigned int attributes
;
230 } rtti_base_descriptor
;
234 unsigned int bases
[10]; /* First element is the class itself */
239 unsigned int signature
;
240 unsigned int attributes
;
241 int array_len
; /* Size of the array pointed to by 'base_classes' */
242 unsigned int base_classes
;
243 } rtti_object_hierarchy
;
247 unsigned int signature
;
248 int base_class_offset
;
250 unsigned int type_descriptor
;
251 unsigned int type_hierarchy
;
252 unsigned int object_locator
;
253 } rtti_object_locator
;
257 #ifdef __ASM_USE_THISCALL_WRAPPER
259 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
261 extern void *vtbl_wrapper_0
;
262 extern void *vtbl_wrapper_4
;
263 extern void *vtbl_wrapper_8
;
264 extern void *vtbl_wrapper_12
;
265 extern void *vtbl_wrapper_16
;
266 extern void *vtbl_wrapper_20
;
267 extern void *vtbl_wrapper_24
;
268 extern void *vtbl_wrapper_28
;
269 extern void *vtbl_wrapper_32
;
270 extern void *vtbl_wrapper_36
;
271 extern void *vtbl_wrapper_40
;
272 extern void *vtbl_wrapper_44
;
273 extern void *vtbl_wrapper_48
;
277 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__thiscall***)type)this)[0][off/4]args
281 exception
* __thiscall
exception_ctor(exception
*, const char**);
283 extern const vtable_ptr type_info_vtable
;
285 #define CREATE_TYPE_INFO_VTABLE \
286 DEFINE_THISCALL_WRAPPER(type_info_vector_dtor,8) \
287 void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags) \
291 /* we have an array, with the number of elements stored before the first object */ \
292 INT_PTR i, *ptr = (INT_PTR *)_this - 1; \
294 for (i = *ptr - 1; i >= 0; i--) free(_this[i].name); \
300 if (flags & 1) free(_this); \
305 DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" ) \
307 __ASM_BLOCK_BEGIN(type_info_vtables) \
308 __ASM_VTABLE(type_info, \
309 VTABLE_ADD_FUNC(type_info_vector_dtor)); \