1999-05-09 18:12:19 +02:00
|
|
|
/*
|
|
|
|
* NT exception handling routines
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-05-09 18:12:19 +02:00
|
|
|
* Copyright 1999 Turchanov Sergey
|
|
|
|
* Copyright 1999 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
1999-05-09 18:12:19 +02:00
|
|
|
*/
|
|
|
|
|
2001-10-14 18:18:52 +02:00
|
|
|
#include "config.h"
|
2002-04-25 23:40:56 +02:00
|
|
|
#include "wine/port.h"
|
2001-10-14 18:18:52 +02:00
|
|
|
|
2000-08-06 04:42:46 +02:00
|
|
|
#include <assert.h>
|
2007-06-01 11:16:09 +02:00
|
|
|
#include <errno.h>
|
1999-06-18 20:21:24 +02:00
|
|
|
#include <signal.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-11-25 02:31:17 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2002-12-10 23:56:43 +01:00
|
|
|
#include "windef.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
1999-05-12 15:10:39 +02:00
|
|
|
#include "wine/exception.h"
|
2001-07-19 02:39:09 +02:00
|
|
|
#include "wine/server.h"
|
2003-10-28 22:22:50 +01:00
|
|
|
#include "wine/list.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2002-12-13 00:34:01 +01:00
|
|
|
#include "excpt.h"
|
2003-10-31 00:06:41 +01:00
|
|
|
#include "ntdll_misc.h"
|
1999-05-09 18:12:19 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(seh);
|
1999-05-09 18:12:19 +02:00
|
|
|
|
|
|
|
/* Exception record for handling exceptions happening inside exception handlers */
|
|
|
|
typedef struct
|
|
|
|
{
|
2003-08-28 05:07:56 +02:00
|
|
|
EXCEPTION_REGISTRATION_RECORD frame;
|
|
|
|
EXCEPTION_REGISTRATION_RECORD *prevFrame;
|
1999-05-09 18:12:19 +02:00
|
|
|
} EXC_NESTED_FRAME;
|
|
|
|
|
2003-10-28 22:22:50 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
PVECTORED_EXCEPTION_HANDLER func;
|
|
|
|
} VECTORED_HANDLER;
|
|
|
|
|
|
|
|
static struct list vectored_handlers = LIST_INIT(vectored_handlers);
|
|
|
|
|
2005-06-25 20:00:57 +02:00
|
|
|
static RTL_CRITICAL_SECTION vectored_handlers_section;
|
|
|
|
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
|
2003-10-28 22:22:50 +01:00
|
|
|
{
|
|
|
|
0, 0, &vectored_handlers_section,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": vectored_handlers_section") }
|
2003-10-28 22:22:50 +01:00
|
|
|
};
|
2005-06-25 20:00:57 +02:00
|
|
|
static RTL_CRITICAL_SECTION vectored_handlers_section = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2003-10-28 22:22:50 +01:00
|
|
|
|
2000-11-26 00:56:20 +01:00
|
|
|
#ifdef __i386__
|
|
|
|
# define GET_IP(context) ((LPVOID)(context)->Eip)
|
2002-08-17 03:19:06 +02:00
|
|
|
#elif defined(__sparc__)
|
2000-11-26 00:56:20 +01:00
|
|
|
# define GET_IP(context) ((LPVOID)(context)->pc)
|
2002-08-17 03:19:06 +02:00
|
|
|
#elif defined(__powerpc__)
|
2002-08-30 02:00:57 +02:00
|
|
|
# define GET_IP(context) ((LPVOID)(context)->Iar)
|
2004-10-18 23:27:52 +02:00
|
|
|
#elif defined(__ALPHA__)
|
|
|
|
# define GET_IP(context) ((LPVOID)(context)->Fir)
|
2005-09-08 21:17:04 +02:00
|
|
|
#elif defined(__x86_64__)
|
|
|
|
# define GET_IP(context) ((LPVOID)(context)->Rip)
|
2002-08-17 03:19:06 +02:00
|
|
|
#else
|
2000-11-26 00:56:20 +01:00
|
|
|
# error You must define GET_IP for this CPU
|
|
|
|
#endif
|
|
|
|
|
1999-05-09 18:12:19 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* EXC_RaiseHandler
|
|
|
|
*
|
|
|
|
* Handler for exceptions happening inside a handler.
|
|
|
|
*/
|
2003-08-28 05:07:56 +02:00
|
|
|
static DWORD EXC_RaiseHandler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
|
|
|
if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
|
|
|
|
return ExceptionContinueSearch;
|
|
|
|
/* We shouldn't get here so we store faulty frame in dispatcher */
|
|
|
|
*dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
|
|
|
|
return ExceptionNestedException;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* EXC_UnwindHandler
|
|
|
|
*
|
|
|
|
* Handler for exceptions happening inside an unwind handler.
|
|
|
|
*/
|
2003-08-28 05:07:56 +02:00
|
|
|
static DWORD EXC_UnwindHandler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
|
|
|
if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
|
|
|
|
return ExceptionContinueSearch;
|
|
|
|
/* We shouldn't get here so we store faulty frame in dispatcher */
|
|
|
|
*dispatcher = ((EXC_NESTED_FRAME*)frame)->prevFrame;
|
|
|
|
return ExceptionCollidedUnwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* EXC_CallHandler
|
|
|
|
*
|
|
|
|
* Call an exception handler, setting up an exception frame to catch exceptions
|
|
|
|
* happening during the handler execution.
|
2005-10-31 15:08:05 +01:00
|
|
|
*
|
|
|
|
* For i386 this function is implemented in assembler in signal_i386.c.
|
1999-05-09 18:12:19 +02:00
|
|
|
*/
|
2005-10-31 15:08:05 +01:00
|
|
|
#ifndef __i386__
|
2003-08-28 05:07:56 +02:00
|
|
|
static DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher,
|
1999-10-24 01:55:50 +02:00
|
|
|
PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler)
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
|
|
|
EXC_NESTED_FRAME newframe;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
newframe.frame.Handler = nested_handler;
|
|
|
|
newframe.prevFrame = frame;
|
2000-08-06 04:42:46 +02:00
|
|
|
__wine_push_frame( &newframe.frame );
|
1999-05-09 18:12:19 +02:00
|
|
|
ret = handler( record, frame, context, dispatcher );
|
2000-08-06 04:42:46 +02:00
|
|
|
__wine_pop_frame( &newframe.frame );
|
1999-05-09 18:12:19 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2005-10-31 15:08:05 +01:00
|
|
|
#else
|
|
|
|
/* in signal_i386.c */
|
|
|
|
extern DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher,
|
|
|
|
PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler);
|
|
|
|
#endif
|
1999-05-09 18:12:19 +02:00
|
|
|
|
2005-11-02 21:54:12 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* wait_suspend
|
|
|
|
*
|
|
|
|
* Wait until the thread is no longer suspended.
|
|
|
|
*/
|
|
|
|
void wait_suspend( CONTEXT *context )
|
|
|
|
{
|
|
|
|
LARGE_INTEGER timeout;
|
2007-06-01 11:16:09 +02:00
|
|
|
int saved_errno = errno;
|
2005-11-02 21:54:12 +01:00
|
|
|
|
|
|
|
/* store the context we got at suspend time */
|
|
|
|
SERVER_START_REQ( set_thread_context )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( GetCurrentThread() );
|
2005-11-02 21:54:12 +01:00
|
|
|
req->flags = CONTEXT_FULL;
|
|
|
|
req->suspend = 1;
|
|
|
|
wine_server_add_data( req, context, sizeof(*context) );
|
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
/* wait with 0 timeout, will only return once the thread is no longer suspended */
|
|
|
|
timeout.QuadPart = 0;
|
2007-01-10 21:55:23 +01:00
|
|
|
NTDLL_wait_for_multiple_objects( 0, NULL, SELECT_INTERRUPTIBLE, &timeout, 0 );
|
2005-11-02 21:54:12 +01:00
|
|
|
|
|
|
|
/* retrieve the new context */
|
|
|
|
SERVER_START_REQ( get_thread_context )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( GetCurrentThread() );
|
2005-11-02 21:54:12 +01:00
|
|
|
req->flags = CONTEXT_FULL;
|
|
|
|
req->suspend = 1;
|
|
|
|
wine_server_set_reply( req, context, sizeof(*context) );
|
|
|
|
wine_server_call( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2007-06-01 11:16:09 +02:00
|
|
|
|
|
|
|
errno = saved_errno;
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-10 23:16:10 +01:00
|
|
|
/**********************************************************************
|
2000-08-30 02:00:48 +02:00
|
|
|
* send_debug_event
|
2000-03-10 23:16:10 +01:00
|
|
|
*
|
|
|
|
* Send an EXCEPTION_DEBUG_EVENT event to the debugger.
|
|
|
|
*/
|
2005-12-20 11:47:27 +01:00
|
|
|
static NTSTATUS send_debug_event( EXCEPTION_RECORD *rec, int first_chance, CONTEXT *context )
|
2000-03-10 23:16:10 +01:00
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
int ret;
|
2009-01-02 20:12:46 +01:00
|
|
|
DWORD i;
|
2001-01-26 21:45:41 +01:00
|
|
|
HANDLE handle = 0;
|
2009-01-02 20:12:46 +01:00
|
|
|
client_ptr_t params[EXCEPTION_MAXIMUM_PARAMETERS];
|
2001-01-26 21:45:41 +01:00
|
|
|
|
2003-10-14 03:30:42 +02:00
|
|
|
if (!NtCurrentTeb()->Peb->BeingDebugged) return 0; /* no debugger present */
|
|
|
|
|
2009-01-02 20:12:46 +01:00
|
|
|
for (i = 0; i < min( rec->NumberParameters, EXCEPTION_MAXIMUM_PARAMETERS ); i++)
|
|
|
|
params[i] = rec->ExceptionInformation[i];
|
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_START_REQ( queue_exception_event )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
|
|
|
req->first = first_chance;
|
2009-01-02 20:12:46 +01:00
|
|
|
req->code = rec->ExceptionCode;
|
|
|
|
req->flags = rec->ExceptionFlags;
|
|
|
|
req->record = wine_server_client_ptr( rec->ExceptionRecord );
|
|
|
|
req->address = wine_server_client_ptr( rec->ExceptionAddress );
|
|
|
|
req->len = i * sizeof(params[0]);
|
|
|
|
wine_server_add_data( req, params, req->len );
|
2001-11-30 19:46:42 +01:00
|
|
|
wine_server_add_data( req, context, sizeof(*context) );
|
2008-12-08 16:05:17 +01:00
|
|
|
if (!wine_server_call( req )) handle = wine_server_ptr_handle( reply->handle );
|
2001-01-26 21:45:41 +01:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_END_REQ;
|
2003-10-14 03:30:42 +02:00
|
|
|
if (!handle) return 0;
|
2001-01-26 21:45:41 +01:00
|
|
|
|
2007-02-13 17:17:58 +01:00
|
|
|
NTDLL_wait_for_multiple_objects( 1, &handle, SELECT_INTERRUPTIBLE, NULL, 0 );
|
2005-11-01 22:47:07 +01:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_START_REQ( get_exception_status )
|
2001-01-26 21:45:41 +01:00
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( handle );
|
2001-11-30 19:46:42 +01:00
|
|
|
wine_server_set_reply( req, context, sizeof(*context) );
|
2005-11-01 22:47:07 +01:00
|
|
|
ret = wine_server_call( req );
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_END_REQ;
|
2000-08-30 02:00:48 +02:00
|
|
|
return ret;
|
2000-03-10 23:16:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-28 22:22:50 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* call_vectored_handlers
|
|
|
|
*
|
|
|
|
* Call the vectored handlers chain.
|
|
|
|
*/
|
|
|
|
static LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
|
|
|
|
{
|
|
|
|
struct list *ptr;
|
|
|
|
LONG ret = EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
EXCEPTION_POINTERS except_ptrs;
|
|
|
|
|
|
|
|
except_ptrs.ExceptionRecord = rec;
|
|
|
|
except_ptrs.ContextRecord = context;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &vectored_handlers_section );
|
|
|
|
LIST_FOR_EACH( ptr, &vectored_handlers )
|
|
|
|
{
|
|
|
|
VECTORED_HANDLER *handler = LIST_ENTRY( ptr, VECTORED_HANDLER, entry );
|
2009-02-02 16:22:06 +01:00
|
|
|
TRACE( "calling handler at %p code=%x flags=%x\n",
|
|
|
|
handler->func, rec->ExceptionCode, rec->ExceptionFlags );
|
2003-10-28 22:22:50 +01:00
|
|
|
ret = handler->func( &except_ptrs );
|
2009-02-02 16:22:06 +01:00
|
|
|
TRACE( "handler at %p returned %x\n", handler->func, ret );
|
2003-10-28 22:22:50 +01:00
|
|
|
if (ret == EXCEPTION_CONTINUE_EXECUTION) break;
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &vectored_handlers_section );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-10 17:51:22 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* call_stack_handlers
|
1999-05-09 18:12:19 +02:00
|
|
|
*
|
2006-01-10 17:51:22 +01:00
|
|
|
* Call the stack handlers chain.
|
1999-05-09 18:12:19 +02:00
|
|
|
*/
|
2006-01-10 17:51:22 +01:00
|
|
|
static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
2004-08-22 04:07:13 +02:00
|
|
|
EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame;
|
2006-01-10 17:51:22 +01:00
|
|
|
DWORD res;
|
2003-10-28 22:22:50 +01:00
|
|
|
|
2003-08-28 05:44:41 +02:00
|
|
|
frame = NtCurrentTeb()->Tib.ExceptionList;
|
1999-05-09 18:12:19 +02:00
|
|
|
nested_frame = NULL;
|
2004-08-22 04:07:13 +02:00
|
|
|
while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL)
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
|
|
|
/* Check frame address */
|
2003-08-28 05:44:41 +02:00
|
|
|
if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
|
|
|
|
((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
|
2005-02-24 14:15:36 +01:00
|
|
|
(ULONG_PTR)frame & 3)
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
|
|
|
rec->ExceptionFlags |= EH_STACK_INVALID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call handler */
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "calling handler at %p code=%x flags=%x\n",
|
2006-04-06 21:32:17 +02:00
|
|
|
frame->Handler, rec->ExceptionCode, rec->ExceptionFlags );
|
1999-10-24 01:55:50 +02:00
|
|
|
res = EXC_CallHandler( rec, frame, context, &dispatch, frame->Handler, EXC_RaiseHandler );
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "handler at %p returned %x\n", frame->Handler, res );
|
2006-04-06 21:32:17 +02:00
|
|
|
|
1999-05-09 18:12:19 +02:00
|
|
|
if (frame == nested_frame)
|
|
|
|
{
|
|
|
|
/* no longer nested */
|
|
|
|
nested_frame = NULL;
|
|
|
|
rec->ExceptionFlags &= ~EH_NESTED_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(res)
|
|
|
|
{
|
|
|
|
case ExceptionContinueExecution:
|
2006-01-10 17:51:22 +01:00
|
|
|
if (!(rec->ExceptionFlags & EH_NONCONTINUABLE)) return STATUS_SUCCESS;
|
|
|
|
return STATUS_NONCONTINUABLE_EXCEPTION;
|
1999-05-09 18:12:19 +02:00
|
|
|
case ExceptionContinueSearch:
|
|
|
|
break;
|
|
|
|
case ExceptionNestedException:
|
|
|
|
if (nested_frame < dispatch) nested_frame = dispatch;
|
|
|
|
rec->ExceptionFlags |= EH_NESTED_CALL;
|
|
|
|
break;
|
|
|
|
default:
|
2006-01-10 17:51:22 +01:00
|
|
|
return STATUS_INVALID_DISPOSITION;
|
1999-05-09 18:12:19 +02:00
|
|
|
}
|
|
|
|
frame = frame->Prev;
|
|
|
|
}
|
2006-01-10 17:51:22 +01:00
|
|
|
return STATUS_UNHANDLED_EXCEPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* raise_exception
|
|
|
|
*
|
|
|
|
* Implementation of NtRaiseException.
|
|
|
|
*/
|
|
|
|
static NTSTATUS raise_exception( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (first_chance)
|
|
|
|
{
|
|
|
|
DWORD c;
|
|
|
|
|
2009-01-06 17:02:13 +01:00
|
|
|
TRACE( "code=%x flags=%x addr=%p ip=%p tid=%04x\n",
|
|
|
|
rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
|
|
|
|
GET_IP(context), GetCurrentThreadId() );
|
2006-01-10 17:51:22 +01:00
|
|
|
for (c = 0; c < rec->NumberParameters; c++)
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] );
|
2006-01-10 17:51:22 +01:00
|
|
|
if (rec->ExceptionCode == EXCEPTION_WINE_STUB)
|
|
|
|
{
|
|
|
|
if (rec->ExceptionInformation[1] >> 16)
|
|
|
|
MESSAGE( "wine: Call from %p to unimplemented function %s.%s, aborting\n",
|
|
|
|
rec->ExceptionAddress,
|
|
|
|
(char*)rec->ExceptionInformation[0], (char*)rec->ExceptionInformation[1] );
|
|
|
|
else
|
|
|
|
MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
|
|
|
|
rec->ExceptionAddress,
|
|
|
|
(char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-06 17:02:13 +01:00
|
|
|
#ifdef __i386__
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE(" eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n",
|
2006-01-10 17:51:22 +01:00
|
|
|
context->Eax, context->Ebx, context->Ecx,
|
|
|
|
context->Edx, context->Esi, context->Edi );
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE(" ebp=%08x esp=%08x cs=%04x ds=%04x es=%04x fs=%04x gs=%04x flags=%08x\n",
|
2006-01-10 17:51:22 +01:00
|
|
|
context->Ebp, context->Esp, context->SegCs, context->SegDs,
|
|
|
|
context->SegEs, context->SegFs, context->SegGs, context->EFlags );
|
2009-01-06 17:02:13 +01:00
|
|
|
#elif defined(__x86_64__)
|
|
|
|
TRACE(" rax=%016lx rbx=%016lx rcx=%016lx rdx=%016lx\n",
|
|
|
|
context->Rax, context->Rbx, context->Rcx, context->Rdx );
|
|
|
|
TRACE(" rsi=%016lx rdi=%016lx rbp=%016lx rsp=%016lx\n",
|
|
|
|
context->Rsi, context->Rdi, context->Rbp, context->Rsp );
|
|
|
|
TRACE(" r8=%016lx r9=%016lx r10=%016lx r11=%016lx\n",
|
|
|
|
context->R8, context->R9, context->R10, context->R11 );
|
|
|
|
TRACE(" r12=%016lx r13=%016lx r14=%016lx r15=%016lx\n",
|
|
|
|
context->R12, context->R13, context->R14, context->R15 );
|
2006-01-10 17:51:22 +01:00
|
|
|
#endif
|
2009-01-06 17:02:13 +01:00
|
|
|
}
|
2006-01-10 17:51:22 +01:00
|
|
|
status = send_debug_event( rec, TRUE, context );
|
|
|
|
if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
2007-05-22 18:28:53 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
/* fix up instruction pointer in context for EXCEPTION_BREAKPOINT */
|
|
|
|
if (rec->ExceptionCode == EXCEPTION_BREAKPOINT) context->Eip--;
|
|
|
|
#endif
|
|
|
|
|
2006-01-10 17:51:22 +01:00
|
|
|
if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
if ((status = call_stack_handlers( rec, context )) != STATUS_UNHANDLED_EXCEPTION)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* last chance exception */
|
|
|
|
|
|
|
|
status = send_debug_event( rec, FALSE, context );
|
|
|
|
if (status != DBG_CONTINUE)
|
|
|
|
{
|
|
|
|
if (rec->ExceptionFlags & EH_STACK_INVALID)
|
|
|
|
ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
|
|
|
|
else if (rec->ExceptionCode == STATUS_NONCONTINUABLE_EXCEPTION)
|
|
|
|
ERR("Process attempted to continue execution after noncontinuable exception.\n");
|
|
|
|
else
|
2006-10-16 13:49:06 +02:00
|
|
|
ERR("Unhandled exception code %x flags %x addr %p\n",
|
2006-01-10 17:51:22 +01:00
|
|
|
rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
|
|
|
|
NtTerminateProcess( NtCurrentProcess(), 1 );
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* NtRaiseException (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
|
|
|
|
{
|
|
|
|
NTSTATUS status = raise_exception( rec, context, first_chance );
|
2006-04-20 15:40:42 +02:00
|
|
|
if (status == STATUS_SUCCESS) NtSetContextThread( GetCurrentThread(), context );
|
2006-01-10 17:51:22 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-12-04 12:23:13 +01:00
|
|
|
|
2006-01-10 17:51:22 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlRaiseException (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI __regs_RtlRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context )
|
|
|
|
{
|
|
|
|
NTSTATUS status = raise_exception( rec, context, TRUE );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
EXCEPTION_RECORD newrec;
|
|
|
|
newrec.ExceptionCode = status;
|
|
|
|
newrec.ExceptionFlags = EH_NONCONTINUABLE;
|
|
|
|
newrec.ExceptionRecord = rec;
|
|
|
|
newrec.NumberParameters = 0;
|
|
|
|
RtlRaiseException( &newrec ); /* never returns */
|
|
|
|
}
|
1999-05-09 18:12:19 +02:00
|
|
|
}
|
|
|
|
|
2004-02-20 21:19:23 +01:00
|
|
|
/**********************************************************************/
|
|
|
|
|
2003-12-04 06:48:03 +01:00
|
|
|
#ifdef DEFINE_REGS_ENTRYPOINT
|
2009-01-06 12:49:18 +01:00
|
|
|
DEFINE_REGS_ENTRYPOINT( RtlRaiseException, 1 )
|
2003-12-04 06:48:03 +01:00
|
|
|
#else
|
|
|
|
void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec )
|
|
|
|
{
|
|
|
|
CONTEXT context;
|
2008-12-04 12:23:13 +01:00
|
|
|
RtlCaptureContext( &context );
|
2005-05-07 20:10:30 +02:00
|
|
|
__regs_RtlRaiseException( rec, &context );
|
2003-12-04 06:48:03 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-05-09 18:12:19 +02:00
|
|
|
|
|
|
|
/*******************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* RtlUnwind (NTDLL.@)
|
1999-05-09 18:12:19 +02:00
|
|
|
*/
|
2005-05-07 20:10:30 +02:00
|
|
|
void WINAPI __regs_RtlUnwind( EXCEPTION_REGISTRATION_RECORD* pEndFrame, PVOID unusedEip,
|
|
|
|
PEXCEPTION_RECORD pRecord, PVOID returnEax, CONTEXT *context )
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
|
|
|
EXCEPTION_RECORD record, newrec;
|
2004-08-22 04:07:13 +02:00
|
|
|
EXCEPTION_REGISTRATION_RECORD *frame, *dispatch;
|
2006-04-06 21:32:17 +02:00
|
|
|
DWORD res;
|
1999-05-09 18:12:19 +02:00
|
|
|
|
1999-06-26 20:40:24 +02:00
|
|
|
#ifdef __i386__
|
2003-12-30 20:26:19 +01:00
|
|
|
context->Eax = (DWORD)returnEax;
|
1999-06-26 20:40:24 +02:00
|
|
|
#endif
|
1999-05-13 18:21:37 +02:00
|
|
|
|
1999-05-09 18:12:19 +02:00
|
|
|
/* build an exception record, if we do not have one */
|
|
|
|
if (!pRecord)
|
|
|
|
{
|
|
|
|
record.ExceptionCode = STATUS_UNWIND;
|
|
|
|
record.ExceptionFlags = 0;
|
|
|
|
record.ExceptionRecord = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
record.ExceptionAddress = GET_IP(context);
|
1999-05-09 18:12:19 +02:00
|
|
|
record.NumberParameters = 0;
|
|
|
|
pRecord = &record;
|
|
|
|
}
|
|
|
|
|
|
|
|
pRecord->ExceptionFlags |= EH_UNWINDING | (pEndFrame ? 0 : EH_EXIT_UNWIND);
|
1999-05-23 22:02:04 +02:00
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "code=%x flags=%x\n", pRecord->ExceptionCode, pRecord->ExceptionFlags );
|
1999-05-23 22:02:04 +02:00
|
|
|
|
1999-05-09 18:12:19 +02:00
|
|
|
/* get chain of exception frames */
|
2003-08-28 05:44:41 +02:00
|
|
|
frame = NtCurrentTeb()->Tib.ExceptionList;
|
2004-08-22 04:07:13 +02:00
|
|
|
while ((frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) && (frame != pEndFrame))
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
|
|
|
/* Check frame address */
|
|
|
|
if (pEndFrame && (frame > pEndFrame))
|
|
|
|
{
|
|
|
|
newrec.ExceptionCode = STATUS_INVALID_UNWIND_TARGET;
|
|
|
|
newrec.ExceptionFlags = EH_NONCONTINUABLE;
|
|
|
|
newrec.ExceptionRecord = pRecord;
|
|
|
|
newrec.NumberParameters = 0;
|
|
|
|
RtlRaiseException( &newrec ); /* never returns */
|
|
|
|
}
|
2003-08-28 05:44:41 +02:00
|
|
|
if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
|
|
|
|
((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
|
2005-09-12 17:14:06 +02:00
|
|
|
(UINT_PTR)frame & 3)
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
|
|
|
newrec.ExceptionCode = STATUS_BAD_STACK;
|
|
|
|
newrec.ExceptionFlags = EH_NONCONTINUABLE;
|
|
|
|
newrec.ExceptionRecord = pRecord;
|
|
|
|
newrec.NumberParameters = 0;
|
|
|
|
RtlRaiseException( &newrec ); /* never returns */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call handler */
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "calling handler at %p code=%x flags=%x\n",
|
2006-04-06 21:32:17 +02:00
|
|
|
frame->Handler, pRecord->ExceptionCode, pRecord->ExceptionFlags );
|
|
|
|
res = EXC_CallHandler( pRecord, frame, context, &dispatch, frame->Handler, EXC_UnwindHandler );
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "handler at %p returned %x\n", frame->Handler, res );
|
2006-04-06 21:32:17 +02:00
|
|
|
|
|
|
|
switch(res)
|
1999-05-09 18:12:19 +02:00
|
|
|
{
|
|
|
|
case ExceptionContinueSearch:
|
|
|
|
break;
|
|
|
|
case ExceptionCollidedUnwind:
|
|
|
|
frame = dispatch;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
newrec.ExceptionCode = STATUS_INVALID_DISPOSITION;
|
|
|
|
newrec.ExceptionFlags = EH_NONCONTINUABLE;
|
|
|
|
newrec.ExceptionRecord = pRecord;
|
|
|
|
newrec.NumberParameters = 0;
|
|
|
|
RtlRaiseException( &newrec ); /* never returns */
|
|
|
|
break;
|
|
|
|
}
|
2000-08-06 04:42:46 +02:00
|
|
|
frame = __wine_pop_frame( frame );
|
1999-05-09 18:12:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-20 21:19:23 +01:00
|
|
|
/**********************************************************************/
|
|
|
|
|
2003-12-04 06:48:03 +01:00
|
|
|
#ifdef DEFINE_REGS_ENTRYPOINT
|
2009-01-06 12:49:18 +01:00
|
|
|
DEFINE_REGS_ENTRYPOINT( RtlUnwind, 4 )
|
2003-12-04 06:48:03 +01:00
|
|
|
#else
|
2003-12-30 20:26:19 +01:00
|
|
|
void WINAPI RtlUnwind( PVOID pEndFrame, PVOID unusedEip,
|
|
|
|
PEXCEPTION_RECORD pRecord, PVOID returnEax )
|
2003-12-04 06:48:03 +01:00
|
|
|
{
|
|
|
|
CONTEXT context;
|
2008-12-04 12:23:13 +01:00
|
|
|
RtlCaptureContext( &context );
|
2005-05-07 20:10:30 +02:00
|
|
|
__regs_RtlUnwind( pEndFrame, unusedEip, pRecord, returnEax, &context );
|
2003-12-04 06:48:03 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-05-09 18:12:19 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* RtlRaiseStatus (NTDLL.@)
|
1999-05-09 18:12:19 +02:00
|
|
|
*
|
|
|
|
* Raise an exception with ExceptionCode = status
|
|
|
|
*/
|
|
|
|
void WINAPI RtlRaiseStatus( NTSTATUS status )
|
|
|
|
{
|
|
|
|
EXCEPTION_RECORD ExceptionRec;
|
|
|
|
|
|
|
|
ExceptionRec.ExceptionCode = status;
|
|
|
|
ExceptionRec.ExceptionFlags = EH_NONCONTINUABLE;
|
|
|
|
ExceptionRec.ExceptionRecord = NULL;
|
|
|
|
ExceptionRec.NumberParameters = 0;
|
|
|
|
RtlRaiseException( &ExceptionRec );
|
|
|
|
}
|
2000-08-06 04:42:46 +02:00
|
|
|
|
|
|
|
|
2003-10-28 22:22:50 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* RtlAddVectoredExceptionHandler (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PVOID WINAPI RtlAddVectoredExceptionHandler( ULONG first, PVECTORED_EXCEPTION_HANDLER func )
|
|
|
|
{
|
|
|
|
VECTORED_HANDLER *handler = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*handler) );
|
|
|
|
if (handler)
|
|
|
|
{
|
|
|
|
handler->func = func;
|
|
|
|
RtlEnterCriticalSection( &vectored_handlers_section );
|
|
|
|
if (first) list_add_head( &vectored_handlers, &handler->entry );
|
|
|
|
else list_add_tail( &vectored_handlers, &handler->entry );
|
|
|
|
RtlLeaveCriticalSection( &vectored_handlers_section );
|
|
|
|
}
|
|
|
|
return handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* RtlRemoveVectoredExceptionHandler (NTDLL.@)
|
|
|
|
*/
|
|
|
|
ULONG WINAPI RtlRemoveVectoredExceptionHandler( PVOID handler )
|
|
|
|
{
|
|
|
|
struct list *ptr;
|
|
|
|
ULONG ret = FALSE;
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &vectored_handlers_section );
|
|
|
|
LIST_FOR_EACH( ptr, &vectored_handlers )
|
|
|
|
{
|
2005-05-18 11:45:53 +02:00
|
|
|
VECTORED_HANDLER *curr_handler = LIST_ENTRY( ptr, VECTORED_HANDLER, entry );
|
|
|
|
if (curr_handler == handler)
|
2003-10-28 22:22:50 +01:00
|
|
|
{
|
|
|
|
list_remove( ptr );
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &vectored_handlers_section );
|
|
|
|
if (ret) RtlFreeHeap( GetProcessHeap(), 0, handler );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-12 01:34:30 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* RtlCaptureStackBackTrace [NTDLL.@]
|
|
|
|
*
|
|
|
|
* Captures stack backtrace
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* Skip [I] Number of stack frames to skip before starting a capture
|
|
|
|
* Count [I] Number of stack frames to capture into Buffer
|
|
|
|
* Buffer [O] Array of backtrace pointers captured from stack
|
|
|
|
* Hash [O] Optional pointer to variable where backtrace hash should be stored
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Number of captured stack frames or 0 if error occurred
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Unimplemented
|
|
|
|
*/
|
|
|
|
USHORT WINAPI RtlCaptureStackBackTrace(ULONG Skip, ULONG Count, PVOID *Buffer, ULONG *Hash)
|
|
|
|
{
|
|
|
|
FIXME("(%d, %d, %p, %p) stub!\n", Skip, Count, Buffer, Hash);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-25 17:27:44 +02:00
|
|
|
/*************************************************************
|
|
|
|
* __wine_spec_unimplemented_stub
|
|
|
|
*
|
|
|
|
* ntdll-specific implementation to avoid depending on kernel functions.
|
|
|
|
* Can be removed once ntdll.spec no longer contains stubs.
|
|
|
|
*/
|
|
|
|
void __wine_spec_unimplemented_stub( const char *module, const char *function )
|
|
|
|
{
|
|
|
|
EXCEPTION_RECORD record;
|
|
|
|
|
|
|
|
record.ExceptionCode = EXCEPTION_WINE_STUB;
|
|
|
|
record.ExceptionFlags = EH_NONCONTINUABLE;
|
|
|
|
record.ExceptionRecord = NULL;
|
|
|
|
record.ExceptionAddress = __wine_spec_unimplemented_stub;
|
|
|
|
record.NumberParameters = 2;
|
|
|
|
record.ExceptionInformation[0] = (ULONG_PTR)module;
|
|
|
|
record.ExceptionInformation[1] = (ULONG_PTR)function;
|
2008-12-29 12:43:59 +01:00
|
|
|
for (;;) RtlRaiseException( &record );
|
2005-08-25 17:27:44 +02:00
|
|
|
}
|