msvcp90: Use macro to define RTTI data.
[wine] / dlls / msvcp90 / msvcp90.h
1 /*
2  * Copyright 2010 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 #include "stdlib.h"
20 #include "windef.h"
21
22 typedef unsigned char MSVCP_bool;
23 typedef SIZE_T MSVCP_size_t;
24 typedef SIZE_T streamoff;
25 typedef SIZE_T streamsize;
26
27 void __cdecl _invalid_parameter(const wchar_t*, const wchar_t*,
28         const wchar_t*, unsigned int, uintptr_t);
29
30 extern void* (__cdecl *MSVCRT_operator_new)(MSVCP_size_t);
31 extern void (__cdecl *MSVCRT_operator_delete)(void*);
32 extern void* (__cdecl *MSVCRT_set_new_handler)(void*);
33
34 /* Copied from dlls/msvcrt/cpp.c */
35 #ifdef __i386__  /* thiscall functions are i386-specific */
36
37 #define THISCALL(func) __thiscall_ ## func
38 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
39 #define __thiscall __stdcall
40 #define DEFINE_THISCALL_WRAPPER(func,args) \
41     extern void THISCALL(func)(void); \
42     __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
43                       "popl %eax\n\t" \
44                       "pushl %ecx\n\t" \
45                       "pushl %eax\n\t" \
46                       "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
47
48 #define DEFINE_THISCALL_WRAPPER_RETPTR(func,args) \
49     extern void THISCALL(func)(void); \
50     __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
51                       "popl %eax\n\t" \
52                       "popl %edx\n\t" \
53                       "pushl %ecx\n\t" \
54                       "pushl %edx\n\t" \
55                       "pushl %eax\n\t" \
56                       "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
57 #else /* __i386__ */
58
59 #define THISCALL(func) func
60 #define THISCALL_NAME(func) __ASM_NAME(#func)
61 #define __thiscall __cdecl
62 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
63 #define DEFINE_THISCALL_WRAPPER_RETPTR(func,args)  /* nothing */
64
65 #endif /* __i386__ */
66
67 #ifdef _WIN64
68
69 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
70
71 #define __ASM_VTABLE(name,funcs) \
72     __asm__(".data\n" \
73             "\t.align 8\n" \
74             "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
75             "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
76             __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
77             "\t.quad " THISCALL_NAME(MSVCP_ ## name ## _vector_dtor) "\n" \
78             funcs "\n\t.text")
79
80 #else
81
82 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
83
84 #define __ASM_VTABLE(name,funcs) \
85     __asm__(".data\n" \
86             "\t.align 4\n" \
87             "\t.long " __ASM_NAME(#name "_rtti") "\n" \
88             "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
89             __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
90             "\t.long " THISCALL_NAME(MSVCP_ ## name ## _vector_dtor) "\n" \
91             funcs "\n\t.text")
92
93 #endif /* _WIN64 */
94
95 #define DEFINE_RTTI_DATA(name, off, base_classes, cl1, cl2, cl3, mangled_name) \
96 static const type_info name ## _type_info = { \
97     &MSVCP_ ## name ## _vtable, \
98     NULL, \
99     mangled_name \
100 }; \
101 \
102 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
103     &name ##_type_info, \
104     base_classes, \
105     { 0, -1, 0}, \
106     64 \
107 }; \
108 \
109 static const rtti_base_array name ## _rtti_base_array = { \
110     { \
111         &name ## _rtti_base_descriptor, \
112         cl1, \
113         cl2, \
114         cl3 \
115     } \
116 }; \
117 \
118 static const rtti_object_hierarchy name ## _hierarchy = { \
119     0, \
120     0, \
121     base_classes+1, \
122     &name ## _rtti_base_array \
123 }; \
124 \
125 const rtti_object_locator name ## _rtti = { \
126     0, \
127     off, \
128     0, \
129     &name ## _type_info, \
130     &name ## _hierarchy \
131 }
132
133 /* exception object */
134 typedef void (*vtable_ptr)(void);
135 typedef struct __exception
136 {
137     const vtable_ptr *vtable;
138     char             *name;    /* Name of this exception, always a new copy for each object */
139     int               do_free; /* Whether to free 'name' in our dtor */
140 } exception;
141
142 /* Internal: throws selected exception */
143 typedef enum __exception_type {
144     EXCEPTION,
145     EXCEPTION_BAD_ALLOC,
146     EXCEPTION_LOGIC_ERROR,
147     EXCEPTION_LENGTH_ERROR,
148     EXCEPTION_OUT_OF_RANGE,
149     EXCEPTION_INVALID_ARGUMENT,
150     EXCEPTION_RUNTIME_ERROR
151 } exception_type;
152 void throw_exception(exception_type, const char *);
153 void set_exception_vtable(void);
154
155 /* rtti */
156 typedef struct __type_info
157 {
158     const vtable_ptr *vtable;
159     char              *name;        /* Unmangled name, allocated lazily */
160     char               mangled[64]; /* Variable length, but we declare it large enough for static RTTI */
161 } type_info;
162
163 /* offsets for computing the this pointer */
164 typedef struct
165 {
166     int         this_offset;   /* offset of base class this pointer from start of object */
167     int         vbase_descr;   /* offset of virtual base class descriptor */
168     int         vbase_offset;  /* offset of this pointer offset in virtual base class descriptor */
169 } this_ptr_offsets;
170
171 typedef struct _rtti_base_descriptor
172 {
173     const type_info *type_descriptor;
174     int num_base_classes;
175     this_ptr_offsets offsets;    /* offsets for computing the this pointer */
176     unsigned int attributes;
177 } rtti_base_descriptor;
178
179 typedef struct _rtti_base_array
180 {
181     const rtti_base_descriptor *bases[4]; /* First element is the class itself */
182 } rtti_base_array;
183
184 typedef struct _rtti_object_hierarchy
185 {
186     unsigned int signature;
187     unsigned int attributes;
188     int array_len; /* Size of the array pointed to by 'base_classes' */
189     const rtti_base_array *base_classes;
190 } rtti_object_hierarchy;
191
192 typedef struct _rtti_object_locator
193 {
194     unsigned int signature;
195     int base_class_offset;
196     unsigned int flags;
197     const type_info *type_descriptor;
198     const rtti_object_hierarchy *type_hierarchy;
199 } rtti_object_locator;
200
201 /* basic_string<char, char_traits<char>, allocator<char>> */
202 #define BUF_SIZE_CHAR 16
203 typedef struct _basic_string_char
204 {
205     void *allocator;
206     union {
207         char buf[BUF_SIZE_CHAR];
208         char *ptr;
209     } data;
210     MSVCP_size_t size;
211     MSVCP_size_t res;
212 } basic_string_char;
213
214 basic_string_char* __stdcall MSVCP_basic_string_char_ctor_cstr(basic_string_char*, const char*);
215 basic_string_char* __stdcall MSVCP_basic_string_char_copy_ctor(basic_string_char*, const basic_string_char*);
216 void __stdcall MSVCP_basic_string_char_dtor(basic_string_char*);
217 const char* __stdcall MSVCP_basic_string_char_c_str(const basic_string_char*);
218
219 #define BUF_SIZE_WCHAR 8
220 typedef struct _basic_string_wchar
221 {
222     void *allocator;
223     union {
224         wchar_t buf[BUF_SIZE_WCHAR];
225         wchar_t *ptr;
226     } data;
227     MSVCP_size_t size;
228     MSVCP_size_t res;
229 } basic_string_wchar;
230
231 char* __stdcall MSVCP_allocator_char_allocate(void*, MSVCP_size_t);
232 void __stdcall MSVCP_allocator_char_deallocate(void*, char*, MSVCP_size_t);
233 MSVCP_size_t __stdcall MSVCP_allocator_char_max_size(void*);
234 wchar_t* __stdcall MSVCP_allocator_wchar_allocate(void*, MSVCP_size_t);
235 void __stdcall MSVCP_allocator_wchar_deallocate(void*, wchar_t*, MSVCP_size_t);
236 MSVCP_size_t __stdcall MSVCP_allocator_wchar_max_size(void*);
237
238 /* class locale */
239 typedef struct
240 {
241     struct _locale__Locimp *ptr;
242 } locale;
243
244 locale* __thiscall locale_ctor(locale*);
245 void __thiscall locale_dtor(locale*);
246
247 /* class _Lockit */
248 typedef struct {
249     int locktype;
250 } _Lockit;
251
252 #define _LOCK_LOCALE 0
253 #define _LOCK_MALLOC 1
254 #define _LOCK_STREAM 2
255 #define _LOCK_DEBUG 3
256 #define _MAX_LOCK 4
257
258 void init_lockit(void);
259 void free_lockit(void);
260 _Lockit* __thiscall _Lockit_ctor_locktype(_Lockit*, int);
261 void __thiscall _Lockit_dtor(_Lockit*);
262
263 /* class mutex */
264 typedef struct {
265         void *mutex;
266 } mutex;
267
268 mutex* __thiscall mutex_ctor(mutex*);
269 void __thiscall mutex_dtor(mutex*);
270 void __thiscall mutex_lock(mutex*);
271 void __thiscall mutex_unlock(mutex*);