wined3d: wined3d_device_get_transform() never fails.
[wine] / dlls / msvcp100 / cxx.h
1 /*
2  * Copyright 2012 Piotr Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 /* Copied from dlls/msvcrt/cpp.c */
20 #ifdef __i386__  /* thiscall functions are i386-specific */
21
22 #define THISCALL(func) __thiscall_ ## func
23 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
24 #define __thiscall __stdcall
25 #define DEFINE_THISCALL_WRAPPER(func,args) \
26     extern void THISCALL(func)(void); \
27     __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
28                       "popl %eax\n\t" \
29                       "pushl %ecx\n\t" \
30                       "pushl %eax\n\t" \
31                       "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
32 #else /* __i386__ */
33
34 #define THISCALL(func) func
35 #define THISCALL_NAME(func) __ASM_NAME(#func)
36 #define __thiscall __cdecl
37 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
38
39 #endif /* __i386__ */
40
41 #ifdef _WIN64
42
43 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
44
45 #define __ASM_VTABLE(name,funcs) \
46     __asm__(".data\n" \
47             "\t.align 8\n" \
48             "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
49             "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
50             __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
51             funcs "\n\t.text")
52
53 #else
54
55 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
56
57 #define __ASM_VTABLE(name,funcs) \
58     __asm__(".data\n" \
59             "\t.align 4\n" \
60             "\t.long " __ASM_NAME(#name "_rtti") "\n" \
61             "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
62             __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
63             funcs "\n\t.text")
64
65 #endif /* _WIN64 */
66
67 #ifndef __x86_64__
68
69 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
70     static const type_info name ## _type_info = { \
71         &MSVCP_type_info_vtable, \
72         NULL, \
73         mangled_name \
74     }; \
75 \
76 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
77     &name ##_type_info, \
78     base_classes_no, \
79     { 0, -1, 0}, \
80     64 \
81 }; \
82 \
83 static const rtti_base_array name ## _rtti_base_array = { \
84     { \
85         &name ## _rtti_base_descriptor, \
86         cl1, \
87         cl2, \
88         cl3, \
89         cl4, \
90         cl5, \
91         cl6, \
92         cl7, \
93         cl8, \
94         cl9, \
95     } \
96 }; \
97 \
98 static const rtti_object_hierarchy name ## _hierarchy = { \
99     0, \
100     0, \
101     base_classes_no+1, \
102     &name ## _rtti_base_array \
103 }; \
104 \
105 const rtti_object_locator name ## _rtti = { \
106     0, \
107     off, \
108     0, \
109     &name ## _type_info, \
110     &name ## _hierarchy \
111 }
112
113 #else
114
115 #define DEFINE_RTTI_DATA(name, off, base_classes_no, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
116     static const type_info name ## _type_info = { \
117         &MSVCP_type_info_vtable, \
118         NULL, \
119         mangled_name \
120     }; \
121 \
122 static rtti_base_descriptor name ## _rtti_base_descriptor = { \
123     0xdeadbeef, \
124     base_classes_no, \
125     { 0, -1, 0}, \
126     64 \
127 }; \
128 \
129 static rtti_base_array name ## _rtti_base_array = { \
130     { \
131         0xdeadbeef, \
132         0xdeadbeef, \
133         0xdeadbeef, \
134         0xdeadbeef, \
135         0xdeadbeef, \
136         0xdeadbeef, \
137         0xdeadbeef, \
138         0xdeadbeef, \
139         0xdeadbeef, \
140         0xdeadbeef, \
141     } \
142 }; \
143 \
144 static rtti_object_hierarchy name ## _hierarchy = { \
145     0, \
146     0, \
147     base_classes_no+1, \
148     0xdeadbeef \
149 }; \
150 \
151 rtti_object_locator name ## _rtti = { \
152     1, \
153     off, \
154     0, \
155     0xdeadbeef, \
156     0xdeadbeef, \
157     0xdeadbeef \
158 };\
159 \
160 static void init_ ## name ## _rtti(char *base) \
161 { \
162     name ## _rtti_base_descriptor.type_descriptor = (char*)&name ## _type_info - base; \
163     name ## _rtti_base_array.bases[0] = (char*)&name ## _rtti_base_descriptor - base; \
164     name ## _rtti_base_array.bases[1] = (char*)cl1 - base; \
165     name ## _rtti_base_array.bases[2] = (char*)cl2 - base; \
166     name ## _rtti_base_array.bases[3] = (char*)cl3 - base; \
167     name ## _rtti_base_array.bases[4] = (char*)cl4 - base; \
168     name ## _rtti_base_array.bases[5] = (char*)cl5 - base; \
169     name ## _rtti_base_array.bases[6] = (char*)cl6 - base; \
170     name ## _rtti_base_array.bases[7] = (char*)cl7 - base; \
171     name ## _rtti_base_array.bases[8] = (char*)cl8 - base; \
172     name ## _rtti_base_array.bases[9] = (char*)cl9 - base; \
173     name ## _hierarchy.base_classes = (char*)&name ## _rtti_base_array - base; \
174     name ## _rtti.type_descriptor = (char*)&name ## _type_info - base; \
175     name ## _rtti.type_hierarchy = (char*)&name ## _hierarchy - base; \
176     name ## _rtti.object_locator = (char*)&name ## _rtti - base; \
177 }
178
179 #endif
180
181 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
182     DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
183 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
184     DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
185 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
186     DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
187 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
188     DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
189 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
190     DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
191 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
192     DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
193 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
194     DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
195
196 #ifdef __i386__
197
198 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (WINAPI*)type)&vtbl_wrapper_##off)args
199
200 extern void *vtbl_wrapper_0;
201 extern void *vtbl_wrapper_4;
202 extern void *vtbl_wrapper_8;
203 extern void *vtbl_wrapper_12;
204 extern void *vtbl_wrapper_16;
205 extern void *vtbl_wrapper_20;
206 extern void *vtbl_wrapper_24;
207 extern void *vtbl_wrapper_28;
208 extern void *vtbl_wrapper_32;
209 extern void *vtbl_wrapper_36;
210 extern void *vtbl_wrapper_40;
211 extern void *vtbl_wrapper_44;
212 extern void *vtbl_wrapper_48;
213 extern void *vtbl_wrapper_52;
214 extern void *vtbl_wrapper_56;
215 extern void *vtbl_wrapper_60;
216
217 #else
218
219 #define CALL_VTBL_FUNC(this, off, ret, type, args) ((ret (__cdecl***)type)this)[0][off/4]args
220
221 #endif
222
223 /* exception object */
224 typedef void (*vtable_ptr)(void);
225 typedef struct __exception
226 {
227     const vtable_ptr *vtable;
228     char             *name;    /* Name of this exception, always a new copy for each object */
229     int               do_free; /* Whether to free 'name' in our dtor */
230 } exception;
231
232 /* Internal: throws selected exception */
233 typedef enum __exception_type {
234     EXCEPTION_RERAISE,
235     EXCEPTION,
236     EXCEPTION_BAD_ALLOC,
237     EXCEPTION_LOGIC_ERROR,
238     EXCEPTION_LENGTH_ERROR,
239     EXCEPTION_OUT_OF_RANGE,
240     EXCEPTION_INVALID_ARGUMENT,
241     EXCEPTION_RUNTIME_ERROR,
242     EXCEPTION_FAILURE,
243 } exception_type;
244 void throw_exception(exception_type, const char *);
245
246 /* rtti */
247 typedef struct __type_info
248 {
249     const vtable_ptr *vtable;
250     char              *name;         /* Unmangled name, allocated lazily */
251     char               mangled[128]; /* Variable length, but we declare it large enough for static RTTI */
252 } type_info;
253
254 extern const vtable_ptr MSVCP_type_info_vtable;
255
256 /* offsets for computing the this pointer */
257 typedef struct
258 {
259     int         this_offset;   /* offset of base class this pointer from start of object */
260     int         vbase_descr;   /* offset of virtual base class descriptor */
261     int         vbase_offset;  /* offset of this pointer offset in virtual base class descriptor */
262 } this_ptr_offsets;
263
264 #ifndef __x86_64__
265
266 typedef struct _rtti_base_descriptor
267 {
268     const type_info *type_descriptor;
269     int num_base_classes;
270     this_ptr_offsets offsets;    /* offsets for computing the this pointer */
271     unsigned int attributes;
272 } rtti_base_descriptor;
273
274 typedef struct _rtti_base_array
275 {
276     const rtti_base_descriptor *bases[10]; /* First element is the class itself */
277 } rtti_base_array;
278
279 typedef struct _rtti_object_hierarchy
280 {
281     unsigned int signature;
282     unsigned int attributes;
283     int array_len; /* Size of the array pointed to by 'base_classes' */
284     const rtti_base_array *base_classes;
285 } rtti_object_hierarchy;
286
287 typedef struct _rtti_object_locator
288 {
289     unsigned int signature;
290     int base_class_offset;
291     unsigned int flags;
292     const type_info *type_descriptor;
293     const rtti_object_hierarchy *type_hierarchy;
294 } rtti_object_locator;
295
296 #else
297
298 typedef struct
299 {
300     unsigned int type_descriptor;
301     int num_base_classes;
302     this_ptr_offsets offsets;    /* offsets for computing the this pointer */
303     unsigned int attributes;
304 } rtti_base_descriptor;
305
306 typedef struct
307 {
308     unsigned int bases[10]; /* First element is the class itself */
309 } rtti_base_array;
310
311 typedef struct
312 {
313     unsigned int signature;
314     unsigned int attributes;
315     int array_len; /* Size of the array pointed to by 'base_classes' */
316     unsigned int base_classes;
317 } rtti_object_hierarchy;
318
319 typedef struct
320 {
321     unsigned int signature;
322     int base_class_offset;
323     unsigned int flags;
324     unsigned int type_descriptor;
325     unsigned int type_hierarchy;
326     unsigned int object_locator;
327 } rtti_object_locator;
328
329 #endif