wined3d: Pass a wined3d_context_gl structure to context_check_fbo_status().
[wine.git] / dlls / msvcp90 / cxx.h
blobfd697564afda8fd6b76dd4d3ac9688cefc67f3e9
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 /* Copied from dlls/msvcrt/cxx.h */
22 #undef __thiscall
23 #ifdef __i386__ /* thiscall functions are i386-specific */
25 #define THISCALL(func) __thiscall_ ## func
26 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
27 #define __thiscall __stdcall
28 #define DEFINE_THISCALL_WRAPPER(func,args) \
29 extern void THISCALL(func)(void); \
30 __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
31 "popl %eax\n\t" \
32 "pushl %ecx\n\t" \
33 "pushl %eax\n\t" \
34 "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
35 #else /* __i386__ */
37 #define THISCALL(func) func
38 #define THISCALL_NAME(func) __ASM_NAME(#func)
39 #define __thiscall __cdecl
40 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
42 #endif /* __i386__ */
44 #ifdef _WIN64
46 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
48 #define __ASM_VTABLE(name,funcs) \
49 __asm__(".data\n" \
50 "\t.balign 8\n" \
51 "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
52 "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
53 __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
54 funcs "\n\t.text")
56 #else
58 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
60 #define __ASM_VTABLE(name,funcs) \
61 __asm__(".data\n" \
62 "\t.balign 4\n" \
63 "\t.long " __ASM_NAME(#name "_rtti") "\n" \
64 "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
65 __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
66 funcs "\n\t.text")
68 #endif /* _WIN64 */
70 #ifndef __x86_64__
72 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
73 static type_info name ## _type_info = { \
74 &MSVCP_type_info_vtable, \
75 NULL, \
76 mangled_name \
77 }; \
79 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
80 &name ##_type_info, \
81 base_classes_no, \
82 { 0, -1, 0}, \
83 64 \
84 }; \
86 static const rtti_base_array name ## _rtti_base_array = { \
87 { \
88 &name ## _rtti_base_descriptor, \
89 cl1, \
90 cl2, \
91 cl3, \
92 cl4, \
93 cl5, \
94 cl6, \
95 cl7, \
96 cl8, \
97 cl9, \
98 } \
99 }; \
101 static const rtti_object_hierarchy name ## _hierarchy = { \
102 0, \
103 0, \
104 base_classes_no+1, \
105 &name ## _rtti_base_array \
106 }; \
108 const rtti_object_locator name ## _rtti = { \
109 0, \
110 off, \
111 0, \
112 &name ## _type_info, \
113 &name ## _hierarchy \
116 #define DEFINE_CXX_TYPE_INFO(type) \
117 static const cxx_type_info type ## _cxx_type_info = { \
118 0, \
119 & type ##_type_info, \
120 { 0, -1, 0 }, \
121 sizeof(type), \
122 (cxx_copy_ctor)THISCALL(MSVCP_ ## type ##_copy_ctor) \
125 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, cl3, cl4, dtor) \
126 DEFINE_CXX_TYPE_INFO(type) \
128 static const cxx_type_info_table type ## _cxx_type_table = { \
129 base_no+1, \
131 & type ## _cxx_type_info, \
132 cl1, \
133 cl2, \
134 cl3, \
135 cl4 \
137 }; \
139 static const cxx_exception_type type ## _cxx_type = { \
140 0, \
141 (cxx_copy_ctor)THISCALL(dtor), \
142 NULL, \
143 & type ## _cxx_type_table \
146 #else
148 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
149 static type_info name ## _type_info = { \
150 &MSVCP_type_info_vtable, \
151 NULL, \
152 mangled_name \
153 }; \
155 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
156 0xdeadbeef, \
157 base_classes_no, \
158 { 0, -1, 0}, \
159 64 \
160 }; \
162 static rtti_base_array name ## _rtti_base_array = { \
164 0xdeadbeef, \
165 0xdeadbeef, \
166 0xdeadbeef, \
167 0xdeadbeef, \
168 0xdeadbeef, \
169 0xdeadbeef, \
170 0xdeadbeef, \
171 0xdeadbeef, \
172 0xdeadbeef, \
173 0xdeadbeef, \
175 }; \
177 static rtti_object_hierarchy name ## _hierarchy = { \
178 0, \
179 0, \
180 base_classes_no+1, \
181 0xdeadbeef \
182 }; \
184 rtti_object_locator name ## _rtti = { \
185 1, \
186 off, \
187 0, \
188 0xdeadbeef, \
189 0xdeadbeef, \
190 0xdeadbeef \
193 static void init_ ## name ## _rtti(char *base) \
195 name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
196 name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
197 name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
198 name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
199 name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
200 name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
201 name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
202 name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
203 name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
204 name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
205 name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
206 name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
207 name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
208 name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
209 name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
212 #define DEFINE_CXX_TYPE_INFO(type) \
213 static cxx_type_info type ## _cxx_type_info = { \
214 0, \
215 0xdeadbeef, \
216 { 0, -1, 0 }, \
217 sizeof(type), \
218 0xdeadbeef \
219 }; \
221 static void init_ ## type ## _cxx_type_info(char *base) \
223 type ## _cxx_type_info.type_info = (char *)&type ## _type_info - base; \
224 type ## _cxx_type_info.copy_ctor = (char *)MSVCP_ ## type ## _copy_ctor - base; \
227 #define DEFINE_CXX_DATA(type, base_no, cl1, cl2, cl3, cl4, dtor) \
229 DEFINE_CXX_TYPE_INFO(type) \
231 static cxx_type_info_table type ## _cxx_type_table = { \
232 base_no+1, \
234 0xdeadbeef, \
235 0xdeadbeef, \
236 0xdeadbeef, \
237 0xdeadbeef, \
238 0xdeadbeef \
240 }; \
242 static cxx_exception_type type ##_cxx_type = { \
243 0, \
244 0xdeadbeef, \
245 0, \
246 0xdeadbeef \
247 }; \
249 static void init_ ## type ## _cxx(char *base) \
251 init_ ## type ## _cxx_type_info(base); \
252 type ## _cxx_type_table.info[0] = (char *)&type ## _cxx_type_info - base; \
253 type ## _cxx_type_table.info[1] = (char *)cl1 - base; \
254 type ## _cxx_type_table.info[2] = (char *)cl2 - base; \
255 type ## _cxx_type_table.info[3] = (char *)cl3 - base; \
256 type ## _cxx_type_table.info[4] = (char *)cl4 - base; \
257 type ## _cxx_type.destructor = (char *)dtor - base; \
258 type ## _cxx_type.type_info_table = (char *)&type ## _cxx_type_table - base; \
261 #endif
263 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
264 DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
265 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
266 DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
267 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
268 DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
269 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
270 DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
271 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
272 DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
273 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
274 DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
275 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
276 DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
278 #define DEFINE_CXX_DATA0(name, dtor) \
279 DEFINE_CXX_DATA(name, 0, NULL, NULL, NULL, NULL, dtor)
280 #define DEFINE_CXX_DATA1(name, cl1, dtor) \
281 DEFINE_CXX_DATA(name, 1, cl1, NULL, NULL, NULL, dtor)
282 #define DEFINE_CXX_DATA2(name, cl1, cl2, dtor) \
283 DEFINE_CXX_DATA(name, 2, cl1, cl2, NULL, NULL, dtor)
284 #define DEFINE_CXX_DATA3(name, cl1, cl2, cl3, dtor) \
285 DEFINE_CXX_DATA(name, 3, cl1, cl2, cl3, NULL, dtor)
286 #define DEFINE_CXX_DATA4(name, cl1, cl2, cl3, cl4, dtor) \
287 DEFINE_CXX_DATA(name, 4, cl1, cl2, cl3, cl4, dtor)
289 #ifdef __i386__
291 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
293 extern void *vtbl_wrapper_0;
294 extern void *vtbl_wrapper_4;
295 extern void *vtbl_wrapper_8;
296 extern void *vtbl_wrapper_12;
297 extern void *vtbl_wrapper_16;
298 extern void *vtbl_wrapper_20;
299 extern void *vtbl_wrapper_24;
300 extern void *vtbl_wrapper_28;
301 extern void *vtbl_wrapper_32;
302 extern void *vtbl_wrapper_36;
303 extern void *vtbl_wrapper_40;
304 extern void *vtbl_wrapper_44;
305 extern void *vtbl_wrapper_48;
306 extern void *vtbl_wrapper_52;
307 extern void *vtbl_wrapper_56;
309 #else
311 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__cdecl***)type)this)[0][off/4]args
313 #endif
315 /* exception object */
316 typedef void (*vtable_ptr)(void);
317 typedef struct __exception
319 const vtable_ptr *vtable;
320 char *name; /* Name of this exception, always a new copy for each object */
321 int do_free; /* Whether to free 'name' in our dtor */
322 } exception;
324 /* Internal: throws selected exception */
325 typedef enum __exception_type {
326 EXCEPTION_RERAISE,
327 EXCEPTION,
328 EXCEPTION_BAD_ALLOC,
329 EXCEPTION_BAD_CAST,
330 EXCEPTION_LOGIC_ERROR,
331 EXCEPTION_LENGTH_ERROR,
332 EXCEPTION_OUT_OF_RANGE,
333 EXCEPTION_INVALID_ARGUMENT,
334 EXCEPTION_RUNTIME_ERROR,
335 EXCEPTION_FAILURE,
336 EXCEPTION_RANGE_ERROR,
337 } exception_type;
338 void throw_exception(exception_type, const char *);
340 /* rtti */
341 typedef struct __type_info
343 const vtable_ptr *vtable;
344 char *name; /* Unmangled name, allocated lazily */
345 char mangled[128]; /* Variable length, but we declare it large enough for static RTTI */
346 } type_info;
348 extern const vtable_ptr MSVCP_type_info_vtable;
350 /* offsets for computing the this pointer */
351 typedef struct
353 int this_offset; /* offset of base class this pointer from start of object */
354 int vbase_descr; /* offset of virtual base class descriptor */
355 int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
356 } this_ptr_offsets;
358 /* dlls/msvcrt/cppexcept.h */
359 typedef void (*cxx_copy_ctor)(void);
361 #ifndef __x86_64__
363 typedef struct _rtti_base_descriptor
365 const type_info *type_descriptor;
366 int num_base_classes;
367 this_ptr_offsets offsets; /* offsets for computing the this pointer */
368 unsigned int attributes;
369 } rtti_base_descriptor;
371 typedef struct _rtti_base_array
373 const rtti_base_descriptor *bases[10]; /* First element is the class itself */
374 } rtti_base_array;
376 typedef struct _rtti_object_hierarchy
378 unsigned int signature;
379 unsigned int attributes;
380 int array_len; /* Size of the array pointed to by 'base_classes' */
381 const rtti_base_array *base_classes;
382 } rtti_object_hierarchy;
384 typedef struct _rtti_object_locator
386 unsigned int signature;
387 int base_class_offset;
388 unsigned int flags;
389 const type_info *type_descriptor;
390 const rtti_object_hierarchy *type_hierarchy;
391 } rtti_object_locator;
393 typedef struct
395 UINT flags;
396 const type_info *type_info;
397 this_ptr_offsets offsets;
398 unsigned int size;
399 cxx_copy_ctor copy_ctor;
400 } cxx_type_info;
402 typedef struct
404 UINT count;
405 const cxx_type_info *info[5];
406 } cxx_type_info_table;
408 typedef struct
410 UINT flags;
411 void (*destructor)(void);
412 void* /*cxx_exc_custom_handler*/ custom_handler;
413 const cxx_type_info_table *type_info_table;
414 } cxx_exception_type;
416 #else
418 typedef struct
420 unsigned int type_descriptor;
421 int num_base_classes;
422 this_ptr_offsets offsets; /* offsets for computing the this pointer */
423 unsigned int attributes;
424 } rtti_base_descriptor;
426 typedef struct
428 unsigned int bases[10]; /* First element is the class itself */
429 } rtti_base_array;
431 typedef struct
433 unsigned int signature;
434 unsigned int attributes;
435 int array_len; /* Size of the array pointed to by 'base_classes' */
436 unsigned int base_classes;
437 } rtti_object_hierarchy;
439 typedef struct
441 unsigned int signature;
442 int base_class_offset;
443 unsigned int flags;
444 unsigned int type_descriptor;
445 unsigned int type_hierarchy;
446 unsigned int object_locator;
447 } rtti_object_locator;
449 typedef struct
451 UINT flags;
452 unsigned int type_info;
453 this_ptr_offsets offsets;
454 unsigned int size;
455 unsigned int copy_ctor;
456 } cxx_type_info;
458 typedef struct
460 UINT count;
461 unsigned int info[5];
462 } cxx_type_info_table;
464 typedef struct
466 UINT flags;
467 unsigned int destructor;
468 unsigned int custom_handler;
469 unsigned int type_info_table;
470 } cxx_exception_type;
472 #endif