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