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