msvcp90: Added set_new_handler 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 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 __ASM_VTABLE(name,funcs) \
70     __asm__(".data\n" \
71             "\t.align 8\n" \
72             "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
73             "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
74             __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
75             "\t.quad " THISCALL_NAME(MSVCP_ ## name ## _vector_dtor) "\n" \
76             funcs "\n\t.text");
77
78 #else
79
80 #define __ASM_VTABLE(name,funcs) \
81     __asm__(".data\n" \
82             "\t.align 4\n" \
83             "\t.long " __ASM_NAME(#name "_rtti") "\n" \
84             "\t.globl " __ASM_NAME("MSVCP_" #name "_vtable") "\n" \
85             __ASM_NAME("MSVCP_" #name "_vtable") ":\n" \
86             "\t.long " THISCALL_NAME(MSVCP_ ## name ## _vector_dtor) "\n" \
87             funcs "\n\t.text");
88
89 #endif /* _WIN64 */
90
91 /* exception object */
92 typedef void (*vtable_ptr)(void);
93 typedef struct __exception
94 {
95     const vtable_ptr *vtable;
96     char             *name;    /* Name of this exception, always a new copy for each object */
97     int               do_free; /* Whether to free 'name' in our dtor */
98 } exception;
99
100 /* Internal: throws selected exception */
101 typedef enum __exception_type {
102     EXCEPTION,
103     EXCEPTION_BAD_ALLOC,
104     EXCEPTION_LOGIC_ERROR,
105     EXCEPTION_LENGTH_ERROR,
106     EXCEPTION_OUT_OF_RANGE,
107     EXCEPTION_INVALID_ARGUMENT
108 } exception_type;
109 void throw_exception(exception_type, const char *);
110 void set_exception_vtable(void);
111
112 /* rtti */
113 typedef struct __type_info
114 {
115     const vtable_ptr *vtable;
116     char              *name;        /* Unmangled name, allocated lazily */
117     char               mangled[64]; /* Variable length, but we declare it large enough for static RTTI */
118 } type_info;
119
120 /* offsets for computing the this pointer */
121 typedef struct
122 {
123     int         this_offset;   /* offset of base class this pointer from start of object */
124     int         vbase_descr;   /* offset of virtual base class descriptor */
125     int         vbase_offset;  /* offset of this pointer offset in virtual base class descriptor */
126 } this_ptr_offsets;
127
128 typedef struct _rtti_base_descriptor
129 {
130     const type_info *type_descriptor;
131     int num_base_classes;
132     this_ptr_offsets offsets;    /* offsets for computing the this pointer */
133     unsigned int attributes;
134 } rtti_base_descriptor;
135
136 typedef struct _rtti_base_array
137 {
138     const rtti_base_descriptor *bases[4]; /* First element is the class itself */
139 } rtti_base_array;
140
141 typedef struct _rtti_object_hierarchy
142 {
143     unsigned int signature;
144     unsigned int attributes;
145     int array_len; /* Size of the array pointed to by 'base_classes' */
146     const rtti_base_array *base_classes;
147 } rtti_object_hierarchy;
148
149 typedef struct _rtti_object_locator
150 {
151     unsigned int signature;
152     int base_class_offset;
153     unsigned int flags;
154     const type_info *type_descriptor;
155     const rtti_object_hierarchy *type_hierarchy;
156 } rtti_object_locator;
157
158 /* basic_string<char, char_traits<char>, allocator<char>> */
159 #define BUF_SIZE_CHAR 16
160 typedef struct _basic_string_char
161 {
162     void *allocator;
163     union {
164         char buf[BUF_SIZE_CHAR];
165         char *ptr;
166     } data;
167     MSVCP_size_t size;
168     MSVCP_size_t res;
169 } basic_string_char;
170
171 basic_string_char* __stdcall MSVCP_basic_string_char_ctor_cstr(basic_string_char*, const char*);
172 basic_string_char* __stdcall MSVCP_basic_string_char_copy_ctor(basic_string_char*, const basic_string_char*);
173 void __stdcall MSVCP_basic_string_char_dtor(basic_string_char*);
174 const char* __stdcall MSVCP_basic_string_char_c_str(basic_string_char*);
175
176 #define BUF_SIZE_WCHAR 8
177 typedef struct _basic_string_wchar
178 {
179     void *allocator;
180     union {
181         wchar_t buf[BUF_SIZE_WCHAR];
182         wchar_t *ptr;
183     } data;
184     MSVCP_size_t size;
185     MSVCP_size_t res;
186 } basic_string_wchar;
187
188 char* __stdcall MSVCP_allocator_char_allocate(void*, MSVCP_size_t);
189 void __stdcall MSVCP_allocator_char_deallocate(void*, char*, MSVCP_size_t);
190 wchar_t* __stdcall MSVCP_allocator_wchar_allocate(void*, MSVCP_size_t);
191 void __stdcall MSVCP_allocator_wchar_deallocate(void*, wchar_t*, MSVCP_size_t);
192
193 /* class locale */
194 typedef struct
195 {
196     struct locale__Locimp *ptr;
197 } locale;
198
199 locale* __thiscall locale_ctor(locale*);
200 void __thiscall locale_dtor(locale*);
201
202 /* class _Lockit */
203 typedef struct {
204     int locktype;
205 } _Lockit;
206
207 #define _LOCK_LOCALE 0
208 #define _LOCK_MALLOC 1
209 #define _LOCK_STREAM 2
210 #define _LOCK_DEBUG 3
211 #define _MAX_LOCK 4
212
213 void init_lockit(void);
214 void free_lockit(void);
215 _Lockit* __thiscall _Lockit_ctor_locktype(_Lockit*, int);
216 void __thiscall _Lockit_dtor(_Lockit*);
217
218 /* class mutex */
219 typedef struct {
220         void *mutex;
221 } mutex;
222
223 mutex* __thiscall mutex_ctor(mutex*);
224 void __thiscall mutex_dtor(mutex*);
225 void __thiscall mutex_lock(mutex*);
226 void __thiscall mutex_unlock(mutex*);