d3d9/tests: Accept AMD GPU sysmem sample failure in test_mipmap_upload.
[wine.git] / dlls / msvcp90 / cxx.h
blob701ab02fc05b7a5a34b8e27df75eeb0dd2866df3
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(#name "_vtable") "\n" \
30 __ASM_NAME(#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(#name "_vtable") "\n" \
42 __ASM_NAME(#name "_vtable") ":\n" \
43 funcs "\n\t.text")
45 #endif /* _WIN64 */
47 #ifndef __x86_64__
49 #define DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
50 static type_info name ## _type_info = { \
51 &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 \
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 = { \
67 { \
68 &name ## _rtti_base_descriptor, \
69 cl1, \
70 cl2, \
71 cl3, \
72 cl4, \
73 cl5, \
74 cl6, \
75 cl7, \
76 cl8, \
77 cl9, \
78 } \
79 }; \
81 static const rtti_object_hierarchy name ## _hierarchy = { \
82 0, \
83 0, \
84 base_classes_no+1, \
85 &name ## _rtti_base_array \
86 }; \
88 const rtti_object_locator name ## _rtti = { \
89 0, \
90 off, \
91 0, \
92 &name ## _type_info, \
93 &name ## _hierarchy \
96 #define DEFINE_CXX_TYPE_INFO(type) \
97 static const cxx_type_info type ## _cxx_type_info = { \
98 0, \
99 & type ##_type_info, \
100 { 0, -1, 0 }, \
101 sizeof(type), \
102 (cxx_copy_ctor)THISCALL(type ##_copy_ctor) \
105 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, cl3, cl4, dtor) \
106 DEFINE_CXX_TYPE_INFO(type) \
108 static const cxx_type_info_table type ## _cxx_type_table = { \
109 base_no+1, \
111 & type ## _cxx_type_info, \
112 cl1, \
113 cl2, \
114 cl3, \
115 cl4 \
117 }; \
119 static const cxx_exception_type type ## _cxx_type = { \
120 0, \
121 (cxx_copy_ctor)THISCALL(dtor), \
122 NULL, \
123 & type ## _cxx_type_table \
126 #else
128 #define __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
129 static type_info name ## _type_info = { \
130 &type_info_vtable, \
131 NULL, \
132 mangled_name \
133 }; \
135 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
136 0xdeadbeef, \
137 base_classes_no, \
138 { 0, -1, 0}, \
139 64 \
142 #define DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
143 __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
145 static void init_ ## name ## _rtti(char *base) \
147 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
150 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
151 __DEFINE_RTTI_BASE(name, base_classes_no, mangled_name) \
153 static rtti_base_array name ## _rtti_base_array = { \
155 0xdeadbeef, \
156 0xdeadbeef, \
157 0xdeadbeef, \
158 0xdeadbeef, \
159 0xdeadbeef, \
160 0xdeadbeef, \
161 0xdeadbeef, \
162 0xdeadbeef, \
163 0xdeadbeef, \
164 0xdeadbeef, \
166 }; \
168 static rtti_object_hierarchy name ## _hierarchy = { \
169 0, \
170 0, \
171 base_classes_no+1, \
172 0xdeadbeef \
173 }; \
175 rtti_object_locator name ## _rtti = { \
176 1, \
177 off, \
178 0, \
179 0xdeadbeef, \
180 0xdeadbeef, \
181 0xdeadbeef \
184 static void init_ ## name ## _rtti(char *base) \
186 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
187 name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
188 name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
189 name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
190 name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
191 name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
192 name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
193 name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
194 name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
195 name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
196 name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
197 name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
198 name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
199 name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
200 name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
203 #define DEFINE_CXX_TYPE_INFO(type) \
204 static cxx_type_info type ## _cxx_type_info = { \
205 0, \
206 0xdeadbeef, \
207 { 0, -1, 0 }, \
208 sizeof(type), \
209 0xdeadbeef \
210 }; \
212 static void init_ ## type ## _cxx_type_info(char *base) \
214 type ## _cxx_type_info.type_info = (char *)&type ## _type_info - base; \
215 type ## _cxx_type_info.copy_ctor = (char *)type ## _copy_ctor - base; \
218 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, cl3, cl4, dtor) \
220 DEFINE_CXX_TYPE_INFO(type) \
222 static cxx_type_info_table type ## _cxx_type_table = { \
223 base_no+1, \
225 0xdeadbeef, \
226 0xdeadbeef, \
227 0xdeadbeef, \
228 0xdeadbeef, \
229 0xdeadbeef \
231 }; \
233 static cxx_exception_type type ##_cxx_type = { \
234 0, \
235 0xdeadbeef, \
236 0, \
237 0xdeadbeef \
238 }; \
240 static void init_ ## type ## _cxx(char *base) \
242 init_ ## type ## _cxx_type_info(base); \
243 type ## _cxx_type_table.info[0] = (char *)&type ## _cxx_type_info - base; \
244 type ## _cxx_type_table.info[1] = (char *)cl1 - base; \
245 type ## _cxx_type_table.info[2] = (char *)cl2 - base; \
246 type ## _cxx_type_table.info[3] = (char *)cl3 - base; \
247 type ## _cxx_type_table.info[4] = (char *)cl4 - base; \
248 type ## _cxx_type.destructor = (char *)dtor - base; \
249 type ## _cxx_type.type_info_table = (char *)&type ## _cxx_type_table - base; \
252 #endif
254 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
255 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
256 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
257 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
258 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
259 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
260 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
261 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
262 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
263 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
264 #define DEFINE_RTTI_DATA5(name, off, cl1, cl2, cl3, cl4, cl5, mangled_name) \
265 DEFINE_RTTI_DATA(name, off, 5, cl1, cl2, cl3, cl4, cl5, NULL, NULL, NULL, NULL, mangled_name)
266 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
267 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
268 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
269 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
271 #define DEFINE_CXX_DATA0(name, dtor) \
272 DEFINE_CXX_DATA(name, 0, NULL, NULL, NULL, NULL, dtor)
273 #define DEFINE_CXX_DATA1(name, cl1, dtor) \
274 DEFINE_CXX_DATA(name, 1, cl1, NULL, NULL, NULL, dtor)
275 #define DEFINE_CXX_DATA2(name, cl1, cl2, dtor) \
276 DEFINE_CXX_DATA(name, 2, cl1, cl2, NULL, NULL, dtor)
277 #define DEFINE_CXX_DATA3(name, cl1, cl2, cl3, dtor) \
278 DEFINE_CXX_DATA(name, 3, cl1, cl2, cl3, NULL, dtor)
279 #define DEFINE_CXX_DATA4(name, cl1, cl2, cl3, cl4, dtor) \
280 DEFINE_CXX_DATA(name, 4, cl1, cl2, cl3, cl4, dtor)
282 #ifdef __ASM_USE_THISCALL_WRAPPER
284 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
286 extern void *vtbl_wrapper_0;
287 extern void *vtbl_wrapper_4;
288 extern void *vtbl_wrapper_8;
289 extern void *vtbl_wrapper_12;
290 extern void *vtbl_wrapper_16;
291 extern void *vtbl_wrapper_20;
292 extern void *vtbl_wrapper_24;
293 extern void *vtbl_wrapper_28;
294 extern void *vtbl_wrapper_32;
295 extern void *vtbl_wrapper_36;
296 extern void *vtbl_wrapper_40;
297 extern void *vtbl_wrapper_44;
298 extern void *vtbl_wrapper_48;
299 extern void *vtbl_wrapper_52;
300 extern void *vtbl_wrapper_56;
302 #else
304 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__thiscall***)type)this)[0][off/4]args
306 #endif
308 /* exception object */
309 typedef void (*vtable_ptr)(void);
310 typedef struct __exception
312 const vtable_ptr *vtable;
313 char *name; /* Name of this exception, always a new copy for each object */
314 int do_free; /* Whether to free 'name' in our dtor */
315 } exception;
317 /* rtti */
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 */
323 } type_info;
325 extern const vtable_ptr type_info_vtable;
327 /* offsets for computing the this pointer */
328 typedef struct
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 */
333 } this_ptr_offsets;
335 /* dlls/msvcrt/cppexcept.h */
336 typedef void (*cxx_copy_ctor)(void);
338 #ifndef __x86_64__
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 */
351 } rtti_base_array;
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;
365 unsigned int flags;
366 const type_info *type_descriptor;
367 const rtti_object_hierarchy *type_hierarchy;
368 } rtti_object_locator;
370 typedef struct
372 UINT flags;
373 const type_info *type_info;
374 this_ptr_offsets offsets;
375 unsigned int size;
376 cxx_copy_ctor copy_ctor;
377 } cxx_type_info;
379 typedef struct
381 UINT count;
382 const cxx_type_info *info[5];
383 } cxx_type_info_table;
385 typedef struct
387 UINT flags;
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;
393 #else
395 typedef struct
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;
403 typedef struct
405 unsigned int bases[10]; /* First element is the class itself */
406 } rtti_base_array;
408 typedef struct
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;
416 typedef struct
418 unsigned int signature;
419 int base_class_offset;
420 unsigned int flags;
421 unsigned int type_descriptor;
422 unsigned int type_hierarchy;
423 unsigned int object_locator;
424 } rtti_object_locator;
426 typedef struct
428 UINT flags;
429 unsigned int type_info;
430 this_ptr_offsets offsets;
431 unsigned int size;
432 unsigned int copy_ctor;
433 } cxx_type_info;
435 typedef struct
437 UINT count;
438 unsigned int info[5];
439 } cxx_type_info_table;
441 typedef struct
443 UINT flags;
444 unsigned int destructor;
445 unsigned int custom_handler;
446 unsigned int type_info_table;
447 } cxx_exception_type;
449 #endif
451 #define CREATE_TYPE_INFO_VTABLE \
452 DEFINE_THISCALL_WRAPPER(type_info_vector_dtor,8) \
453 void * __thiscall type_info_vector_dtor(type_info * _this, unsigned int flags) \
455 if (flags & 2) \
457 /* we have an array, with the number of elements stored before the first object */ \
458 INT_PTR i, *ptr = (INT_PTR *)_this - 1; \
460 for (i = *ptr - 1; i >= 0; i--) free(_this[i].name); \
461 free(ptr); \
463 else \
465 free(_this->name); \
466 if (flags & 1) free(_this); \
468 return _this; \
471 DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" ) \
473 __ASM_BLOCK_BEGIN(type_info_vtables) \
474 __ASM_VTABLE(type_info, \
475 VTABLE_ADD_FUNC(type_info_vector_dtor)); \
476 __ASM_BLOCK_END