ReactOS  0.4.15-dev-3453-gff89651
cppexcept.h
Go to the documentation of this file.
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 /* Macros to define assembler functions somewhat portably */
30 
31 #define EH_NONCONTINUABLE 0x01
32 #define EH_UNWINDING 0x02
33 #define EH_EXIT_UNWIND 0x04
34 #define EH_STACK_INVALID 0x08
35 #define EH_NESTED_CALL 0x10
36 
37 typedef void (*vtable_ptr)();
38 
39 /* type_info object, see cpp.c for inplementation */
40 typedef struct __type_info
41 {
43  char *name; /* Unmangled name, allocated lazily */
44  char mangled[32]; /* Variable length, but we declare it large enough for static RTTI */
45 } type_info;
46 
47 /* exception object */
48 typedef struct __exception
49 {
51  char *name; /* Name of this exception, always a new copy for each object */
52  int do_free; /* Whether to free 'name' in our dtor */
53 } exception;
54 
55 /* the exception frame used by CxxFrameHandler */
56 typedef struct __cxx_exception_frame
57 {
58  EXCEPTION_REGISTRATION_RECORD frame; /* the standard exception frame */
59  int trylevel;
62 
63 /* info about a single catch {} block */
64 typedef struct __catchblock_info
65 {
66  UINT flags; /* flags (see below) */
67  const type_info *type_info; /* C++ type caught by this block */
68  int offset; /* stack offset to copy exception object to */
69  void (*handler)(void);/* catch block handler code */
71 #define TYPE_FLAG_CONST 1
72 #define TYPE_FLAG_VOLATILE 2
73 #define TYPE_FLAG_REFERENCE 8
74 
75 /* info about a single try {} block */
76 typedef struct __tryblock_info
77 {
78  int start_level; /* start trylevel of that block */
79  int end_level; /* end trylevel of that block */
80  int catch_level; /* initial trylevel of the catch block */
81  int catchblock_count; /* count of catch blocks in array */
82  const catchblock_info *catchblock; /* array of catch blocks */
84 
85 /* info about the unwind handler for a given trylevel */
86 typedef struct __unwind_info
87 {
88  int prev; /* prev trylevel unwind handler, to run after this one */
89  void (*handler)(void);/* unwind handler */
90 } unwind_info;
91 
92 /* descriptor of all try blocks of a given function */
93 typedef struct __cxx_function_descr
94 {
95  UINT magic; /* must be CXX_FRAME_MAGIC */
96  UINT unwind_count; /* number of unwind handlers */
97  const unwind_info *unwind_table; /* array of unwind handlers */
98  UINT tryblock_count; /* number of try blocks */
99  const tryblock_info *tryblock; /* array of try blocks */
101  const void *ipmap;
102  const void *expect_list; /* expected exceptions list when magic >= VC7 */
103  UINT flags; /* flags when magic >= VC8 */
105 
106 #define FUNC_DESCR_SYNCHRONOUS 1 /* synchronous exceptions only (built with /EHs) */
107 
108 typedef void (*cxx_copy_ctor)(void);
109 
110 /* offsets for computing the this pointer */
111 typedef struct
112 {
113  int this_offset; /* offset of base class this pointer from start of object */
114  int vbase_descr; /* offset of virtual base class descriptor */
115  int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
117 
118 /* complete information about a C++ type */
119 typedef struct __cxx_type_info
120 {
121  UINT flags; /* flags (see CLASS_* flags below) */
122  const type_info *type_info; /* C++ type info */
123  this_ptr_offsets offsets; /* offsets for computing the this pointer */
124  unsigned int size; /* object size */
125  cxx_copy_ctor copy_ctor; /* copy constructor */
126 } cxx_type_info;
127 #define CLASS_IS_SIMPLE_TYPE 1
128 #define CLASS_HAS_VIRTUAL_BASE_CLASS 4
129 
130 /* table of C++ types that apply for a given object */
131 typedef struct __cxx_type_info_table
132 {
133  UINT count; /* number of types */
134  const cxx_type_info *info[3]; /* variable length, we declare it large enough for static RTTI */
136 
139  const cxx_function_descr*, int nested_trylevel,
140  EXCEPTION_REGISTRATION_RECORD *nested_frame, DWORD unknown3 );
141 
142 /* type information for an exception object */
143 typedef struct __cxx_exception_type
144 {
145  UINT flags; /* TYPE_FLAG flags */
146  void (*destructor)(void);/* exception object destructor */
147  cxx_exc_custom_handler custom_handler; /* custom handler for this exception */
148  const cxx_type_info_table *type_info_table; /* list of types for this exception object */
150 
154 
155 static inline const char *dbgstr_type_info( const type_info *info )
156 {
157  if (!info) return "{}";
158  return wine_dbg_sprintf( "{vtable=%p name=%s (%s)}",
159  info->vtable, info->mangled, info->name ? info->name : "" );
160 }
161 
162 /* compute the this pointer for a base class of a given type */
163 static inline void *get_this_pointer( const this_ptr_offsets *off, void *object )
164 {
165  if (!object) return NULL;
166 
167  if (off->vbase_descr >= 0)
168  {
169  int *offset_ptr;
170 
171  /* move this ptr to vbase descriptor */
172  object = (char *)object + off->vbase_descr;
173  /* and fetch additional offset from vbase descriptor */
174  offset_ptr = (int *)(*(char **)object + off->vbase_offset);
175  object = (char *)object + *offset_ptr;
176  }
177 
178  object = (char *)object + off->this_offset;
179  return object;
180 }
181 
182 #endif /* __MSVCRT_CPPEXCEPT_H */
struct _EXCEPTION_RECORD * PEXCEPTION_RECORD
void(* handler)(void)
Definition: cppexcept.h:89
void(* cxx_copy_ctor)(void)
Definition: cppexcept.h:108
void WINAPI _CxxThrowException(exception *, const cxx_exception_type *)
Definition: cpp.c:1574
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
const type_info * type_info
Definition: cppexcept.h:122
struct __cxx_function_descr cxx_function_descr
LONG NTSTATUS
Definition: precomp.h:26
const unwind_info * unwind_table
Definition: cppexcept.h:97
int catchblock_count
Definition: cppexcept.h:81
const vtable_ptr * vtable
Definition: cppexcept.h:42
#define DWORD
Definition: nt_native.h:44
const catchblock_info * catchblock
Definition: cppexcept.h:82
struct __cxx_type_info cxx_type_info
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:296
char mangled[16]
Definition: cpp.c:36
struct __tryblock_info tryblock_info
static void * get_this_pointer(const this_ptr_offsets *off, void *object)
Definition: cppexcept.h:163
char * name
Definition: cpp.c:35
this_ptr_offsets offsets
Definition: cppexcept.h:123
cxx_exc_custom_handler custom_handler
Definition: cppexcept.h:147
int CDECL __CppXcptFilter(NTSTATUS, PEXCEPTION_POINTERS)
const void * expect_list
Definition: cppexcept.h:102
void(* destructor)(void)
Definition: cppexcept.h:146
DWORD(* cxx_exc_custom_handler)(PEXCEPTION_RECORD, cxx_exception_frame *, PCONTEXT, EXCEPTION_REGISTRATION_RECORD **, const cxx_function_descr *, int nested_trylevel, EXCEPTION_REGISTRATION_RECORD *nested_frame, DWORD unknown3)
Definition: cppexcept.h:137
EXCEPTION_REGISTRATION_RECORD frame
Definition: cppexcept.h:58
struct __catchblock_info catchblock_info
#define WINAPI
Definition: msvc.h:6
void(* handler)(void)
Definition: cppexcept.h:69
unsigned long DWORD
Definition: ntddk_ex.h:95
const type_info * type_info
Definition: cppexcept.h:67
void(* vtable_ptr)()
Definition: cppexcept.h:37
unsigned int size
Definition: cppexcept.h:124
cxx_copy_ctor copy_ctor
Definition: cppexcept.h:125
struct __cxx_exception_frame cxx_exception_frame
struct __type_info type_info
struct __unwind_info unwind_info
struct __cxx_exception_type cxx_exception_type
struct __exception exception
static const char * dbgstr_type_info(const type_info *info)
Definition: cppexcept.h:155
char * name
Definition: cpp.c:28
#define CDECL
Definition: compat.h:29
const cxx_type_info_table * type_info_table
Definition: cppexcept.h:148
const void * ipmap
Definition: cppexcept.h:101
int do_free
Definition: cpp.c:29
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
CONTEXT * PCONTEXT
Definition: compat.h:558
int CDECL _XcptFilter(NTSTATUS, PEXCEPTION_POINTERS)
Definition: except.c:274
const tryblock_info * tryblock
Definition: cppexcept.h:99
const vtable_ptr * vtable
Definition: cppexcept.h:50
struct __cxx_type_info_table cxx_type_info_table