msvcp71: Remove an unused VTBL wrapper.
[wine] / dlls / msvcp71 / cxx.h
1 /*
2  * Copyright 2012 Piotr Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 /* Copied from dlls/msvcrt/cpp.c */
20 #ifdef __i386__  /* thiscall functions are i386-specific */
21
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, \
28                       "popl %eax\n\t" \
29                       "pushl %ecx\n\t" \
30                       "pushl %eax\n\t" \
31                       "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
32 #else /* __i386__ */
33
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 */
38
39 #endif /* __i386__ */
40
41 #ifdef _WIN64
42
43 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
44
45 #define __ASM_VTABLE(name,funcs) \
46     __asm__(".data\n" \
47             "\t.align 8\n" \
48             "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
49             "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
50             __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
51             funcs "\n\t.text")
52
53 #else
54
55 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
56
57 #define __ASM_VTABLE(name,funcs) \
58     __asm__(".data\n" \
59             "\t.align 4\n" \
60             "\t.long " __ASM_NAME(#name "_rtti") "\n" \
61             "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
62             __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
63             funcs "\n\t.text")
64
65 #endif /* _WIN64 */
66
67 #ifndef __x86_64__
68
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         &MSVCP_type_info_vtable, \
72         NULL, \
73         mangled_name \
74     }; \
75 \
76 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
77     &name ##_type_info, \
78     base_classes_no, \
79     { 0, -1, 0}, \
80     64 \
81 }; \
82 \
83 static const rtti_base_array name ## _rtti_base_array = { \
84     { \
85         &name ## _rtti_base_descriptor, \
86         cl1, \
87         cl2, \
88         cl3, \
89         cl4, \
90         cl5, \
91         cl6, \
92         cl7, \
93         cl8, \
94         cl9, \
95     } \
96 }; \
97 \
98 static const rtti_object_hierarchy name ## _hierarchy = { \
99     0, \
100     0, \
101     base_classes_no+1, \
102     &name ## _rtti_base_array \
103 }; \
104 \
105 const rtti_object_locator name ## _rtti = { \
106     0, \
107     off, \
108     0, \
109     &name ## _type_info, \
110     &name ## _hierarchy \
111 }
112
113 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, dtor)  \
114 \
115 static const cxx_type_info type ## _cxx_type_info = { \
116     0, \
117     & type ##_type_info, \
118     { 0, -1, 0 }, \
119     sizeof(type), \
120     (cxx_copy_ctor)THISCALL(MSVCP_ ## type ##_copy_ctor) \
121 }; \
122 \
123 static const cxx_type_info_table type ## _cxx_type_table = { \
124     base_no+1, \
125     { \
126         & type ## _cxx_type_info, \
127         cl1, \
128         cl2 \
129     } \
130 }; \
131 \
132 static const cxx_exception_type type ## _cxx_type = { \
133     0, \
134     (cxx_copy_ctor)THISCALL(dtor), \
135     NULL, \
136     & type ## _cxx_type_table \
137 };
138
139 #else
140
141 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
142     static const type_info name ## _type_info = { \
143         &MSVCP_type_info_vtable, \
144         NULL, \
145         mangled_name \
146     }; \
147 \
148 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
149     0xdeadbeef, \
150     base_classes_no, \
151     { 0, -1, 0}, \
152     64 \
153 }; \
154 \
155 static rtti_base_array name ## _rtti_base_array = { \
156     { \
157         0xdeadbeef, \
158         0xdeadbeef, \
159         0xdeadbeef, \
160         0xdeadbeef, \
161         0xdeadbeef, \
162         0xdeadbeef, \
163         0xdeadbeef, \
164         0xdeadbeef, \
165         0xdeadbeef, \
166         0xdeadbeef, \
167     } \
168 }; \
169 \
170 static rtti_object_hierarchy name ## _hierarchy = { \
171     0, \
172     0, \
173     base_classes_no+1, \
174     0xdeadbeef \
175 }; \
176 \
177 rtti_object_locator name ## _rtti = { \
178     1, \
179     off, \
180     0, \
181     0xdeadbeef, \
182     0xdeadbeef, \
183     0xdeadbeef \
184 };\
185 \
186 static void init_ ## name ## _rtti(char *base) \
187 { \
188     name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
189     name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
190     name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
191     name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
192     name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
193     name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
194     name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
195     name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
196     name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
197     name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
198     name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
199     name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
200     name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
201     name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
202     name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
203 }
204
205 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, dtor)  \
206 \
207 static cxx_type_info type ## _cxx_type_info = { \
208     0, \
209     0xdeadbeef, \
210     { 0, -1, 0 }, \
211     sizeof(type), \
212     0xdeadbeef \
213 }; \
214 \
215 static cxx_type_info_table type ## _cxx_type_table = { \
216     base_no+1, \
217     { \
218         0xdeadbeef, \
219         0xdeadbeef, \
220         0xdeadbeef  \
221     } \
222 }; \
223 \
224 static cxx_exception_type type ##_cxx_type = { \
225     0, \
226     0xdeadbeef, \
227     0, \
228     0xdeadbeef \
229 }; \
230 \
231 static void init_ ## type ## _cxx(char *base) \
232 { \
233     type ## _cxx_type_info.type_info  = (char *)&type ## _type_info - base; \
234     type ## _cxx_type_info.copy_ctor  = (char *)MSVCP_ ## type ## _copy_ctor - base; \
235     type ## _cxx_type_table.info[0]   = (char *)&type ## _cxx_type_info - base; \
236     type ## _cxx_type_table.info[1]   = (char *)cl1 - base; \
237     type ## _cxx_type_table.info[2]   = (char *)cl2 - base; \
238     type ## _cxx_type.destructor      = (char *)dtor - base; \
239     type ## _cxx_type.type_info_table = (char *)&type ## _cxx_type_table - base; \
240 }
241
242 #endif
243
244 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
245     DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
246 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
247     DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
248 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
249     DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
250 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
251     DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
252 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
253     DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
254 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
255     DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
256 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
257     DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
258
259 #define DEFINE_CXX_DATA0(name, dtor) \
260     DEFINE_CXX_DATA(name, 0, NULL, NULL, dtor)
261 #define DEFINE_CXX_DATA1(name, cl1, dtor) \
262     DEFINE_CXX_DATA(name, 1, cl1, NULL, dtor)
263 #define DEFINE_CXX_DATA2(name, cl1, cl2, dtor) \
264     DEFINE_CXX_DATA(name, 2, cl1, cl2, dtor)
265
266 #ifdef __i386__
267
268 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
269
270 extern void *vtbl_wrapper_0;
271 extern void *vtbl_wrapper_4;
272 extern void *vtbl_wrapper_8;
273 extern void *vtbl_wrapper_12;
274 extern void *vtbl_wrapper_16;
275 extern void *vtbl_wrapper_20;
276 extern void *vtbl_wrapper_24;
277 extern void *vtbl_wrapper_28;
278 extern void *vtbl_wrapper_32;
279 extern void *vtbl_wrapper_36;
280 extern void *vtbl_wrapper_40;
281 extern void *vtbl_wrapper_44;
282 extern void *vtbl_wrapper_48;
283 extern void *vtbl_wrapper_52;
284
285 #else
286
287 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__cdecl***)type)this)[0][off/4]args
288
289 #endif
290
291 /* exception object */
292 typedef void (*vtable_ptr)(void);
293 typedef struct __exception
294 {
295     const vtable_ptr *vtable;
296     char             *name;    /* Name of this exception, always a new copy for each object */
297     int               do_free; /* Whether to free 'name' in our dtor */
298 } exception;
299
300 /* Internal: throws selected exception */
301 typedef enum __exception_type {
302     EXCEPTION_RERAISE,
303     EXCEPTION,
304     EXCEPTION_BAD_ALLOC,
305     EXCEPTION_LOGIC_ERROR,
306     EXCEPTION_LENGTH_ERROR,
307     EXCEPTION_OUT_OF_RANGE,
308     EXCEPTION_INVALID_ARGUMENT,
309     EXCEPTION_RUNTIME_ERROR,
310     EXCEPTION_FAILURE,
311 } exception_type;
312 void throw_exception(exception_type, const char *);
313
314 /* rtti */
315 typedef struct __type_info
316 {
317     const vtable_ptr *vtable;
318     char              *name;         /* Unmangled name, allocated lazily */
319     char               mangled[128]; /* Variable length, but we declare it large enough for static RTTI */
320 } type_info;
321
322 extern const vtable_ptr MSVCP_type_info_vtable;
323
324 /* offsets for computing the this pointer */
325 typedef struct
326 {
327     int         this_offset;   /* offset of base class this pointer from start of object */
328     int         vbase_descr;   /* offset of virtual base class descriptor */
329     int         vbase_offset;  /* offset of this pointer offset in virtual base class descriptor */
330 } this_ptr_offsets;
331
332 /* dlls/msvcrt/cppexcept.h */
333 typedef void (*cxx_copy_ctor)(void);
334
335 #ifndef __x86_64__
336
337 typedef struct _rtti_base_descriptor
338 {
339     const type_info *type_descriptor;
340     int num_base_classes;
341     this_ptr_offsets offsets;    /* offsets for computing the this pointer */
342     unsigned int attributes;
343 } rtti_base_descriptor;
344
345 typedef struct _rtti_base_array
346 {
347     const rtti_base_descriptor *bases[10]; /* First element is the class itself */
348 } rtti_base_array;
349
350 typedef struct _rtti_object_hierarchy
351 {
352     unsigned int signature;
353     unsigned int attributes;
354     int array_len; /* Size of the array pointed to by 'base_classes' */
355     const rtti_base_array *base_classes;
356 } rtti_object_hierarchy;
357
358 typedef struct _rtti_object_locator
359 {
360     unsigned int signature;
361     int base_class_offset;
362     unsigned int flags;
363     const type_info *type_descriptor;
364     const rtti_object_hierarchy *type_hierarchy;
365 } rtti_object_locator;
366
367 typedef struct
368 {
369     UINT flags;
370     const type_info *type_info;
371     this_ptr_offsets offsets;
372     unsigned int size;
373     cxx_copy_ctor copy_ctor;
374 } cxx_type_info;
375
376 typedef struct
377 {
378     UINT count;
379     const cxx_type_info *info[3];
380 } cxx_type_info_table;
381
382 typedef struct
383 {
384     UINT flags;
385     void (*destructor)(void);
386     void* /*cxx_exc_custom_handler*/ custom_handler;
387     const cxx_type_info_table *type_info_table;
388 } cxx_exception_type;
389
390 #else
391
392 typedef struct
393 {
394     unsigned int type_descriptor;
395     int num_base_classes;
396     this_ptr_offsets offsets;    /* offsets for computing the this pointer */
397     unsigned int attributes;
398 } rtti_base_descriptor;
399
400 typedef struct
401 {
402     unsigned int bases[10]; /* First element is the class itself */
403 } rtti_base_array;
404
405 typedef struct
406 {
407     unsigned int signature;
408     unsigned int attributes;
409     int array_len; /* Size of the array pointed to by 'base_classes' */
410     unsigned int base_classes;
411 } rtti_object_hierarchy;
412
413 typedef struct
414 {
415     unsigned int signature;
416     int base_class_offset;
417     unsigned int flags;
418     unsigned int type_descriptor;
419     unsigned int type_hierarchy;
420     unsigned int object_locator;
421 } rtti_object_locator;
422
423 typedef struct
424 {
425     UINT flags;
426     unsigned int type_info;
427     this_ptr_offsets offsets;
428     unsigned int size;
429     unsigned int copy_ctor;
430 } cxx_type_info;
431
432 typedef struct
433 {
434     UINT count;
435     unsigned int info[3];
436 } cxx_type_info_table;
437
438 typedef struct
439 {
440     UINT flags;
441     unsigned int destructor;
442     unsigned int custom_handler;
443     unsigned int type_info_table;
444 } cxx_exception_type;
445
446 #endif