makefiles: Explicitly create destination dirs when installing symlinks.
[wine/zf.git] / dlls / msvcp90 / cxx.h
blob02735a3c16855539db573ba9d65ec047006e1775
1 /*
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 "wine/asm.h"
21 #ifdef _WIN64
23 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
25 #define __ASM_VTABLE(name,funcs) \
26 __asm__(".data\n" \
27 "\t.balign 8\n" \
28 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
29 "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
30 __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
31 funcs "\n\t.text")
33 #else
35 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
37 #define __ASM_VTABLE(name,funcs) \
38 __asm__(".data\n" \
39 "\t.balign 4\n" \
40 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
41 "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
42 __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
43 funcs "\n\t.text")
45 #endif /* _WIN64 */
47 #ifndef __x86_64__
49 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
50 static type_info name ## _type_info = { \
51 &MSVCP_type_info_vtable, \
52 NULL, \
53 mangled_name \
54 }; \
56 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
57 &name ##_type_info, \
58 base_classes_no, \
59 { 0, -1, 0}, \
60 64 \
61 }; \
63 static const rtti_base_array name ## _rtti_base_array = { \
64 { \
65 &name ## _rtti_base_descriptor, \
66 cl1, \
67 cl2, \
68 cl3, \
69 cl4, \
70 cl5, \
71 cl6, \
72 cl7, \
73 cl8, \
74 cl9, \
75 } \
76 }; \
78 static const rtti_object_hierarchy name ## _hierarchy = { \
79 0, \
80 0, \
81 base_classes_no+1, \
82 &name ## _rtti_base_array \
83 }; \
85 const rtti_object_locator name ## _rtti = { \
86 0, \
87 off, \
88 0, \
89 &name ## _type_info, \
90 &name ## _hierarchy \
93 #define DEFINE_CXX_TYPE_INFO(type) \
94 static const cxx_type_info type ## _cxx_type_info = { \
95 0, \
96 & type ##_type_info, \
97 { 0, -1, 0 }, \
98 sizeof(type), \
99 (cxx_copy_ctor)THISCALL(MSVCP_ ## type ##_copy_ctor) \
102 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, cl3, cl4, dtor) \
103 DEFINE_CXX_TYPE_INFO(type) \
105 static const cxx_type_info_table type ## _cxx_type_table = { \
106 base_no+1, \
108 & type ## _cxx_type_info, \
109 cl1, \
110 cl2, \
111 cl3, \
112 cl4 \
114 }; \
116 static const cxx_exception_type type ## _cxx_type = { \
117 0, \
118 (cxx_copy_ctor)THISCALL(dtor), \
119 NULL, \
120 & type ## _cxx_type_table \
123 #else
125 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
126 static type_info name ## _type_info = { \
127 &MSVCP_type_info_vtable, \
128 NULL, \
129 mangled_name \
130 }; \
132 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
133 0xdeadbeef, \
134 base_classes_no, \
135 { 0, -1, 0}, \
136 64 \
137 }; \
139 static rtti_base_array name ## _rtti_base_array = { \
141 0xdeadbeef, \
142 0xdeadbeef, \
143 0xdeadbeef, \
144 0xdeadbeef, \
145 0xdeadbeef, \
146 0xdeadbeef, \
147 0xdeadbeef, \
148 0xdeadbeef, \
149 0xdeadbeef, \
150 0xdeadbeef, \
152 }; \
154 static rtti_object_hierarchy name ## _hierarchy = { \
155 0, \
156 0, \
157 base_classes_no+1, \
158 0xdeadbeef \
159 }; \
161 rtti_object_locator name ## _rtti = { \
162 1, \
163 off, \
164 0, \
165 0xdeadbeef, \
166 0xdeadbeef, \
167 0xdeadbeef \
170 static void init_ ## name ## _rtti(char *base) \
172 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
173 name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
174 name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
175 name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
176 name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
177 name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
178 name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
179 name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
180 name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
181 name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
182 name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
183 name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
184 name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
185 name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
186 name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
189 #define DEFINE_CXX_TYPE_INFO(type) \
190 static cxx_type_info type ## _cxx_type_info = { \
191 0, \
192 0xdeadbeef, \
193 { 0, -1, 0 }, \
194 sizeof(type), \
195 0xdeadbeef \
196 }; \
198 static void init_ ## type ## _cxx_type_info(char *base) \
200 type ## _cxx_type_info.type_info = (char *)&type ## _type_info - base; \
201 type ## _cxx_type_info.copy_ctor = (char *)MSVCP_ ## type ## _copy_ctor - base; \
204 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, cl3, cl4, dtor) \
206 DEFINE_CXX_TYPE_INFO(type) \
208 static cxx_type_info_table type ## _cxx_type_table = { \
209 base_no+1, \
211 0xdeadbeef, \
212 0xdeadbeef, \
213 0xdeadbeef, \
214 0xdeadbeef, \
215 0xdeadbeef \
217 }; \
219 static cxx_exception_type type ##_cxx_type = { \
220 0, \
221 0xdeadbeef, \
222 0, \
223 0xdeadbeef \
224 }; \
226 static void init_ ## type ## _cxx(char *base) \
228 init_ ## type ## _cxx_type_info(base); \
229 type ## _cxx_type_table.info[0] = (char *)&type ## _cxx_type_info - base; \
230 type ## _cxx_type_table.info[1] = (char *)cl1 - base; \
231 type ## _cxx_type_table.info[2] = (char *)cl2 - base; \
232 type ## _cxx_type_table.info[3] = (char *)cl3 - base; \
233 type ## _cxx_type_table.info[4] = (char *)cl4 - base; \
234 type ## _cxx_type.destructor = (char *)dtor - base; \
235 type ## _cxx_type.type_info_table = (char *)&type ## _cxx_type_table - base; \
238 #endif
240 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
241 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
242 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
243 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
244 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
245 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
246 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
247 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
248 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
249 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
250 #define DEFINE_RTTI_DATA5(name, off, cl1, cl2, cl3, cl4, cl5, mangled_name) \
251 DEFINE_RTTI_DATA(name, off, 5, cl1, cl2, cl3, cl4, cl5, NULL, NULL, NULL, NULL, mangled_name)
252 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
253 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
254 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
255 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
257 #define DEFINE_CXX_DATA0(name, dtor) \
258 DEFINE_CXX_DATA(name, 0, NULL, NULL, NULL, NULL, dtor)
259 #define DEFINE_CXX_DATA1(name, cl1, dtor) \
260 DEFINE_CXX_DATA(name, 1, cl1, NULL, NULL, NULL, dtor)
261 #define DEFINE_CXX_DATA2(name, cl1, cl2, dtor) \
262 DEFINE_CXX_DATA(name, 2, cl1, cl2, NULL, NULL, dtor)
263 #define DEFINE_CXX_DATA3(name, cl1, cl2, cl3, dtor) \
264 DEFINE_CXX_DATA(name, 3, cl1, cl2, cl3, NULL, dtor)
265 #define DEFINE_CXX_DATA4(name, cl1, cl2, cl3, cl4, dtor) \
266 DEFINE_CXX_DATA(name, 4, cl1, cl2, cl3, cl4, dtor)
268 #ifdef __ASM_USE_THISCALL_WRAPPER
270 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
272 extern void *vtbl_wrapper_0;
273 extern void *vtbl_wrapper_4;
274 extern void *vtbl_wrapper_8;
275 extern void *vtbl_wrapper_12;
276 extern void *vtbl_wrapper_16;
277 extern void *vtbl_wrapper_20;
278 extern void *vtbl_wrapper_24;
279 extern void *vtbl_wrapper_28;
280 extern void *vtbl_wrapper_32;
281 extern void *vtbl_wrapper_36;
282 extern void *vtbl_wrapper_40;
283 extern void *vtbl_wrapper_44;
284 extern void *vtbl_wrapper_48;
285 extern void *vtbl_wrapper_52;
286 extern void *vtbl_wrapper_56;
288 #else
290 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__thiscall***)type)this)[0][off/4]args
292 #endif
294 /* exception object */
295 typedef void (*vtable_ptr)(void);
296 typedef struct __exception
298 const vtable_ptr *vtable;
299 char *name; /* Name of this exception, always a new copy for each object */
300 int do_free; /* Whether to free 'name' in our dtor */
301 } exception;
303 /* Internal: throws selected exception */
304 typedef enum __exception_type {
305 EXCEPTION_RERAISE,
306 EXCEPTION,
307 EXCEPTION_BAD_ALLOC,
308 EXCEPTION_BAD_CAST,
309 EXCEPTION_LOGIC_ERROR,
310 EXCEPTION_LENGTH_ERROR,
311 EXCEPTION_OUT_OF_RANGE,
312 EXCEPTION_INVALID_ARGUMENT,
313 EXCEPTION_RUNTIME_ERROR,
314 EXCEPTION_FAILURE,
315 EXCEPTION_RANGE_ERROR,
316 } exception_type;
317 void throw_exception(exception_type, const char *);
319 /* rtti */
320 typedef struct __type_info
322 const vtable_ptr *vtable;
323 char *name; /* Unmangled name, allocated lazily */
324 char mangled[128]; /* Variable length, but we declare it large enough for static RTTI */
325 } type_info;
327 extern const vtable_ptr MSVCP_type_info_vtable;
329 /* offsets for computing the this pointer */
330 typedef struct
332 int this_offset; /* offset of base class this pointer from start of object */
333 int vbase_descr; /* offset of virtual base class descriptor */
334 int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
335 } this_ptr_offsets;
337 /* dlls/msvcrt/cppexcept.h */
338 typedef void (*cxx_copy_ctor)(void);
340 #ifndef __x86_64__
342 typedef struct _rtti_base_descriptor
344 const type_info *type_descriptor;
345 int num_base_classes;
346 this_ptr_offsets offsets; /* offsets for computing the this pointer */
347 unsigned int attributes;
348 } rtti_base_descriptor;
350 typedef struct _rtti_base_array
352 const rtti_base_descriptor *bases[10]; /* First element is the class itself */
353 } rtti_base_array;
355 typedef struct _rtti_object_hierarchy
357 unsigned int signature;
358 unsigned int attributes;
359 int array_len; /* Size of the array pointed to by 'base_classes' */
360 const rtti_base_array *base_classes;
361 } rtti_object_hierarchy;
363 typedef struct _rtti_object_locator
365 unsigned int signature;
366 int base_class_offset;
367 unsigned int flags;
368 const type_info *type_descriptor;
369 const rtti_object_hierarchy *type_hierarchy;
370 } rtti_object_locator;
372 typedef struct
374 UINT flags;
375 const type_info *type_info;
376 this_ptr_offsets offsets;
377 unsigned int size;
378 cxx_copy_ctor copy_ctor;
379 } cxx_type_info;
381 typedef struct
383 UINT count;
384 const cxx_type_info *info[5];
385 } cxx_type_info_table;
387 typedef struct
389 UINT flags;
390 void (*destructor)(void);
391 void* /*cxx_exc_custom_handler*/ custom_handler;
392 const cxx_type_info_table *type_info_table;
393 } cxx_exception_type;
395 #else
397 typedef struct
399 unsigned int type_descriptor;
400 int num_base_classes;
401 this_ptr_offsets offsets; /* offsets for computing the this pointer */
402 unsigned int attributes;
403 } rtti_base_descriptor;
405 typedef struct
407 unsigned int bases[10]; /* First element is the class itself */
408 } rtti_base_array;
410 typedef struct
412 unsigned int signature;
413 unsigned int attributes;
414 int array_len; /* Size of the array pointed to by 'base_classes' */
415 unsigned int base_classes;
416 } rtti_object_hierarchy;
418 typedef struct
420 unsigned int signature;
421 int base_class_offset;
422 unsigned int flags;
423 unsigned int type_descriptor;
424 unsigned int type_hierarchy;
425 unsigned int object_locator;
426 } rtti_object_locator;
428 typedef struct
430 UINT flags;
431 unsigned int type_info;
432 this_ptr_offsets offsets;
433 unsigned int size;
434 unsigned int copy_ctor;
435 } cxx_type_info;
437 typedef struct
439 UINT count;
440 unsigned int info[5];
441 } cxx_type_info_table;
443 typedef struct
445 UINT flags;
446 unsigned int destructor;
447 unsigned int custom_handler;
448 unsigned int type_info_table;
449 } cxx_exception_type;
451 #endif