uxtheme: Remove unused variable.
[wine] / dlls / msvcrt / 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #ifndef __MSVCRT_CPPEXCEPT_H
22 #define __MSVCRT_CPPEXCEPT_H
23
24 #define CXX_FRAME_MAGIC_VC6 0x19930520
25 #define CXX_FRAME_MAGIC_VC7 0x19930521
26 #define CXX_FRAME_MAGIC_VC8 0x19930522
27 #define CXX_EXCEPTION       0xe06d7363
28
29 typedef void (*vtable_ptr)(void);
30
31 /* type_info object, see cpp.c for implementation */
32 typedef struct __type_info
33 {
34   const vtable_ptr *vtable;
35   char              *name;        /* Unmangled name, allocated lazily */
36   char               mangled[32]; /* Variable length, but we declare it large enough for static RTTI */
37 } type_info;
38
39 /* exception object */
40 typedef struct __exception
41 {
42   const vtable_ptr *vtable;
43   char             *name;    /* Name of this exception, always a new copy for each object */
44   int               do_free; /* Whether to free 'name' in our dtor */
45 } exception;
46
47 typedef void (*cxx_copy_ctor)(void);
48
49 /* offsets for computing the this pointer */
50 typedef struct
51 {
52     int         this_offset;   /* offset of base class this pointer from start of object */
53     int         vbase_descr;   /* offset of virtual base class descriptor */
54     int         vbase_offset;  /* offset of this pointer offset in virtual base class descriptor */
55 } this_ptr_offsets;
56
57 /* complete information about a C++ type */
58 #ifndef __x86_64__
59 typedef struct __cxx_type_info
60 {
61     UINT             flags;        /* flags (see CLASS_* flags below) */
62     const type_info *type_info;    /* C++ type info */
63     this_ptr_offsets offsets;      /* offsets for computing the this pointer */
64     unsigned int     size;         /* object size */
65     cxx_copy_ctor    copy_ctor;    /* copy constructor */
66 } cxx_type_info;
67 #else
68 typedef struct __cxx_type_info
69 {
70     UINT flags;
71     unsigned int type_info;
72     this_ptr_offsets offsets;
73     unsigned int size;
74     unsigned int copy_ctor;
75 } cxx_type_info;
76 #endif
77
78 #define CLASS_IS_SIMPLE_TYPE          1
79 #define CLASS_HAS_VIRTUAL_BASE_CLASS  4
80
81 /* table of C++ types that apply for a given object */
82 #ifndef __x86_64__
83 typedef struct __cxx_type_info_table
84 {
85     UINT                 count;     /* number of types */
86     const cxx_type_info *info[3];   /* variable length, we declare it large enough for static RTTI */
87 } cxx_type_info_table;
88 #else
89 typedef struct __cxx_type_info_table
90 {
91     UINT count;
92     unsigned int info[3];
93 } cxx_type_info_table;
94 #endif
95
96 struct __cxx_exception_frame;
97 struct __cxx_function_descr;
98
99 typedef DWORD (*cxx_exc_custom_handler)( PEXCEPTION_RECORD, struct __cxx_exception_frame*,
100                                          PCONTEXT, EXCEPTION_REGISTRATION_RECORD**,
101                                          const struct __cxx_function_descr*, int nested_trylevel,
102                                          EXCEPTION_REGISTRATION_RECORD *nested_frame, DWORD unknown3 );
103
104 /* type information for an exception object */
105 #ifndef __x86_64__
106 typedef struct __cxx_exception_type
107 {
108     UINT                       flags;            /* TYPE_FLAG flags */
109     void                     (*destructor)(void);/* exception object destructor */
110     cxx_exc_custom_handler     custom_handler;   /* custom handler for this exception */
111     const cxx_type_info_table *type_info_table;  /* list of types for this exception object */
112 } cxx_exception_type;
113 #else
114 typedef struct
115 {
116     UINT flags;
117     unsigned int destructor;
118     unsigned int custom_handler;
119     unsigned int type_info_table;
120 } cxx_exception_type;
121 #endif
122
123 void WINAPI _CxxThrowException(exception*,const cxx_exception_type*);
124 int CDECL _XcptFilter(NTSTATUS, PEXCEPTION_POINTERS);
125
126 static inline const char *dbgstr_type_info( const type_info *info )
127 {
128     if (!info) return "{}";
129     return wine_dbg_sprintf( "{vtable=%p name=%s (%s)}",
130                              info->vtable, info->mangled, info->name ? info->name : "" );
131 }
132
133 /* compute the this pointer for a base class of a given type */
134 static inline void *get_this_pointer( const this_ptr_offsets *off, void *object )
135 {
136     void *this_ptr;
137     int *offset_ptr;
138
139     if (!object) return NULL;
140     this_ptr = (char *)object + off->this_offset;
141     if (off->vbase_descr >= 0)
142     {
143         /* move this ptr to vbase descriptor */
144         this_ptr = (char *)this_ptr + off->vbase_descr;
145         /* and fetch additional offset from vbase descriptor */
146         offset_ptr = (int *)(*(char **)this_ptr + off->vbase_offset);
147         this_ptr = (char *)this_ptr + *offset_ptr;
148     }
149     return this_ptr;
150 }
151
152 #ifndef __x86_64__
153 #define DEFINE_EXCEPTION_TYPE_INFO(type, base_no, cl1, cl2)  \
154 \
155 static const cxx_type_info type ## _cxx_type_info = { \
156     0, \
157     & type ##_type_info, \
158     { 0, -1, 0 }, \
159     sizeof(type), \
160     (cxx_copy_ctor)THISCALL(MSVCRT_ ## type ##_copy_ctor) \
161 }; \
162 \
163 static const cxx_type_info_table type ## _type_info_table = { \
164     base_no+1, \
165     { \
166         & type ## _cxx_type_info, \
167         cl1, \
168         cl2 \
169     } \
170 }; \
171 \
172 static const cxx_exception_type type ## _exception_type = { \
173     0, \
174     (cxx_copy_ctor)THISCALL(MSVCRT_ ## type ## _dtor), \
175     NULL, \
176     & type ## _type_info_table \
177 };
178
179 #else
180
181 #define DEFINE_EXCEPTION_TYPE_INFO(type, base_no, cl1, cl2)  \
182 \
183 static cxx_type_info type ## _cxx_type_info = { \
184     0, \
185     0xdeadbeef, \
186     { 0, -1, 0 }, \
187     sizeof(type), \
188     0xdeadbeef \
189 }; \
190 \
191 static cxx_type_info_table type ## _type_info_table = { \
192     base_no+1, \
193     { \
194         0xdeadbeef, \
195         0xdeadbeef, \
196         0xdeadbeef  \
197     } \
198 }; \
199 \
200 static cxx_exception_type type ##_exception_type = { \
201     0, \
202     0xdeadbeef, \
203     0, \
204     0xdeadbeef \
205 }; \
206 \
207 static void init_ ## type ## _cxx(char *base) \
208 { \
209     type ## _cxx_type_info.type_info  = (char *)&type ## _type_info - base; \
210     type ## _cxx_type_info.copy_ctor  = (char *)MSVCRT_ ## type ## _copy_ctor - base; \
211     type ## _type_info_table.info[0]   = (char *)&type ## _cxx_type_info - base; \
212     type ## _type_info_table.info[1]   = (char *)cl1 - base; \
213     type ## _type_info_table.info[2]   = (char *)cl2 - base; \
214     type ## _exception_type.destructor      = (char *)MSVCRT_ ## type ## _dtor - base; \
215     type ## _exception_type.type_info_table = (char *)&type ## _type_info_table - base; \
216 }
217 #endif
218
219 #endif /* __MSVCRT_CPPEXCEPT_H */