dwrite: Always initialize output glyph count in GetGlyphs().
[wine.git] / dlls / msvcrt / cppexcept.h
blob5170bf23fa2b77948f300a1e9cde10a17e0c3bee
1 /*
2 * msvcrt C++ exception handling
4 * Copyright 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __MSVCRT_CPPEXCEPT_H
22 #define __MSVCRT_CPPEXCEPT_H
24 #include "wine/asm.h"
26 #define CXX_FRAME_MAGIC_VC6 0x19930520
27 #define CXX_FRAME_MAGIC_VC7 0x19930521
28 #define CXX_FRAME_MAGIC_VC8 0x19930522
29 #define CXX_EXCEPTION 0xe06d7363
31 #define FUNC_DESCR_SYNCHRONOUS 1 /* synchronous exceptions only (built with /EHs and /EHsc) */
32 #define FUNC_DESCR_NOEXCEPT 4 /* noexcept function */
34 typedef void (*vtable_ptr)(void);
36 /* type_info object, see cpp.c for implementation */
37 typedef struct __type_info
39 const vtable_ptr *vtable;
40 char *name; /* Unmangled name, allocated lazily */
41 char mangled[64]; /* Variable length, but we declare it large enough for static RTTI */
42 } type_info;
44 /* exception object */
45 typedef struct __exception
47 const vtable_ptr *vtable;
48 char *name; /* Name of this exception, always a new copy for each object */
49 BOOL do_free; /* Whether to free 'name' in our dtor */
50 } exception;
52 typedef void (*cxx_copy_ctor)(void);
54 /* offsets for computing the this pointer */
55 typedef struct
57 int this_offset; /* offset of base class this pointer from start of object */
58 int vbase_descr; /* offset of virtual base class descriptor */
59 int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
60 } this_ptr_offsets;
62 /* complete information about a C++ type */
63 #ifndef __x86_64__
64 typedef struct __cxx_type_info
66 UINT flags; /* flags (see CLASS_* flags below) */
67 const type_info *type_info; /* C++ type info */
68 this_ptr_offsets offsets; /* offsets for computing the this pointer */
69 unsigned int size; /* object size */
70 cxx_copy_ctor copy_ctor; /* copy constructor */
71 } cxx_type_info;
72 #else
73 typedef struct __cxx_type_info
75 UINT flags;
76 unsigned int type_info;
77 this_ptr_offsets offsets;
78 unsigned int size;
79 unsigned int copy_ctor;
80 } cxx_type_info;
81 #endif
83 #define CLASS_IS_SIMPLE_TYPE 1
84 #define CLASS_HAS_VIRTUAL_BASE_CLASS 4
86 /* table of C++ types that apply for a given object */
87 #ifndef __x86_64__
88 typedef struct __cxx_type_info_table
90 UINT count; /* number of types */
91 const cxx_type_info *info[3]; /* variable length, we declare it large enough for static RTTI */
92 } cxx_type_info_table;
93 #else
94 typedef struct __cxx_type_info_table
96 UINT count;
97 unsigned int info[3];
98 } cxx_type_info_table;
99 #endif
101 struct __cxx_exception_frame;
102 struct __cxx_function_descr;
104 typedef DWORD (*cxx_exc_custom_handler)( PEXCEPTION_RECORD, struct __cxx_exception_frame*,
105 PCONTEXT, EXCEPTION_REGISTRATION_RECORD**,
106 const struct __cxx_function_descr*, int nested_trylevel,
107 EXCEPTION_REGISTRATION_RECORD *nested_frame, DWORD unknown3 );
109 /* type information for an exception object */
110 #ifndef __x86_64__
111 typedef struct __cxx_exception_type
113 UINT flags; /* TYPE_FLAG flags */
114 void (*destructor)(void);/* exception object destructor */
115 cxx_exc_custom_handler custom_handler; /* custom handler for this exception */
116 const cxx_type_info_table *type_info_table; /* list of types for this exception object */
117 } cxx_exception_type;
118 #else
119 typedef struct
121 UINT flags;
122 unsigned int destructor;
123 unsigned int custom_handler;
124 unsigned int type_info_table;
125 } cxx_exception_type;
126 #endif
128 void WINAPI _CxxThrowException(exception*,const cxx_exception_type*);
129 int CDECL _XcptFilter(NTSTATUS, PEXCEPTION_POINTERS);
131 static inline const char *dbgstr_type_info( const type_info *info )
133 if (!info) return "{}";
134 return wine_dbg_sprintf( "{vtable=%p name=%s (%s)}",
135 info->vtable, info->mangled, info->name ? info->name : "" );
138 /* compute the this pointer for a base class of a given type */
139 static inline void *get_this_pointer( const this_ptr_offsets *off, void *object )
141 if (!object) return NULL;
143 if (off->vbase_descr >= 0)
145 int *offset_ptr;
147 /* move this ptr to vbase descriptor */
148 object = (char *)object + off->vbase_descr;
149 /* and fetch additional offset from vbase descriptor */
150 offset_ptr = (int *)(*(char **)object + off->vbase_offset);
151 object = (char *)object + *offset_ptr;
154 object = (char *)object + off->this_offset;
155 return object;
158 #ifndef __x86_64__
159 #define DEFINE_EXCEPTION_TYPE_INFO(type, base_no, cl1, cl2) \
161 static const cxx_type_info type ## _cxx_type_info = { \
162 0, \
163 & type ##_type_info, \
164 { 0, -1, 0 }, \
165 sizeof(type), \
166 (cxx_copy_ctor)THISCALL(type ##_copy_ctor) \
167 }; \
169 static const cxx_type_info_table type ## _type_info_table = { \
170 base_no+1, \
172 & type ## _cxx_type_info, \
173 cl1, \
174 cl2 \
176 }; \
178 static const cxx_exception_type type ## _exception_type = { \
179 0, \
180 (cxx_copy_ctor)THISCALL(type ## _dtor), \
181 NULL, \
182 & type ## _type_info_table \
185 #else
187 #define DEFINE_EXCEPTION_TYPE_INFO(type, base_no, cl1, cl2) \
189 static cxx_type_info type ## _cxx_type_info = { \
190 0, \
191 0xdeadbeef, \
192 { 0, -1, 0 }, \
193 sizeof(type), \
194 0xdeadbeef \
195 }; \
197 static cxx_type_info_table type ## _type_info_table = { \
198 base_no+1, \
200 0xdeadbeef, \
201 0xdeadbeef, \
202 0xdeadbeef \
204 }; \
206 static cxx_exception_type type ##_exception_type = { \
207 0, \
208 0xdeadbeef, \
209 0, \
210 0xdeadbeef \
211 }; \
213 static void init_ ## type ## _cxx(char *base) \
215 type ## _cxx_type_info.type_info = (char *)&type ## _type_info - base; \
216 type ## _cxx_type_info.copy_ctor = (char *)type ## _copy_ctor - base; \
217 type ## _type_info_table.info[0] = (char *)&type ## _cxx_type_info - base; \
218 type ## _type_info_table.info[1] = (char *)cl1 - base; \
219 type ## _type_info_table.info[2] = (char *)cl2 - base; \
220 type ## _exception_type.destructor = (char *)type ## _dtor - base; \
221 type ## _exception_type.type_info_table = (char *)&type ## _type_info_table - base; \
223 #endif
225 #endif /* __MSVCRT_CPPEXCEPT_H */