2003-03-18 19:26:05 +01:00
|
|
|
/*
|
|
|
|
* msvcrt C++ exception handling
|
|
|
|
*
|
|
|
|
* Copyright 2002 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-03-18 19:26:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MSVCRT_CPPEXCEPT_H
|
|
|
|
#define __MSVCRT_CPPEXCEPT_H
|
|
|
|
|
2010-04-13 17:21:06 +02:00
|
|
|
#define CXX_FRAME_MAGIC_VC6 0x19930520
|
|
|
|
#define CXX_FRAME_MAGIC_VC7 0x19930521
|
|
|
|
#define CXX_FRAME_MAGIC_VC8 0x19930522
|
|
|
|
#define CXX_EXCEPTION 0xe06d7363
|
2003-03-18 19:26:05 +01:00
|
|
|
|
2009-10-06 12:18:50 +02:00
|
|
|
typedef void (*vtable_ptr)(void);
|
2003-03-18 19:26:05 +01:00
|
|
|
|
2008-04-08 23:22:43 +02:00
|
|
|
/* type_info object, see cpp.c for implementation */
|
2003-03-18 19:26:05 +01:00
|
|
|
typedef struct __type_info
|
|
|
|
{
|
2004-10-19 06:03:07 +02:00
|
|
|
const vtable_ptr *vtable;
|
|
|
|
char *name; /* Unmangled name, allocated lazily */
|
|
|
|
char mangled[32]; /* Variable length, but we declare it large enough for static RTTI */
|
2003-03-18 19:26:05 +01:00
|
|
|
} type_info;
|
|
|
|
|
2004-10-19 06:03:07 +02:00
|
|
|
/* exception object */
|
|
|
|
typedef struct __exception
|
|
|
|
{
|
|
|
|
const vtable_ptr *vtable;
|
|
|
|
char *name; /* Name of this exception, always a new copy for each object */
|
|
|
|
int do_free; /* Whether to free 'name' in our dtor */
|
|
|
|
} exception;
|
|
|
|
|
2003-03-18 19:26:05 +01:00
|
|
|
/* the exception frame used by CxxFrameHandler */
|
|
|
|
typedef struct __cxx_exception_frame
|
|
|
|
{
|
2003-08-28 05:07:56 +02:00
|
|
|
EXCEPTION_REGISTRATION_RECORD frame; /* the standard exception frame */
|
|
|
|
int trylevel;
|
|
|
|
DWORD ebp;
|
2003-03-18 19:26:05 +01:00
|
|
|
} cxx_exception_frame;
|
|
|
|
|
|
|
|
/* info about a single catch {} block */
|
|
|
|
typedef struct __catchblock_info
|
|
|
|
{
|
2006-12-15 13:41:31 +01:00
|
|
|
UINT flags; /* flags (see below) */
|
|
|
|
const type_info *type_info; /* C++ type caught by this block */
|
|
|
|
int offset; /* stack offset to copy exception object to */
|
2009-10-06 12:18:50 +02:00
|
|
|
void (*handler)(void);/* catch block handler code */
|
2003-03-18 19:26:05 +01:00
|
|
|
} catchblock_info;
|
|
|
|
#define TYPE_FLAG_CONST 1
|
|
|
|
#define TYPE_FLAG_VOLATILE 2
|
|
|
|
#define TYPE_FLAG_REFERENCE 8
|
|
|
|
|
|
|
|
/* info about a single try {} block */
|
|
|
|
typedef struct __tryblock_info
|
|
|
|
{
|
2006-12-15 13:41:31 +01:00
|
|
|
int start_level; /* start trylevel of that block */
|
|
|
|
int end_level; /* end trylevel of that block */
|
|
|
|
int catch_level; /* initial trylevel of the catch block */
|
|
|
|
int catchblock_count; /* count of catch blocks in array */
|
|
|
|
const catchblock_info *catchblock; /* array of catch blocks */
|
2003-03-18 19:26:05 +01:00
|
|
|
} tryblock_info;
|
|
|
|
|
|
|
|
/* info about the unwind handler for a given trylevel */
|
|
|
|
typedef struct __unwind_info
|
|
|
|
{
|
|
|
|
int prev; /* prev trylevel unwind handler, to run after this one */
|
2009-10-06 12:18:50 +02:00
|
|
|
void (*handler)(void);/* unwind handler */
|
2003-03-18 19:26:05 +01:00
|
|
|
} unwind_info;
|
|
|
|
|
|
|
|
/* descriptor of all try blocks of a given function */
|
|
|
|
typedef struct __cxx_function_descr
|
|
|
|
{
|
2006-12-15 13:41:31 +01:00
|
|
|
UINT magic; /* must be CXX_FRAME_MAGIC */
|
|
|
|
UINT unwind_count; /* number of unwind handlers */
|
|
|
|
const unwind_info *unwind_table; /* array of unwind handlers */
|
|
|
|
UINT tryblock_count; /* number of try blocks */
|
|
|
|
const tryblock_info *tryblock; /* array of try blocks */
|
2010-04-13 17:21:06 +02:00
|
|
|
UINT ipmap_count;
|
|
|
|
const void *ipmap;
|
|
|
|
const void *expect_list; /* expected exceptions list when magic >= VC7 */
|
|
|
|
UINT flags; /* flags when magic >= VC8 */
|
2003-03-18 19:26:05 +01:00
|
|
|
} cxx_function_descr;
|
|
|
|
|
2010-04-13 17:21:06 +02:00
|
|
|
#define FUNC_DESCR_SYNCHRONOUS 1 /* synchronous exceptions only (built with /EHs) */
|
|
|
|
|
2003-03-18 19:26:05 +01:00
|
|
|
typedef void (*cxx_copy_ctor)(void);
|
|
|
|
|
2004-10-19 01:13:55 +02:00
|
|
|
/* offsets for computing the this pointer */
|
|
|
|
typedef struct
|
2003-03-18 19:26:05 +01:00
|
|
|
{
|
|
|
|
int this_offset; /* offset of base class this pointer from start of object */
|
|
|
|
int vbase_descr; /* offset of virtual base class descriptor */
|
|
|
|
int vbase_offset; /* offset of this pointer offset in virtual base class descriptor */
|
2004-10-19 01:13:55 +02:00
|
|
|
} this_ptr_offsets;
|
|
|
|
|
|
|
|
/* complete information about a C++ type */
|
|
|
|
typedef struct __cxx_type_info
|
|
|
|
{
|
|
|
|
UINT flags; /* flags (see CLASS_* flags below) */
|
2004-10-19 06:03:07 +02:00
|
|
|
const type_info *type_info; /* C++ type info */
|
2004-10-19 01:13:55 +02:00
|
|
|
this_ptr_offsets offsets; /* offsets for computing the this pointer */
|
2006-06-13 14:14:06 +02:00
|
|
|
unsigned int size; /* object size */
|
2004-10-19 01:13:55 +02:00
|
|
|
cxx_copy_ctor copy_ctor; /* copy constructor */
|
2003-03-18 19:26:05 +01:00
|
|
|
} cxx_type_info;
|
|
|
|
#define CLASS_IS_SIMPLE_TYPE 1
|
|
|
|
#define CLASS_HAS_VIRTUAL_BASE_CLASS 4
|
|
|
|
|
|
|
|
/* table of C++ types that apply for a given object */
|
|
|
|
typedef struct __cxx_type_info_table
|
|
|
|
{
|
|
|
|
UINT count; /* number of types */
|
|
|
|
const cxx_type_info *info[3]; /* variable length, we declare it large enough for static RTTI */
|
|
|
|
} cxx_type_info_table;
|
|
|
|
|
|
|
|
typedef DWORD (*cxx_exc_custom_handler)( PEXCEPTION_RECORD, cxx_exception_frame*,
|
2003-08-28 05:07:56 +02:00
|
|
|
PCONTEXT, EXCEPTION_REGISTRATION_RECORD**,
|
2006-12-15 13:41:31 +01:00
|
|
|
const cxx_function_descr*, int nested_trylevel,
|
2003-08-28 05:07:56 +02:00
|
|
|
EXCEPTION_REGISTRATION_RECORD *nested_frame, DWORD unknown3 );
|
2003-03-18 19:26:05 +01:00
|
|
|
|
|
|
|
/* type information for an exception object */
|
|
|
|
typedef struct __cxx_exception_type
|
|
|
|
{
|
|
|
|
UINT flags; /* TYPE_FLAG flags */
|
2009-10-06 12:18:50 +02:00
|
|
|
void (*destructor)(void);/* exception object destructor */
|
2003-03-18 19:26:05 +01:00
|
|
|
cxx_exc_custom_handler custom_handler; /* custom handler for this exception */
|
|
|
|
const cxx_type_info_table *type_info_table; /* list of types for this exception object */
|
|
|
|
} cxx_exception_type;
|
|
|
|
|
2011-05-14 10:40:16 +02:00
|
|
|
void WINAPI _CxxThrowException(exception*,const cxx_exception_type*);
|
2008-03-11 16:14:44 +01:00
|
|
|
int CDECL _XcptFilter(NTSTATUS, PEXCEPTION_POINTERS);
|
|
|
|
int CDECL __CppXcptFilter(NTSTATUS, PEXCEPTION_POINTERS);
|
2004-10-19 06:03:07 +02:00
|
|
|
|
2004-10-19 01:13:55 +02:00
|
|
|
static inline const char *dbgstr_type_info( const type_info *info )
|
|
|
|
{
|
|
|
|
if (!info) return "{}";
|
|
|
|
return wine_dbg_sprintf( "{vtable=%p name=%s (%s)}",
|
|
|
|
info->vtable, info->mangled, info->name ? info->name : "" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute the this pointer for a base class of a given type */
|
|
|
|
static inline void *get_this_pointer( const this_ptr_offsets *off, void *object )
|
|
|
|
{
|
|
|
|
void *this_ptr;
|
|
|
|
int *offset_ptr;
|
|
|
|
|
|
|
|
if (!object) return NULL;
|
|
|
|
this_ptr = (char *)object + off->this_offset;
|
|
|
|
if (off->vbase_descr >= 0)
|
|
|
|
{
|
|
|
|
/* move this ptr to vbase descriptor */
|
|
|
|
this_ptr = (char *)this_ptr + off->vbase_descr;
|
|
|
|
/* and fetch additional offset from vbase descriptor */
|
|
|
|
offset_ptr = (int *)(*(char **)this_ptr + off->vbase_offset);
|
|
|
|
this_ptr = (char *)this_ptr + *offset_ptr;
|
|
|
|
}
|
|
|
|
return this_ptr;
|
|
|
|
}
|
|
|
|
|
2003-03-18 19:26:05 +01:00
|
|
|
#endif /* __MSVCRT_CPPEXCEPT_H */
|