wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / msvcp90 / cxx.h
blob0c5b83f93f6807ad5712112238e76a2c4b1f61f8
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_BASE(name, base_classes_no, 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 \
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(MSVCP_ ## 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 &MSVCP_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 *)MSVCP_ ## 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 /* Internal: throws selected exception */
318 typedef enum __exception_type {
319 EXCEPTION_RERAISE,
320 EXCEPTION,
321 EXCEPTION_BAD_ALLOC,
322 EXCEPTION_BAD_CAST,
323 EXCEPTION_LOGIC_ERROR,
324 EXCEPTION_LENGTH_ERROR,
325 EXCEPTION_OUT_OF_RANGE,
326 EXCEPTION_INVALID_ARGUMENT,
327 EXCEPTION_RUNTIME_ERROR,
328 EXCEPTION_FAILURE,
329 EXCEPTION_RANGE_ERROR,
330 } exception_type;
331 void throw_exception(exception_type, const char *);
333 /* rtti */
334 typedef struct __type_info
336 const vtable_ptr *vtable;
337 char *name; /* Unmangled name, allocated lazily */
338 char mangled[128]; /* Variable length, but we declare it large enough for static RTTI */
339 } type_info;
341 extern const vtable_ptr MSVCP_type_info_vtable;
343 /* offsets for computing the this pointer */
344 typedef struct
346 int this_offset; /* offset of base class this pointer from start of object */
347 int vbase_descr; /* offset of virtual base class descriptor */
348 int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
349 } this_ptr_offsets;
351 /* dlls/msvcrt/cppexcept.h */
352 typedef void (*cxx_copy_ctor)(void);
354 #ifndef __x86_64__
356 typedef struct _rtti_base_descriptor
358 const type_info *type_descriptor;
359 int num_base_classes;
360 this_ptr_offsets offsets; /* offsets for computing the this pointer */
361 unsigned int attributes;
362 } rtti_base_descriptor;
364 typedef struct _rtti_base_array
366 const rtti_base_descriptor *bases[10]; /* First element is the class itself */
367 } rtti_base_array;
369 typedef struct _rtti_object_hierarchy
371 unsigned int signature;
372 unsigned int attributes;
373 int array_len; /* Size of the array pointed to by 'base_classes' */
374 const rtti_base_array *base_classes;
375 } rtti_object_hierarchy;
377 typedef struct _rtti_object_locator
379 unsigned int signature;
380 int base_class_offset;
381 unsigned int flags;
382 const type_info *type_descriptor;
383 const rtti_object_hierarchy *type_hierarchy;
384 } rtti_object_locator;
386 typedef struct
388 UINT flags;
389 const type_info *type_info;
390 this_ptr_offsets offsets;
391 unsigned int size;
392 cxx_copy_ctor copy_ctor;
393 } cxx_type_info;
395 typedef struct
397 UINT count;
398 const cxx_type_info *info[5];
399 } cxx_type_info_table;
401 typedef struct
403 UINT flags;
404 void (*destructor)(void);
405 void* /*cxx_exc_custom_handler*/ custom_handler;
406 const cxx_type_info_table *type_info_table;
407 } cxx_exception_type;
409 #else
411 typedef struct
413 unsigned int type_descriptor;
414 int num_base_classes;
415 this_ptr_offsets offsets; /* offsets for computing the this pointer */
416 unsigned int attributes;
417 } rtti_base_descriptor;
419 typedef struct
421 unsigned int bases[10]; /* First element is the class itself */
422 } rtti_base_array;
424 typedef struct
426 unsigned int signature;
427 unsigned int attributes;
428 int array_len; /* Size of the array pointed to by 'base_classes' */
429 unsigned int base_classes;
430 } rtti_object_hierarchy;
432 typedef struct
434 unsigned int signature;
435 int base_class_offset;
436 unsigned int flags;
437 unsigned int type_descriptor;
438 unsigned int type_hierarchy;
439 unsigned int object_locator;
440 } rtti_object_locator;
442 typedef struct
444 UINT flags;
445 unsigned int type_info;
446 this_ptr_offsets offsets;
447 unsigned int size;
448 unsigned int copy_ctor;
449 } cxx_type_info;
451 typedef struct
453 UINT count;
454 unsigned int info[5];
455 } cxx_type_info_table;
457 typedef struct
459 UINT flags;
460 unsigned int destructor;
461 unsigned int custom_handler;
462 unsigned int type_info_table;
463 } cxx_exception_type;
465 #endif
467 #define CREATE_TYPE_INFO_VTABLE\
468 static void MSVCP_type_info_dtor(type_info * _this) \
470 free(_this->name); \
473 DEFINE_THISCALL_WRAPPER(MSVCP_type_info_vector_dtor,8) \
474 void * __thiscall MSVCP_type_info_vector_dtor(type_info * _this, unsigned int flags) \
476 if (flags & 2) \
478 /* we have an array, with the number of elements stored before the first object */ \
479 INT_PTR i, *ptr = (INT_PTR *)_this - 1; \
481 for (i = *ptr - 1; i >= 0; i--) MSVCP_type_info_dtor(_this + i); \
482 free(ptr); \
484 else \
486 MSVCP_type_info_dtor(_this); \
487 if (flags & 1) free(_this); \
489 return _this; \
492 DEFINE_RTTI_DATA0( type_info, 0, ".?AVtype_info@@" ) \
494 __ASM_BLOCK_BEGIN(type_info_vtables) \
495 __ASM_VTABLE(type_info, \
496 VTABLE_ADD_FUNC(MSVCP_type_info_vector_dtor)); \
497 __ASM_BLOCK_END