2002-07-24 05:02:51 +02: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
|
2002-07-24 05:02:51 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* A good reference is the article "How a C++ compiler implements
|
|
|
|
* exception handling" by Vishal Kochhar, available on
|
|
|
|
* www.thecodeproject.com.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2002-07-24 05:02:51 +02:00
|
|
|
#include "msvcrt.h"
|
|
|
|
#include "wine/exception.h"
|
2002-12-13 00:34:01 +01:00
|
|
|
#include "excpt.h"
|
2002-07-24 05:02:51 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2003-03-18 19:26:05 +01:00
|
|
|
#include "cppexcept.h"
|
2002-07-24 05:02:51 +02:00
|
|
|
|
|
|
|
#ifdef __i386__ /* CxxFrameHandler is not supported on non-i386 */
|
|
|
|
|
2006-12-30 21:57:50 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(seh);
|
|
|
|
|
2006-06-13 11:21:19 +02:00
|
|
|
DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
|
|
|
|
PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
|
2006-12-15 13:41:31 +01:00
|
|
|
const cxx_function_descr *descr,
|
|
|
|
EXCEPTION_REGISTRATION_RECORD* nested_frame, int nested_trylevel );
|
2002-10-31 03:10:15 +01:00
|
|
|
|
2002-07-24 05:02:51 +02:00
|
|
|
/* call a function with a given ebp */
|
|
|
|
inline static void *call_ebp_func( void *func, void *ebp )
|
|
|
|
{
|
|
|
|
void *ret;
|
2006-01-21 19:23:02 +01:00
|
|
|
int dummy;
|
|
|
|
__asm__ __volatile__ ("pushl %%ebx\n\t"
|
|
|
|
"pushl %%ebp\n\t"
|
|
|
|
"movl %4,%%ebp\n\t"
|
|
|
|
"call *%%eax\n\t"
|
|
|
|
"popl %%ebp\n\t"
|
|
|
|
"popl %%ebx"
|
|
|
|
: "=a" (ret), "=S" (dummy), "=D" (dummy)
|
|
|
|
: "0" (func), "1" (ebp) : "ecx", "edx", "memory" );
|
2002-07-24 05:02:51 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call a copy constructor */
|
|
|
|
inline static void call_copy_ctor( void *func, void *this, void *src, int has_vbase )
|
|
|
|
{
|
|
|
|
TRACE( "calling copy ctor %p object %p src %p\n", func, this, src );
|
|
|
|
if (has_vbase)
|
|
|
|
/* in that case copy ctor takes an extra bool indicating whether to copy the base class */
|
|
|
|
__asm__ __volatile__("pushl $1; pushl %2; call *%0"
|
2004-12-02 19:19:25 +01:00
|
|
|
: : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" );
|
2002-07-24 05:02:51 +02:00
|
|
|
else
|
|
|
|
__asm__ __volatile__("pushl %2; call *%0"
|
2004-12-02 19:19:25 +01:00
|
|
|
: : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" );
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* call the destructor of the exception object */
|
|
|
|
inline static void call_dtor( void *func, void *object )
|
|
|
|
{
|
2002-11-01 02:50:51 +01:00
|
|
|
__asm__ __volatile__("call *%0" : : "r" (func), "c" (object) : "eax", "edx", "memory" );
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
|
2006-01-05 13:56:11 +01:00
|
|
|
/* continue execution to the specified address after exception is caught */
|
|
|
|
inline static void DECLSPEC_NORETURN continue_after_catch( cxx_exception_frame* frame, void *addr )
|
|
|
|
{
|
|
|
|
__asm__ __volatile__("movl -4(%0),%%esp; leal 12(%0),%%ebp; jmp *%1"
|
|
|
|
: : "r" (frame), "a" (addr) );
|
|
|
|
for (;;) ; /* unreached */
|
|
|
|
}
|
|
|
|
|
2004-10-19 01:13:55 +02:00
|
|
|
static inline void dump_type( const cxx_type_info *type )
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
2005-09-25 17:23:21 +02:00
|
|
|
TRACE( "flags %x type %p %s offsets %d,%d,%d size %d copy ctor %p\n",
|
2004-10-19 01:13:55 +02:00
|
|
|
type->flags, type->type_info, dbgstr_type_info(type->type_info),
|
|
|
|
type->offsets.this_offset, type->offsets.vbase_descr, type->offsets.vbase_offset,
|
|
|
|
type->size, type->copy_ctor );
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
|
2003-03-18 19:26:05 +01:00
|
|
|
static void dump_exception_type( const cxx_exception_type *type )
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
2003-03-18 19:26:05 +01:00
|
|
|
UINT i;
|
2002-07-24 05:02:51 +02:00
|
|
|
|
2005-09-25 17:23:21 +02:00
|
|
|
TRACE( "flags %x destr %p handler %p type info %p\n",
|
2002-07-24 05:02:51 +02:00
|
|
|
type->flags, type->destructor, type->custom_handler, type->type_info_table );
|
|
|
|
for (i = 0; i < type->type_info_table->count; i++)
|
|
|
|
{
|
2005-09-25 17:23:21 +02:00
|
|
|
TRACE( " %d: ", i );
|
2002-07-24 05:02:51 +02:00
|
|
|
dump_type( type->type_info_table->info[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-15 13:41:31 +01:00
|
|
|
static void dump_function_descr( const cxx_function_descr *descr )
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
2003-03-18 19:26:05 +01:00
|
|
|
UINT i;
|
|
|
|
int j;
|
2002-07-24 05:02:51 +02:00
|
|
|
|
2005-09-25 17:23:21 +02:00
|
|
|
TRACE( "magic %x\n", descr->magic );
|
|
|
|
TRACE( "unwind table: %p %d\n", descr->unwind_table, descr->unwind_count );
|
2002-07-24 05:02:51 +02:00
|
|
|
for (i = 0; i < descr->unwind_count; i++)
|
|
|
|
{
|
2005-09-25 17:23:21 +02:00
|
|
|
TRACE( " %d: prev %d func %p\n", i,
|
2002-07-24 05:02:51 +02:00
|
|
|
descr->unwind_table[i].prev, descr->unwind_table[i].handler );
|
|
|
|
}
|
2005-09-25 17:23:21 +02:00
|
|
|
TRACE( "try table: %p %d\n", descr->tryblock, descr->tryblock_count );
|
2002-07-24 05:02:51 +02:00
|
|
|
for (i = 0; i < descr->tryblock_count; i++)
|
|
|
|
{
|
2005-09-25 17:23:21 +02:00
|
|
|
TRACE( " %d: start %d end %d catchlevel %d catch %p %d\n", i,
|
2002-07-24 05:02:51 +02:00
|
|
|
descr->tryblock[i].start_level, descr->tryblock[i].end_level,
|
|
|
|
descr->tryblock[i].catch_level, descr->tryblock[i].catchblock,
|
|
|
|
descr->tryblock[i].catchblock_count );
|
|
|
|
for (j = 0; j < descr->tryblock[i].catchblock_count; j++)
|
|
|
|
{
|
2006-12-15 13:41:31 +01:00
|
|
|
const catchblock_info *ptr = &descr->tryblock[i].catchblock[j];
|
2005-09-25 17:23:21 +02:00
|
|
|
TRACE( " %d: flags %x offset %d handler %p type %p %s\n",
|
2004-10-19 01:13:55 +02:00
|
|
|
j, ptr->flags, ptr->offset, ptr->handler,
|
|
|
|
ptr->type_info, dbgstr_type_info( ptr->type_info ) );
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if the exception type is caught by a given catch block, and return the type that matched */
|
2006-12-15 13:41:31 +01:00
|
|
|
static const cxx_type_info *find_caught_type( cxx_exception_type *exc_type,
|
|
|
|
const catchblock_info *catchblock )
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for (i = 0; i < exc_type->type_info_table->count; i++)
|
|
|
|
{
|
2003-03-18 19:26:05 +01:00
|
|
|
const cxx_type_info *type = exc_type->type_info_table->info[i];
|
2002-07-24 05:02:51 +02:00
|
|
|
|
|
|
|
if (!catchblock->type_info) return type; /* catch(...) matches any type */
|
|
|
|
if (catchblock->type_info != type->type_info)
|
|
|
|
{
|
2003-03-18 19:26:05 +01:00
|
|
|
if (strcmp( catchblock->type_info->mangled, type->type_info->mangled )) continue;
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
/* type is the same, now check the flags */
|
|
|
|
if ((exc_type->flags & TYPE_FLAG_CONST) &&
|
|
|
|
!(catchblock->flags & TYPE_FLAG_CONST)) continue;
|
|
|
|
if ((exc_type->flags & TYPE_FLAG_VOLATILE) &&
|
|
|
|
!(catchblock->flags & TYPE_FLAG_VOLATILE)) continue;
|
|
|
|
return type; /* it matched */
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* copy the exception object where the catch block wants it */
|
|
|
|
static void copy_exception( void *object, cxx_exception_frame *frame,
|
2006-12-15 13:41:31 +01:00
|
|
|
const catchblock_info *catchblock, const cxx_type_info *type )
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
|
|
|
void **dest_ptr;
|
|
|
|
|
2003-03-18 19:26:05 +01:00
|
|
|
if (!catchblock->type_info || !catchblock->type_info->mangled[0]) return;
|
2002-07-24 05:02:51 +02:00
|
|
|
if (!catchblock->offset) return;
|
|
|
|
dest_ptr = (void **)((char *)&frame->ebp + catchblock->offset);
|
|
|
|
|
|
|
|
if (catchblock->flags & TYPE_FLAG_REFERENCE)
|
|
|
|
{
|
2004-10-19 01:13:55 +02:00
|
|
|
*dest_ptr = get_this_pointer( &type->offsets, object );
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
else if (type->flags & CLASS_IS_SIMPLE_TYPE)
|
|
|
|
{
|
|
|
|
memmove( dest_ptr, object, type->size );
|
|
|
|
/* if it is a pointer, adjust it */
|
2004-10-19 01:13:55 +02:00
|
|
|
if (type->size == sizeof(void *)) *dest_ptr = get_this_pointer( &type->offsets, *dest_ptr );
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
else /* copy the object */
|
|
|
|
{
|
|
|
|
if (type->copy_ctor)
|
2004-10-19 01:13:55 +02:00
|
|
|
call_copy_ctor( type->copy_ctor, dest_ptr, get_this_pointer(&type->offsets,object),
|
2002-07-24 05:02:51 +02:00
|
|
|
(type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) );
|
|
|
|
else
|
2004-10-19 01:13:55 +02:00
|
|
|
memmove( dest_ptr, get_this_pointer(&type->offsets,object), type->size );
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unwind the local function up to a given trylevel */
|
2006-12-15 13:41:31 +01:00
|
|
|
static void cxx_local_unwind( cxx_exception_frame* frame, const cxx_function_descr *descr, int last_level)
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
|
|
|
void (*handler)();
|
|
|
|
int trylevel = frame->trylevel;
|
|
|
|
|
|
|
|
while (trylevel != last_level)
|
|
|
|
{
|
|
|
|
if (trylevel < 0 || trylevel >= descr->unwind_count)
|
|
|
|
{
|
|
|
|
ERR( "invalid trylevel %d\n", trylevel );
|
|
|
|
MSVCRT_terminate();
|
|
|
|
}
|
|
|
|
handler = descr->unwind_table[trylevel].handler;
|
|
|
|
if (handler)
|
|
|
|
{
|
|
|
|
TRACE( "calling unwind handler %p trylevel %d last %d ebp %p\n",
|
|
|
|
handler, trylevel, last_level, &frame->ebp );
|
|
|
|
call_ebp_func( handler, &frame->ebp );
|
|
|
|
}
|
|
|
|
trylevel = descr->unwind_table[trylevel].prev;
|
|
|
|
}
|
|
|
|
frame->trylevel = last_level;
|
|
|
|
}
|
|
|
|
|
2002-10-31 03:10:15 +01:00
|
|
|
/* exception frame for nested exceptions in catch block */
|
|
|
|
struct catch_func_nested_frame
|
|
|
|
{
|
2003-08-28 05:07:56 +02:00
|
|
|
EXCEPTION_REGISTRATION_RECORD frame; /* standard exception frame */
|
|
|
|
EXCEPTION_RECORD *prev_rec; /* previous record to restore in thread data */
|
|
|
|
cxx_exception_frame *cxx_frame; /* frame of parent exception */
|
2006-12-15 13:41:31 +01:00
|
|
|
const cxx_function_descr *descr; /* descriptor of parent exception */
|
2003-08-28 05:07:56 +02:00
|
|
|
int trylevel; /* current try level */
|
2006-02-22 12:06:56 +01:00
|
|
|
EXCEPTION_RECORD *rec; /* rec associated with frame */
|
2002-10-31 03:10:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* handler for exceptions happening while calling a catch function */
|
2003-08-28 05:07:56 +02:00
|
|
|
static DWORD catch_function_nested_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
|
2002-10-31 03:10:15 +01:00
|
|
|
{
|
|
|
|
struct catch_func_nested_frame *nested_frame = (struct catch_func_nested_frame *)frame;
|
|
|
|
|
|
|
|
if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
|
|
|
|
{
|
|
|
|
msvcrt_get_thread_data()->exc_record = nested_frame->prev_rec;
|
|
|
|
return ExceptionContinueSearch;
|
|
|
|
}
|
2006-02-22 12:04:13 +01:00
|
|
|
|
|
|
|
TRACE( "got nested exception in catch function\n" );
|
|
|
|
|
|
|
|
if(rec->ExceptionCode == CXX_EXCEPTION)
|
2002-10-31 03:10:15 +01:00
|
|
|
{
|
2006-02-22 12:06:56 +01:00
|
|
|
PEXCEPTION_RECORD prev_rec = nested_frame->rec;
|
2006-02-22 12:04:13 +01:00
|
|
|
if(rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0)
|
|
|
|
{
|
|
|
|
/* exception was rethrown */
|
|
|
|
rec->ExceptionInformation[1] = prev_rec->ExceptionInformation[1];
|
|
|
|
rec->ExceptionInformation[2] = prev_rec->ExceptionInformation[2];
|
|
|
|
TRACE("detect rethrow: re-propagate: obj: %lx, type: %lx\n",
|
|
|
|
rec->ExceptionInformation[1], rec->ExceptionInformation[2]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* new exception in exception handler, destroy old */
|
|
|
|
void *object = (void*)prev_rec->ExceptionInformation[1];
|
|
|
|
cxx_exception_type *info = (cxx_exception_type*) prev_rec->ExceptionInformation[2];
|
|
|
|
TRACE("detect threw new exception in catch block - destroy old(obj: %p type: %p)\n",
|
|
|
|
object, info);
|
|
|
|
if(info && info->destructor)
|
|
|
|
call_dtor( info->destructor, object );
|
|
|
|
}
|
2002-10-31 03:10:15 +01:00
|
|
|
}
|
2006-02-22 12:04:13 +01:00
|
|
|
|
|
|
|
return cxx_frame_handler( rec, nested_frame->cxx_frame, context,
|
|
|
|
NULL, nested_frame->descr, &nested_frame->frame,
|
|
|
|
nested_frame->trylevel );
|
2002-10-31 03:10:15 +01:00
|
|
|
}
|
|
|
|
|
2002-07-24 05:02:51 +02:00
|
|
|
/* find and call the appropriate catch block for an exception */
|
|
|
|
/* returns the address to continue execution to after the catch block was called */
|
2006-01-05 13:56:11 +01:00
|
|
|
inline static void call_catch_block( PEXCEPTION_RECORD rec, cxx_exception_frame *frame,
|
2006-12-15 13:41:31 +01:00
|
|
|
const cxx_function_descr *descr, int nested_trylevel,
|
2006-01-05 13:56:11 +01:00
|
|
|
cxx_exception_type *info )
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
2003-03-18 19:26:05 +01:00
|
|
|
UINT i;
|
|
|
|
int j;
|
2006-02-17 17:37:26 +01:00
|
|
|
void *addr, *object = (void *)rec->ExceptionInformation[1];
|
2002-10-31 03:10:15 +01:00
|
|
|
struct catch_func_nested_frame nested_frame;
|
|
|
|
int trylevel = frame->trylevel;
|
2004-06-25 03:19:15 +02:00
|
|
|
thread_data_t *thread_data = msvcrt_get_thread_data();
|
2006-02-22 12:21:00 +01:00
|
|
|
DWORD save_esp = ((DWORD*)frame)[-1];
|
2002-07-24 05:02:51 +02:00
|
|
|
|
|
|
|
for (i = 0; i < descr->tryblock_count; i++)
|
|
|
|
{
|
2006-12-15 13:41:31 +01:00
|
|
|
const tryblock_info *tryblock = &descr->tryblock[i];
|
2002-07-24 05:02:51 +02:00
|
|
|
|
|
|
|
if (trylevel < tryblock->start_level) continue;
|
|
|
|
if (trylevel > tryblock->end_level) continue;
|
|
|
|
|
|
|
|
/* got a try block */
|
|
|
|
for (j = 0; j < tryblock->catchblock_count; j++)
|
|
|
|
{
|
2006-12-15 13:41:31 +01:00
|
|
|
const catchblock_info *catchblock = &tryblock->catchblock[j];
|
2005-10-30 20:03:43 +01:00
|
|
|
if(info)
|
|
|
|
{
|
|
|
|
const cxx_type_info *type = find_caught_type( info, catchblock );
|
|
|
|
if (!type) continue;
|
|
|
|
|
|
|
|
TRACE( "matched type %p in tryblock %d catchblock %d\n", type, i, j );
|
|
|
|
|
|
|
|
/* copy the exception to its destination on the stack */
|
|
|
|
copy_exception( object, frame, catchblock, type );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* no CXX_EXCEPTION only proceed with a catch(...) block*/
|
|
|
|
if(catchblock->type_info)
|
|
|
|
continue;
|
|
|
|
TRACE("found catch(...) block\n");
|
|
|
|
}
|
2002-07-24 05:02:51 +02:00
|
|
|
|
|
|
|
/* unwind the stack */
|
2002-10-31 03:10:15 +01:00
|
|
|
RtlUnwind( frame, 0, rec, 0 );
|
2002-07-24 05:02:51 +02:00
|
|
|
cxx_local_unwind( frame, descr, tryblock->start_level );
|
|
|
|
frame->trylevel = tryblock->end_level + 1;
|
|
|
|
|
|
|
|
/* call the catch block */
|
2005-10-30 20:03:43 +01:00
|
|
|
TRACE( "calling catch block %p addr %p ebp %p\n",
|
|
|
|
catchblock, catchblock->handler, &frame->ebp );
|
2002-10-31 03:10:15 +01:00
|
|
|
|
|
|
|
/* setup an exception block for nested exceptions */
|
|
|
|
|
|
|
|
nested_frame.frame.Handler = catch_function_nested_handler;
|
|
|
|
nested_frame.prev_rec = thread_data->exc_record;
|
|
|
|
nested_frame.cxx_frame = frame;
|
|
|
|
nested_frame.descr = descr;
|
|
|
|
nested_frame.trylevel = nested_trylevel + 1;
|
2006-02-22 12:06:56 +01:00
|
|
|
nested_frame.rec = rec;
|
2002-10-31 03:10:15 +01:00
|
|
|
|
|
|
|
__wine_push_frame( &nested_frame.frame );
|
|
|
|
thread_data->exc_record = rec;
|
2002-07-24 05:02:51 +02:00
|
|
|
addr = call_ebp_func( catchblock->handler, &frame->ebp );
|
2002-10-31 03:10:15 +01:00
|
|
|
thread_data->exc_record = nested_frame.prev_rec;
|
|
|
|
__wine_pop_frame( &nested_frame.frame );
|
|
|
|
|
2006-02-22 12:21:00 +01:00
|
|
|
((DWORD*)frame)[-1] = save_esp;
|
2005-10-30 20:03:43 +01:00
|
|
|
if (info && info->destructor) call_dtor( info->destructor, object );
|
2002-07-24 05:02:51 +02:00
|
|
|
TRACE( "done, continuing at %p\n", addr );
|
2006-02-17 17:37:26 +01:00
|
|
|
|
2006-01-05 13:56:11 +01:00
|
|
|
continue_after_catch( frame, addr );
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* cxx_frame_handler
|
|
|
|
*
|
|
|
|
* Implementation of __CxxFrameHandler.
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
|
|
|
|
PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
|
2006-12-15 13:41:31 +01:00
|
|
|
const cxx_function_descr *descr,
|
|
|
|
EXCEPTION_REGISTRATION_RECORD* nested_frame,
|
2006-06-13 11:21:19 +02:00
|
|
|
int nested_trylevel )
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
|
|
|
cxx_exception_type *exc_type;
|
|
|
|
|
|
|
|
if (descr->magic != CXX_FRAME_MAGIC)
|
|
|
|
{
|
|
|
|
ERR( "invalid frame magic %x\n", descr->magic );
|
|
|
|
return ExceptionContinueSearch;
|
|
|
|
}
|
|
|
|
if (rec->ExceptionFlags & (EH_UNWINDING|EH_EXIT_UNWIND))
|
|
|
|
{
|
2002-10-31 03:10:15 +01:00
|
|
|
if (descr->unwind_count && !nested_trylevel) cxx_local_unwind( frame, descr, -1 );
|
2002-07-24 05:02:51 +02:00
|
|
|
return ExceptionContinueSearch;
|
|
|
|
}
|
|
|
|
if (!descr->tryblock_count) return ExceptionContinueSearch;
|
|
|
|
|
2005-10-30 20:03:43 +01:00
|
|
|
if(rec->ExceptionCode == CXX_EXCEPTION)
|
2002-10-31 03:10:15 +01:00
|
|
|
{
|
|
|
|
exc_type = (cxx_exception_type *)rec->ExceptionInformation[2];
|
2002-07-24 05:02:51 +02:00
|
|
|
|
2005-10-30 20:03:43 +01:00
|
|
|
if (rec->ExceptionInformation[0] > CXX_FRAME_MAGIC &&
|
|
|
|
exc_type->custom_handler)
|
|
|
|
{
|
2006-01-05 13:56:11 +01:00
|
|
|
return exc_type->custom_handler( rec, frame, context, dispatch,
|
2005-10-30 20:03:43 +01:00
|
|
|
descr, nested_trylevel, nested_frame, 0 );
|
|
|
|
}
|
2006-02-22 12:04:13 +01:00
|
|
|
|
2005-10-30 20:03:43 +01:00
|
|
|
if (TRACE_ON(seh))
|
|
|
|
{
|
|
|
|
TRACE("handling C++ exception rec %p frame %p trylevel %d descr %p nested_frame %p\n",
|
|
|
|
rec, frame, frame->trylevel, descr, nested_frame );
|
|
|
|
dump_exception_type( exc_type );
|
2006-12-15 13:41:31 +01:00
|
|
|
dump_function_descr( descr );
|
2005-10-30 20:03:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
2005-10-30 20:03:43 +01:00
|
|
|
exc_type = NULL;
|
2006-10-03 20:39:05 +02:00
|
|
|
TRACE("handling C exception code %x rec %p frame %p trylevel %d descr %p nested_frame %p\n",
|
2005-10-30 20:03:43 +01:00
|
|
|
rec->ExceptionCode, rec, frame, frame->trylevel, descr, nested_frame );
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
|
2006-01-05 13:56:11 +01:00
|
|
|
call_catch_block( rec, frame, descr, frame->trylevel, exc_type );
|
|
|
|
return ExceptionContinueSearch;
|
2002-07-24 05:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __CxxFrameHandler (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
extern DWORD CDECL __CxxFrameHandler( PEXCEPTION_RECORD rec, EXCEPTION_REGISTRATION_RECORD* frame,
|
|
|
|
PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch );
|
2006-01-05 13:56:11 +01:00
|
|
|
__ASM_GLOBAL_FUNC( __CxxFrameHandler,
|
|
|
|
"pushl $0\n\t" /* nested_trylevel */
|
|
|
|
"pushl $0\n\t" /* nested_frame */
|
|
|
|
"pushl %eax\n\t" /* descr */
|
|
|
|
"pushl 28(%esp)\n\t" /* dispatch */
|
|
|
|
"pushl 28(%esp)\n\t" /* context */
|
|
|
|
"pushl 28(%esp)\n\t" /* frame */
|
|
|
|
"pushl 28(%esp)\n\t" /* rec */
|
|
|
|
"call " __ASM_NAME("cxx_frame_handler") "\n\t"
|
|
|
|
"add $28,%esp\n\t"
|
2007-01-13 00:38:07 +01:00
|
|
|
"ret" )
|
2002-07-24 05:02:51 +02:00
|
|
|
|
2006-12-16 17:37:20 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __CxxLongjmpUnwind (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Callback meant to be used as UnwindFunc for setjmp/longjmp.
|
|
|
|
*/
|
|
|
|
void __stdcall __CxxLongjmpUnwind( const struct MSVCRT___JUMP_BUFFER *buf )
|
|
|
|
{
|
|
|
|
cxx_exception_frame *frame = (cxx_exception_frame *)buf->Registration;
|
|
|
|
const cxx_function_descr *descr = (const cxx_function_descr *)buf->UnwindData[0];
|
|
|
|
|
|
|
|
TRACE( "unwinding frame %p descr %p trylevel %ld\n", frame, descr, buf->TryLevel );
|
|
|
|
cxx_local_unwind( frame, descr, buf->TryLevel );
|
|
|
|
}
|
|
|
|
|
2002-07-24 05:02:51 +02:00
|
|
|
#endif /* __i386__ */
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _CxxThrowException (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
void CDECL _CxxThrowException( exception *object, const cxx_exception_type *type )
|
2002-07-24 05:02:51 +02:00
|
|
|
{
|
2005-09-12 17:14:06 +02:00
|
|
|
ULONG_PTR args[3];
|
2002-07-24 05:02:51 +02:00
|
|
|
|
|
|
|
args[0] = CXX_FRAME_MAGIC;
|
2005-09-12 17:14:06 +02:00
|
|
|
args[1] = (ULONG_PTR)object;
|
|
|
|
args[2] = (ULONG_PTR)type;
|
2002-07-24 05:02:51 +02:00
|
|
|
RaiseException( CXX_EXCEPTION, EH_NONCONTINUABLE, 3, args );
|
|
|
|
}
|
2003-03-18 19:26:05 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __CxxDetectRethrow (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)
|
2003-03-18 19:26:05 +01:00
|
|
|
{
|
|
|
|
PEXCEPTION_RECORD rec;
|
|
|
|
|
|
|
|
if (!ptrs)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
rec = ptrs->ExceptionRecord;
|
|
|
|
|
|
|
|
if (rec->ExceptionCode == CXX_EXCEPTION &&
|
|
|
|
rec->NumberParameters == 3 &&
|
|
|
|
rec->ExceptionInformation[0] == CXX_FRAME_MAGIC &&
|
|
|
|
rec->ExceptionInformation[2])
|
|
|
|
{
|
|
|
|
ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return (msvcrt_get_thread_data()->exc_record == rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __CxxQueryExceptionSize (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
unsigned int CDECL __CxxQueryExceptionSize(void)
|
2003-03-18 19:26:05 +01:00
|
|
|
{
|
|
|
|
return sizeof(cxx_exception_type);
|
|
|
|
}
|