Samuel SerapiĆ³n (samdwise51 AT gmail DOT com):
[reactos.git] / reactos / lib / sdk / crt / include / internal / wine / cppexcept.h
1 /*
2 * msvcrt C++ exception handling
3 *
4 * Copyright 2002 Alexandre Julliard
5 *
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.
10 *
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.
15 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef __MSVCRT_CPPEXCEPT_H
22 #define __MSVCRT_CPPEXCEPT_H
23
24 #define CXX_FRAME_MAGIC 0x19930520
25 #define CXX_EXCEPTION 0xe06d7363
26
27 typedef void (*vtable_ptr)();
28
29 /* type_info object, see cpp.c for inplementation */
30 typedef struct __type_info
31 {
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 */
35 } type_info;
36
37 /* exception object */
38 typedef struct __exception
39 {
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 */
43 } exception;
44
45 /* the exception frame used by CxxFrameHandler */
46 typedef struct __cxx_exception_frame
47 {
48 EXCEPTION_REGISTRATION_RECORD frame; /* the standard exception frame */
49 int trylevel;
50 DWORD ebp;
51 } cxx_exception_frame;
52
53 /* info about a single catch {} block */
54 typedef struct __catchblock_info
55 {
56 UINT flags; /* flags (see below) */
57 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 */
60 } catchblock_info;
61 #define TYPE_FLAG_CONST 1
62 #define TYPE_FLAG_VOLATILE 2
63 #define TYPE_FLAG_REFERENCE 8
64
65 /* info about a single try {} block */
66 typedef struct __tryblock_info
67 {
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 catchblock_info *catchblock; /* array of catch blocks */
73 } tryblock_info;
74
75 /* info about the unwind handler for a given trylevel */
76 typedef struct __unwind_info
77 {
78 int prev; /* prev trylevel unwind handler, to run after this one */
79 void (*handler)(); /* unwind handler */
80 } unwind_info;
81
82 /* descriptor of all try blocks of a given function */
83 typedef struct __cxx_function_descr
84 {
85 UINT magic; /* must be CXX_FRAME_MAGIC */
86 UINT unwind_count; /* number of unwind handlers */
87 unwind_info *unwind_table; /* array of unwind handlers */
88 UINT tryblock_count; /* number of try blocks */
89 tryblock_info *tryblock; /* array of try blocks */
90 UINT unknown[3];
91 } cxx_function_descr;
92
93 typedef void (*cxx_copy_ctor)(void);
94
95 /* offsets for computing the this pointer */
96 typedef struct
97 {
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 */
101 } this_ptr_offsets;
102
103 /* complete information about a C++ type */
104 typedef struct __cxx_type_info
105 {
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 */
111 } cxx_type_info;
112 #define CLASS_IS_SIMPLE_TYPE 1
113 #define CLASS_HAS_VIRTUAL_BASE_CLASS 4
114
115 /* table of C++ types that apply for a given object */
116 typedef struct __cxx_type_info_table
117 {
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;
121
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 );
126
127 /* type information for an exception object */
128 typedef struct __cxx_exception_type
129 {
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;
135
136 void _CxxThrowException(exception*,const cxx_exception_type*);
137
138 static inline const char *dbgstr_type_info( const type_info *info )
139 {
140 if (!info) return "{}";
141 return "{}";/*sprintf( "{vtable=%p name=%s (%s)}",
142 info->vtable, info->mangled, info->name ? info->name : "" );*/
143 }
144
145 /* compute the this pointer for a base class of a given type */
146 static inline void *get_this_pointer( const this_ptr_offsets *off, void *object )
147 {
148 void *this_ptr;
149 int *offset_ptr;
150
151 if (!object) return NULL;
152 this_ptr = (char *)object + off->this_offset;
153 if (off->vbase_descr >= 0)
154 {
155 /* move this ptr to vbase descriptor */
156 this_ptr = (char *)this_ptr + off->vbase_descr;
157 /* and fetch additional offset from vbase descriptor */
158 offset_ptr = (int *)(*(char **)this_ptr + off->vbase_offset);
159 this_ptr = (char *)this_ptr + *offset_ptr;
160 }
161 return this_ptr;
162 }
163
164 #endif /* __MSVCRT_CPPEXCEPT_H */