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
20 #ifdef __i386__ /* thiscall functions are i386-specific */
22 #define THISCALL(func) __thiscall_ ## func
23 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
24 #define __thiscall __stdcall
25 #define DEFINE_THISCALL_WRAPPER(func,args) \
26 extern void THISCALL(func)(void); \
27 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
31 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
34 #define THISCALL(func) func
35 #define THISCALL_NAME(func) __ASM_NAME(#func)
36 #define __thiscall __cdecl
37 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
43 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
45 #define __ASM_VTABLE(name,funcs) \
48 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
49 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
50 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
55 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
57 #define __ASM_VTABLE(name,funcs) \
60 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
61 "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
62 __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
69 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
70 static const type_info name ## _type_info = { \
71 &MSVCRT_type_info_vtable, \
76 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
83 static const rtti_base_array name ## _rtti_base_array = { \
85 &name ## _rtti_base_descriptor, \
98 static const rtti_object_hierarchy name ## _hierarchy = { \
102 &name ## _rtti_base_array \
105 const rtti_object_locator name ## _rtti = { \
109 &name ## _type_info, \
110 &name ## _hierarchy \
115 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
116 static const type_info name ## _type_info = { \
117 &MSVCRT_type_info_vtable, \
122 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
129 static rtti_base_array name ## _rtti_base_array = { \
144 static rtti_object_hierarchy name ## _hierarchy = { \
151 rtti_object_locator name ## _rtti = { \
160 static void init_ ## name ## _rtti(char *base) \
162 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
163 name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
164 name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
165 name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
166 name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
167 name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
168 name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
169 name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
170 name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
171 name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
172 name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
173 name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
174 name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
175 name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
176 name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
181 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
182 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
183 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
184 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
185 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
186 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
187 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
188 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
189 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
190 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
191 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
192 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
193 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
194 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
198 typedef struct _rtti_base_descriptor
200 const type_info
*type_descriptor
;
201 int num_base_classes
;
202 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
203 unsigned int attributes
;
204 } rtti_base_descriptor
;
206 typedef struct _rtti_base_array
208 const rtti_base_descriptor
*bases
[10]; /* First element is the class itself */
211 typedef struct _rtti_object_hierarchy
213 unsigned int signature
;
214 unsigned int attributes
;
215 int array_len
; /* Size of the array pointed to by 'base_classes' */
216 const rtti_base_array
*base_classes
;
217 } rtti_object_hierarchy
;
219 typedef struct _rtti_object_locator
221 unsigned int signature
;
222 int base_class_offset
;
224 const type_info
*type_descriptor
;
225 const rtti_object_hierarchy
*type_hierarchy
;
226 } rtti_object_locator
;
232 unsigned int type_descriptor
;
233 int num_base_classes
;
234 this_ptr_offsets offsets
; /* offsets for computing the this pointer */
235 unsigned int attributes
;
236 } rtti_base_descriptor
;
240 unsigned int bases
[10]; /* First element is the class itself */
245 unsigned int signature
;
246 unsigned int attributes
;
247 int array_len
; /* Size of the array pointed to by 'base_classes' */
248 unsigned int base_classes
;
249 } rtti_object_hierarchy
;
253 unsigned int signature
;
254 int base_class_offset
;
256 unsigned int type_descriptor
;
257 unsigned int type_hierarchy
;
258 unsigned int object_locator
;
259 } rtti_object_locator
;