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 /* Copied from dlls/msvcrt/cxx.h */
21 #ifdef __i386__ /* thiscall functions are i386-specific */
23 #define THISCALL(func) __thiscall_ ## func
24 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
25 #define __thiscall __stdcall
26 #define DEFINE_THISCALL_WRAPPER(func,args) \
27 extern void THISCALL(func)(void); \
28 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
32 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
35 #define THISCALL(func) func
36 #define THISCALL_NAME(func) __ASM_NAME(#func)
37 #define __thiscall __cdecl
38 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
44 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
46 #define __ASM_VTABLE(name,funcs) \
49 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
50 "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
51 __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
56 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
58 #define __ASM_VTABLE(name,funcs) \
61 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
62 "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
63 __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
70 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
71 static const type_info name ## _type_info = { \
72 &MSVCP_type_info_vtable, \
77 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
84 static const rtti_base_array name ## _rtti_base_array = { \
86 &name ## _rtti_base_descriptor, \
99 static const rtti_object_hierarchy name ## _hierarchy = { \
103 &name ## _rtti_base_array \
106 const rtti_object_locator name ## _rtti = { \
110 &name ## _type_info, \
111 &name ## _hierarchy \
114 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, dtor) \
116 static const cxx_type_info type ## _cxx_type_info = { \
118 & type ##_type_info, \
121 (cxx_copy_ctor)THISCALL(MSVCP_ ## type ##_copy_ctor) \
124 static const cxx_type_info_table type ## _cxx_type_table = { \
127 & type ## _cxx_type_info, \
133 static const cxx_exception_type type ## _cxx_type = { \
135 (cxx_copy_ctor)THISCALL(dtor), \
137 & type ## _cxx_type_table \
142 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
143 static const type_info name ## _type_info = { \
144 &MSVCP_type_info_vtable, \
149 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
156 static rtti_base_array name ## _rtti_base_array = { \
171 static rtti_object_hierarchy name ## _hierarchy = { \
178 rtti_object_locator name ## _rtti = { \
187 static void init_ ## name ## _rtti(char *base) \
189 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
190 name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
191 name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
192 name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
193 name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
194 name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
195 name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
196 name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
197 name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
198 name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
199 name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
200 name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
201 name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
202 name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
203 name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
206 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, dtor) \
208 static cxx_type_info type ## _cxx_type_info = { \
216 static cxx_type_info_table type ## _cxx_type_table = { \
225 static cxx_exception_type type ##_cxx_type = { \
232 static void init_ ## type ## _cxx(char *base) \
234 type ## _cxx_type_info.type_info = (char *)&type ## _type_info - base; \
235 type ## _cxx_type_info.copy_ctor = (char *)MSVCP_ ## type ## _copy_ctor - base; \
236 type ## _cxx_type_table.info[0] = (char *)&type ## _cxx_type_info - base; \
237 type ## _cxx_type_table.info[1] = (char *)cl1 - base; \
238 type ## _cxx_type_table.info[2] = (char *)cl2 - base; \
239 type ## _cxx_type.destructor = (char *)dtor - base; \
240 type ## _cxx_type.type_info_table = (char *)&type ## _cxx_type_table - base; \
245 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
246 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
247 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
248 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
249 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
250 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
251 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
252 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
253 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
254 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
255 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
256 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
257 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
258 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
260 #define DEFINE_CXX_DATA0(name, dtor) \
261 DEFINE_CXX_DATA(name, 0, NULL, NULL, dtor)
262 #define DEFINE_CXX_DATA1(name, cl1, dtor) \
263 DEFINE_CXX_DATA(name, 1, cl1, NULL, dtor)
264 #define DEFINE_CXX_DATA2(name, cl1, cl2, dtor) \
265 DEFINE_CXX_DATA(name, 2, cl1, cl2, dtor)
269 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
271 extern void *vtbl_wrapper_0
;
272 extern void *vtbl_wrapper_4
;
273 extern void *vtbl_wrapper_8
;
274 extern void *vtbl_wrapper_12
;
275 extern void *vtbl_wrapper_16
;
276 extern void *vtbl_wrapper_20
;
277 extern void *vtbl_wrapper_24
;
278 extern void *vtbl_wrapper_28
;
279 extern void *vtbl_wrapper_32
;
280 extern void *vtbl_wrapper_36
;
281 extern void *vtbl_wrapper_40
;
282 extern void *vtbl_wrapper_44
;
283 extern void *vtbl_wrapper_48
;
284 extern void *vtbl_wrapper_52
;
285 extern void *vtbl_wrapper_56
;
289 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__cdecl***)type)this)[0][off/4]args
293 /* exception object */
294 typedef void (*vtable_ptr
)(void);
295 typedef struct __exception
297 const vtable_ptr
*vtable
;
298 char *name
; /* Name of this exception, always a new copy for each object */
299 int do_free
; /* Whether to free 'name' in our dtor */
302 /* Internal: throws selected exception */
303 typedef enum __exception_type
{
308 EXCEPTION_LOGIC_ERROR
,
309 EXCEPTION_LENGTH_ERROR
,
310 EXCEPTION_OUT_OF_RANGE
,
311 EXCEPTION_INVALID_ARGUMENT
,
312 EXCEPTION_RUNTIME_ERROR
,
315 void throw_exception(exception_type
, const char *);
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 MSVCP_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
[3];
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
[3];
439 } cxx_type_info_table
;
444 unsigned int destructor
;
445 unsigned int custom_handler
;
446 unsigned int type_info_table
;
447 } cxx_exception_type
;