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 #define CXX_FRAME_MAGIC 0x19930520
25 #define CXX_EXCEPTION 0xe06d7363
27 typedef void (*vtable_ptr)();
29 /* type_info object, see cpp.c for inplementation */
30 typedef struct __type_info
32 const vtable_ptr *vtable;
33 char *name; /* Unmangled name, allocated lazily */
34 char mangled[32]; /* Variable length, but we declare it large enough for static RTTI */
37 /* exception object */
38 typedef struct __exception
40 const vtable_ptr *vtable;
41 char *name; /* Name of this exception, always a new copy for each object */
42 int do_free; /* Whether to free 'name' in our dtor */
45 /* the exception frame used by CxxFrameHandler */
46 typedef struct __cxx_exception_frame
48 EXCEPTION_REGISTRATION_RECORD frame; /* the standard exception frame */
51 } cxx_exception_frame;
53 /* info about a single catch {} block */
54 typedef struct __catchblock_info
56 UINT flags; /* flags (see below) */
57 const type_info *type_info; /* C++ type caught by this block */
58 int offset; /* stack offset to copy exception object to */
59 void (*handler)(); /* catch block handler code */
61 #define TYPE_FLAG_CONST 1
62 #define TYPE_FLAG_VOLATILE 2
63 #define TYPE_FLAG_REFERENCE 8
65 /* info about a single try {} block */
66 typedef struct __tryblock_info
68 int start_level; /* start trylevel of that block */
69 int end_level; /* end trylevel of that block */
70 int catch_level; /* initial trylevel of the catch block */
71 int catchblock_count; /* count of catch blocks in array */
72 const catchblock_info *catchblock; /* array of catch blocks */
75 /* info about the unwind handler for a given trylevel */
76 typedef struct __unwind_info
78 int prev; /* prev trylevel unwind handler, to run after this one */
79 void (*handler)(); /* unwind handler */
82 /* descriptor of all try blocks of a given function */
83 typedef struct __cxx_function_descr
85 UINT magic; /* must be CXX_FRAME_MAGIC */
86 UINT unwind_count; /* number of unwind handlers */
87 const unwind_info *unwind_table; /* array of unwind handlers */
88 UINT tryblock_count; /* number of try blocks */
89 const tryblock_info *tryblock; /* array of try blocks */
93 typedef void (*cxx_copy_ctor)(void);
95 /* offsets for computing the this pointer */
98 int this_offset; /* offset of base class this pointer from start of object */
99 int vbase_descr; /* offset of virtual base class descriptor */
100 int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
103 /* complete information about a C++ type */
104 typedef struct __cxx_type_info
106 UINT flags; /* flags (see CLASS_* flags below) */
107 const type_info *type_info; /* C++ type info */
108 this_ptr_offsets offsets; /* offsets for computing the this pointer */
109 unsigned int size; /* object size */
110 cxx_copy_ctor copy_ctor; /* copy constructor */
112 #define CLASS_IS_SIMPLE_TYPE 1
113 #define CLASS_HAS_VIRTUAL_BASE_CLASS 4
115 /* table of C++ types that apply for a given object */
116 typedef struct __cxx_type_info_table
118 UINT count; /* number of types */
119 const cxx_type_info *info[3]; /* variable length, we declare it large enough for static RTTI */
120 } cxx_type_info_table;
122 typedef DWORD (*cxx_exc_custom_handler)( PEXCEPTION_RECORD, cxx_exception_frame*,
123 PCONTEXT, EXCEPTION_REGISTRATION_RECORD**,
124 const cxx_function_descr*, int nested_trylevel,
125 EXCEPTION_REGISTRATION_RECORD *nested_frame, DWORD unknown3 );
127 /* type information for an exception object */
128 typedef struct __cxx_exception_type
130 UINT flags; /* TYPE_FLAG flags */
131 void (*destructor)(); /* exception object destructor */
132 cxx_exc_custom_handler custom_handler; /* custom handler for this exception */
133 const cxx_type_info_table *type_info_table; /* list of types for this exception object */
134 } cxx_exception_type;
136 void _CxxThrowException(exception*,const cxx_exception_type*);
138 /* get the vtable pointer for a C++ object */
139 static inline const vtable_ptr *get_vtable( void *obj )
141 return *(const vtable_ptr **)obj;
144 static inline const char *dbgstr_type_info( const type_info *info )
146 if (!info) return "{}";
147 return wine_dbg_sprintf( "{vtable=%p name=%s (%s)}",
148 info->vtable, info->mangled, info->name ? info->name : "" );
151 /* compute the this pointer for a base class of a given type */
152 static inline void *get_this_pointer( const this_ptr_offsets *off, void *object )
157 if (!object) return NULL;
158 this_ptr = (char *)object + off->this_offset;
159 if (off->vbase_descr >= 0)
161 /* move this ptr to vbase descriptor */
162 this_ptr = (char *)this_ptr + off->vbase_descr;
163 /* and fetch additional offset from vbase descriptor */
164 offset_ptr = (int *)(*(char **)this_ptr + off->vbase_offset);
165 this_ptr = (char *)this_ptr + *offset_ptr;
170 #endif /* __MSVCRT_CPPEXCEPT_H */