1999-09-27 12:58:45 +02:00
|
|
|
/*
|
|
|
|
* i386 signal handling routines
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
1999-09-27 12:58:45 +02:00
|
|
|
* 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-09-27 12:58:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-02-10 23:15:21 +01:00
|
|
|
#include <stdio.h>
|
2006-08-11 14:45:11 +02:00
|
|
|
#include <sys/types.h>
|
2000-11-29 21:04:09 +01:00
|
|
|
|
2009-04-08 19:38:02 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2002-12-10 23:56:43 +01:00
|
|
|
#include "windef.h"
|
2003-06-30 23:00:15 +02:00
|
|
|
#include "ntdll_misc.h"
|
2007-03-14 09:53:59 +01:00
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "wine/debug.h"
|
2000-02-26 17:51:13 +01:00
|
|
|
|
2017-11-29 19:42:53 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(seh);
|
|
|
|
|
2017-07-19 15:14:24 +02:00
|
|
|
struct x86_thread_data
|
|
|
|
{
|
|
|
|
DWORD fs; /* 1d4 TEB selector */
|
|
|
|
DWORD gs; /* 1d8 libc selector; update winebuild if you move this! */
|
2017-07-19 15:20:42 +02:00
|
|
|
DWORD dr0; /* 1dc debug registers */
|
|
|
|
DWORD dr1; /* 1e0 */
|
|
|
|
DWORD dr2; /* 1e4 */
|
|
|
|
DWORD dr3; /* 1e8 */
|
|
|
|
DWORD dr6; /* 1ec */
|
|
|
|
DWORD dr7; /* 1f0 */
|
|
|
|
void *exit_frame; /* 1f4 exit frame pointer */
|
2017-07-19 15:14:24 +02:00
|
|
|
};
|
|
|
|
|
2020-07-24 13:29:31 +02:00
|
|
|
C_ASSERT( sizeof(struct x86_thread_data) <= 16 * sizeof(void *) );
|
2020-07-23 20:35:00 +02:00
|
|
|
C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct x86_thread_data, gs ) == 0x1d8 );
|
|
|
|
C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct x86_thread_data, exit_frame ) == 0x1f4 );
|
2017-07-19 15:14:24 +02:00
|
|
|
|
|
|
|
static inline struct x86_thread_data *x86_thread_data(void)
|
|
|
|
{
|
2020-07-24 13:29:31 +02:00
|
|
|
return (struct x86_thread_data *)&NtCurrentTeb()->GdiTebBatch;
|
2017-07-19 15:14:24 +02:00
|
|
|
}
|
|
|
|
|
2020-06-29 12:10:00 +02:00
|
|
|
struct ldt_copy *__wine_ldt_copy = NULL;
|
|
|
|
|
2009-04-30 13:08:32 +02:00
|
|
|
/* Exception record for handling exceptions happening inside exception handlers */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
EXCEPTION_REGISTRATION_RECORD frame;
|
|
|
|
EXCEPTION_REGISTRATION_RECORD *prevFrame;
|
|
|
|
} EXC_NESTED_FRAME;
|
|
|
|
|
|
|
|
extern DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher,
|
|
|
|
PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler );
|
2003-09-18 06:39:13 +02:00
|
|
|
|
2011-02-01 12:18:39 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* is_valid_frame
|
|
|
|
*/
|
|
|
|
static inline BOOL is_valid_frame( void *frame )
|
|
|
|
{
|
|
|
|
if ((ULONG_PTR)frame & 3) return FALSE;
|
|
|
|
return (frame >= NtCurrentTeb()->Tib.StackLimit &&
|
|
|
|
(void **)frame < (void **)NtCurrentTeb()->Tib.StackBase - 1);
|
|
|
|
}
|
|
|
|
|
2009-04-30 13:08:32 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* raise_handler
|
|
|
|
*
|
|
|
|
* Handler for exceptions happening inside a handler.
|
|
|
|
*/
|
|
|
|
static DWORD raise_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* unwind_handler
|
|
|
|
*
|
|
|
|
* Handler for exceptions happening inside an unwind handler.
|
|
|
|
*/
|
|
|
|
static DWORD unwind_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
|
|
|
|
CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* call_stack_handlers
|
|
|
|
*
|
|
|
|
* Call the stack handlers chain.
|
|
|
|
*/
|
|
|
|
static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
|
|
|
|
{
|
|
|
|
EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame;
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
frame = NtCurrentTeb()->Tib.ExceptionList;
|
|
|
|
nested_frame = NULL;
|
|
|
|
while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL)
|
|
|
|
{
|
|
|
|
/* Check frame address */
|
2011-02-01 12:18:39 +01:00
|
|
|
if (!is_valid_frame( frame ))
|
2009-04-30 13:08:32 +02:00
|
|
|
{
|
|
|
|
rec->ExceptionFlags |= EH_STACK_INVALID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call handler */
|
|
|
|
TRACE( "calling handler at %p code=%x flags=%x\n",
|
|
|
|
frame->Handler, rec->ExceptionCode, rec->ExceptionFlags );
|
|
|
|
res = EXC_CallHandler( rec, frame, context, &dispatch, frame->Handler, raise_handler );
|
|
|
|
TRACE( "handler at %p returned %x\n", frame->Handler, res );
|
|
|
|
|
|
|
|
if (frame == nested_frame)
|
|
|
|
{
|
|
|
|
/* no longer nested */
|
|
|
|
nested_frame = NULL;
|
|
|
|
rec->ExceptionFlags &= ~EH_NESTED_CALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(res)
|
|
|
|
{
|
|
|
|
case ExceptionContinueExecution:
|
|
|
|
if (!(rec->ExceptionFlags & EH_NONCONTINUABLE)) return STATUS_SUCCESS;
|
|
|
|
return STATUS_NONCONTINUABLE_EXCEPTION;
|
|
|
|
case ExceptionContinueSearch:
|
|
|
|
break;
|
|
|
|
case ExceptionNestedException:
|
|
|
|
if (nested_frame < dispatch) nested_frame = dispatch;
|
|
|
|
rec->ExceptionFlags |= EH_NESTED_CALL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return STATUS_INVALID_DISPOSITION;
|
|
|
|
}
|
|
|
|
frame = frame->Prev;
|
|
|
|
}
|
|
|
|
return STATUS_UNHANDLED_EXCEPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2020-06-06 13:56:19 +02:00
|
|
|
* KiUserExceptionDispatcher (NTDLL.@)
|
2009-04-30 13:08:32 +02:00
|
|
|
*/
|
2020-07-03 12:22:23 +02:00
|
|
|
NTSTATUS WINAPI dispatch_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
|
2009-04-30 13:08:32 +02:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
2020-06-06 13:56:19 +02:00
|
|
|
DWORD c;
|
|
|
|
|
|
|
|
TRACE( "code=%x flags=%x addr=%p ip=%08x tid=%04x\n",
|
|
|
|
rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
|
|
|
|
context->Eip, GetCurrentThreadId() );
|
|
|
|
for (c = 0; c < rec->NumberParameters; c++)
|
|
|
|
TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] );
|
2009-04-30 13:08:32 +02:00
|
|
|
|
2020-06-06 13:56:19 +02:00
|
|
|
if (rec->ExceptionCode == EXCEPTION_WINE_STUB)
|
2009-04-30 13:08:32 +02:00
|
|
|
{
|
2020-06-06 13:56:19 +02:00
|
|
|
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] );
|
2009-04-30 13:08:32 +02:00
|
|
|
else
|
2020-06-06 13:56:19 +02:00
|
|
|
MESSAGE( "wine: Call from %p to unimplemented function %s.%ld, aborting\n",
|
|
|
|
rec->ExceptionAddress,
|
|
|
|
(char*)rec->ExceptionInformation[0], rec->ExceptionInformation[1] );
|
|
|
|
}
|
2021-02-05 10:21:28 +01:00
|
|
|
else if (rec->ExceptionCode == EXCEPTION_WINE_NAME_THREAD && rec->ExceptionInformation[0] == 0x1000)
|
|
|
|
{
|
|
|
|
WARN( "Thread %04x renamed to %s\n", (DWORD)rec->ExceptionInformation[2], debugstr_a((char *)rec->ExceptionInformation[1]) );
|
|
|
|
}
|
2021-02-05 10:21:29 +01:00
|
|
|
else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_C)
|
|
|
|
{
|
|
|
|
WARN( "%s\n", debugstr_an((char *)rec->ExceptionInformation[1], rec->ExceptionInformation[0] - 1) );
|
|
|
|
}
|
|
|
|
else if (rec->ExceptionCode == DBG_PRINTEXCEPTION_WIDE_C)
|
|
|
|
{
|
|
|
|
WARN( "%s\n", debugstr_wn((WCHAR *)rec->ExceptionInformation[1], rec->ExceptionInformation[0] - 1) );
|
|
|
|
}
|
2020-06-06 13:56:19 +02:00
|
|
|
else
|
|
|
|
{
|
2021-03-03 10:50:35 +01:00
|
|
|
if (rec->ExceptionCode == STATUS_ASSERTION_FAILURE)
|
|
|
|
ERR( "%s exception (code=%x) raised\n", debugstr_exception_code(rec->ExceptionCode), rec->ExceptionCode );
|
2021-02-05 10:21:30 +01:00
|
|
|
else
|
|
|
|
WARN( "%s exception (code=%x) raised\n", debugstr_exception_code(rec->ExceptionCode), rec->ExceptionCode );
|
|
|
|
|
2020-06-06 13:56:19 +02:00
|
|
|
TRACE(" eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n",
|
|
|
|
context->Eax, context->Ebx, context->Ecx,
|
|
|
|
context->Edx, context->Esi, context->Edi );
|
|
|
|
TRACE(" ebp=%08x esp=%08x cs=%04x ds=%04x es=%04x fs=%04x gs=%04x flags=%08x\n",
|
|
|
|
context->Ebp, context->Esp, context->SegCs, context->SegDs,
|
|
|
|
context->SegEs, context->SegFs, context->SegGs, context->EFlags );
|
|
|
|
}
|
2009-04-30 13:08:32 +02:00
|
|
|
|
2020-06-06 13:56:19 +02:00
|
|
|
if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION)
|
2020-06-06 15:17:07 +02:00
|
|
|
NtContinue( context, FALSE );
|
2009-04-30 13:08:32 +02:00
|
|
|
|
2020-06-06 13:56:19 +02:00
|
|
|
if ((status = call_stack_handlers( rec, context )) == STATUS_SUCCESS)
|
2020-06-06 15:17:07 +02:00
|
|
|
NtContinue( context, FALSE );
|
2009-04-30 13:08:32 +02:00
|
|
|
|
2020-06-06 13:56:19 +02:00
|
|
|
if (status != STATUS_UNHANDLED_EXCEPTION) RtlRaiseStatus( status );
|
|
|
|
return NtRaiseException( rec, context, FALSE );
|
2009-04-30 13:08:32 +02:00
|
|
|
}
|
|
|
|
|
2020-07-03 12:22:23 +02:00
|
|
|
__ASM_STDCALL_FUNC( KiUserExceptionDispatcher, 8,
|
|
|
|
"pushl 4(%esp)\n\t"
|
|
|
|
"pushl 4(%esp)\n\t"
|
|
|
|
"call " __ASM_STDCALL("dispatch_exception", 8) "\n\t"
|
|
|
|
"int3" )
|
2009-04-30 13:08:32 +02:00
|
|
|
|
2020-12-17 00:05:05 +01:00
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* KiUserApcDispatcher (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI KiUserApcDispatcher( CONTEXT *context, ULONG_PTR ctx, ULONG_PTR arg1, ULONG_PTR arg2,
|
|
|
|
PNTAPCFUNC func )
|
|
|
|
{
|
|
|
|
func( ctx, arg1, arg2 );
|
|
|
|
NtContinue( context, TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-20 15:40:28 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* save_fpu
|
|
|
|
*
|
|
|
|
* Save the thread FPU context.
|
|
|
|
*/
|
2007-03-17 11:28:32 +01:00
|
|
|
static inline void save_fpu( CONTEXT *context )
|
2006-04-20 15:40:28 +02:00
|
|
|
{
|
|
|
|
#ifdef __GNUC__
|
2019-03-04 14:05:16 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
DWORD ControlWord;
|
|
|
|
DWORD StatusWord;
|
|
|
|
DWORD TagWord;
|
|
|
|
DWORD ErrorOffset;
|
|
|
|
DWORD ErrorSelector;
|
|
|
|
DWORD DataOffset;
|
|
|
|
DWORD DataSelector;
|
|
|
|
}
|
|
|
|
float_status;
|
|
|
|
|
2006-04-20 15:40:28 +02:00
|
|
|
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
|
|
|
__asm__ __volatile__( "fnsave %0; fwait" : "=m" (context->FloatSave) );
|
2019-03-04 14:05:16 +01:00
|
|
|
|
|
|
|
/* Reset unmasked exceptions status to avoid firing an exception. */
|
|
|
|
memcpy(&float_status, &context->FloatSave, sizeof(float_status));
|
|
|
|
float_status.StatusWord &= float_status.ControlWord | 0xffffff80;
|
|
|
|
|
2019-03-06 12:09:33 +01:00
|
|
|
__asm__ __volatile__( "fldenv %0" : : "m" (float_status) );
|
2006-04-20 15:40:28 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 19:46:16 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* save_fpux
|
|
|
|
*
|
|
|
|
* Save the thread FPU extended context.
|
|
|
|
*/
|
|
|
|
static inline void save_fpux( CONTEXT *context )
|
|
|
|
{
|
|
|
|
#ifdef __GNUC__
|
|
|
|
/* we have to enforce alignment by hand */
|
2020-08-19 23:22:56 +02:00
|
|
|
char buffer[sizeof(XSAVE_FORMAT) + 16];
|
|
|
|
XSAVE_FORMAT *state = (XSAVE_FORMAT *)(((ULONG_PTR)buffer + 15) & ~15);
|
2019-02-14 19:46:16 +01:00
|
|
|
|
|
|
|
context->ContextFlags |= CONTEXT_EXTENDED_REGISTERS;
|
|
|
|
__asm__ __volatile__( "fxsave %0" : "=m" (*state) );
|
|
|
|
memcpy( context->ExtendedRegisters, state, sizeof(*state) );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-20 15:40:28 +02:00
|
|
|
/***********************************************************************
|
2009-01-06 17:50:34 +01:00
|
|
|
* RtlCaptureContext (NTDLL.@)
|
2006-04-20 15:40:28 +02:00
|
|
|
*/
|
2011-02-01 12:13:19 +01:00
|
|
|
__ASM_STDCALL_FUNC( RtlCaptureContext, 4,
|
|
|
|
"pushl %eax\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
"movl 8(%esp),%eax\n\t" /* context */
|
|
|
|
"movl $0x10007,(%eax)\n\t" /* context->ContextFlags */
|
|
|
|
"movw %gs,0x8c(%eax)\n\t" /* context->SegGs */
|
|
|
|
"movw %fs,0x90(%eax)\n\t" /* context->SegFs */
|
|
|
|
"movw %es,0x94(%eax)\n\t" /* context->SegEs */
|
|
|
|
"movw %ds,0x98(%eax)\n\t" /* context->SegDs */
|
|
|
|
"movl %edi,0x9c(%eax)\n\t" /* context->Edi */
|
|
|
|
"movl %esi,0xa0(%eax)\n\t" /* context->Esi */
|
|
|
|
"movl %ebx,0xa4(%eax)\n\t" /* context->Ebx */
|
|
|
|
"movl %edx,0xa8(%eax)\n\t" /* context->Edx */
|
|
|
|
"movl %ecx,0xac(%eax)\n\t" /* context->Ecx */
|
2017-07-24 10:39:42 +02:00
|
|
|
"movl 0(%ebp),%edx\n\t"
|
|
|
|
"movl %edx,0xb4(%eax)\n\t" /* context->Ebp */
|
|
|
|
"movl 4(%ebp),%edx\n\t"
|
2011-02-01 12:13:19 +01:00
|
|
|
"movl %edx,0xb8(%eax)\n\t" /* context->Eip */
|
|
|
|
"movw %cs,0xbc(%eax)\n\t" /* context->SegCs */
|
|
|
|
"pushfl\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
"popl 0xc0(%eax)\n\t" /* context->EFlags */
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
|
2017-07-24 10:39:42 +02:00
|
|
|
"leal 8(%ebp),%edx\n\t"
|
2011-02-01 12:13:19 +01:00
|
|
|
"movl %edx,0xc4(%eax)\n\t" /* context->Esp */
|
|
|
|
"movw %ss,0xc8(%eax)\n\t" /* context->SegSs */
|
|
|
|
"popl 0xb0(%eax)\n\t" /* context->Eax */
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
|
|
|
|
"ret $4" )
|
2006-04-20 15:40:28 +02:00
|
|
|
|
2005-12-19 09:59:50 +01:00
|
|
|
|
2009-04-30 13:08:32 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* RtlUnwind (NTDLL.@)
|
|
|
|
*/
|
2017-07-25 11:48:24 +02:00
|
|
|
void WINAPI DECLSPEC_HIDDEN __regs_RtlUnwind( EXCEPTION_REGISTRATION_RECORD* pEndFrame, PVOID targetIp,
|
|
|
|
PEXCEPTION_RECORD pRecord, PVOID retval, CONTEXT *context )
|
2009-04-30 13:08:32 +02:00
|
|
|
{
|
|
|
|
EXCEPTION_RECORD record;
|
|
|
|
EXCEPTION_REGISTRATION_RECORD *frame, *dispatch;
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
context->Eax = (DWORD)retval;
|
|
|
|
|
|
|
|
/* build an exception record, if we do not have one */
|
|
|
|
if (!pRecord)
|
|
|
|
{
|
|
|
|
record.ExceptionCode = STATUS_UNWIND;
|
|
|
|
record.ExceptionFlags = 0;
|
|
|
|
record.ExceptionRecord = NULL;
|
|
|
|
record.ExceptionAddress = (void *)context->Eip;
|
|
|
|
record.NumberParameters = 0;
|
|
|
|
pRecord = &record;
|
|
|
|
}
|
|
|
|
|
|
|
|
pRecord->ExceptionFlags |= EH_UNWINDING | (pEndFrame ? 0 : EH_EXIT_UNWIND);
|
|
|
|
|
|
|
|
TRACE( "code=%x flags=%x\n", pRecord->ExceptionCode, pRecord->ExceptionFlags );
|
2017-07-24 10:59:45 +02:00
|
|
|
TRACE( "eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n",
|
|
|
|
context->Eax, context->Ebx, context->Ecx, context->Edx, context->Esi, context->Edi );
|
|
|
|
TRACE( "ebp=%08x esp=%08x eip=%08x cs=%04x ds=%04x fs=%04x gs=%04x flags=%08x\n",
|
|
|
|
context->Ebp, context->Esp, context->Eip, LOWORD(context->SegCs), LOWORD(context->SegDs),
|
|
|
|
LOWORD(context->SegFs), LOWORD(context->SegGs), context->EFlags );
|
2009-04-30 13:08:32 +02:00
|
|
|
|
|
|
|
/* get chain of exception frames */
|
|
|
|
frame = NtCurrentTeb()->Tib.ExceptionList;
|
|
|
|
while ((frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) && (frame != pEndFrame))
|
|
|
|
{
|
|
|
|
/* Check frame address */
|
|
|
|
if (pEndFrame && (frame > pEndFrame))
|
|
|
|
raise_status( STATUS_INVALID_UNWIND_TARGET, pRecord );
|
|
|
|
|
2011-02-01 12:18:39 +01:00
|
|
|
if (!is_valid_frame( frame )) raise_status( STATUS_BAD_STACK, pRecord );
|
2009-04-30 13:08:32 +02:00
|
|
|
|
|
|
|
/* Call handler */
|
|
|
|
TRACE( "calling handler at %p code=%x flags=%x\n",
|
|
|
|
frame->Handler, pRecord->ExceptionCode, pRecord->ExceptionFlags );
|
|
|
|
res = EXC_CallHandler( pRecord, frame, context, &dispatch, frame->Handler, unwind_handler );
|
|
|
|
TRACE( "handler at %p returned %x\n", frame->Handler, res );
|
|
|
|
|
|
|
|
switch(res)
|
|
|
|
{
|
|
|
|
case ExceptionContinueSearch:
|
|
|
|
break;
|
|
|
|
case ExceptionCollidedUnwind:
|
|
|
|
frame = dispatch;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
raise_status( STATUS_INVALID_DISPOSITION, pRecord );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = __wine_pop_frame( frame );
|
|
|
|
}
|
2020-06-06 15:17:07 +02:00
|
|
|
NtContinue( context, FALSE );
|
2009-04-30 13:08:32 +02:00
|
|
|
}
|
2017-07-24 10:59:45 +02:00
|
|
|
__ASM_STDCALL_FUNC( RtlUnwind, 16,
|
|
|
|
"pushl %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
|
|
|
"movl %esp,%ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
|
|
|
"leal -(0x2cc+8)(%esp),%esp\n\t" /* sizeof(CONTEXT) + alignment */
|
2018-03-09 20:47:01 +01:00
|
|
|
"pushl %eax\n\t"
|
|
|
|
"leal 4(%esp),%eax\n\t" /* context */
|
|
|
|
"xchgl %eax,(%esp)\n\t"
|
2019-05-16 18:13:45 +02:00
|
|
|
"call " __ASM_STDCALL("RtlCaptureContext",4) "\n\t"
|
2017-07-24 10:59:45 +02:00
|
|
|
"leal 24(%ebp),%eax\n\t"
|
|
|
|
"movl %eax,0xc4(%esp)\n\t" /* context->Esp */
|
|
|
|
"pushl %esp\n\t"
|
|
|
|
"pushl 20(%ebp)\n\t"
|
|
|
|
"pushl 16(%ebp)\n\t"
|
|
|
|
"pushl 12(%ebp)\n\t"
|
|
|
|
"pushl 8(%ebp)\n\t"
|
2019-05-16 18:13:45 +02:00
|
|
|
"call " __ASM_STDCALL("__regs_RtlUnwind",20) "\n\t"
|
2017-07-24 10:59:45 +02:00
|
|
|
"leave\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
|
|
|
"ret $16" ) /* actually never returns */
|
2009-04-30 13:08:32 +02:00
|
|
|
|
|
|
|
|
2019-01-02 17:24:48 +01:00
|
|
|
/*******************************************************************
|
|
|
|
* raise_exception_full_context
|
|
|
|
*
|
|
|
|
* Raise an exception with the full CPU context.
|
|
|
|
*/
|
2019-09-18 18:09:11 +02:00
|
|
|
void raise_exception_full_context( EXCEPTION_RECORD *rec, CONTEXT *context )
|
2019-01-02 17:24:48 +01:00
|
|
|
{
|
|
|
|
save_fpu( context );
|
2019-02-14 19:51:35 +01:00
|
|
|
save_fpux( context );
|
|
|
|
/* FIXME: xstate */
|
|
|
|
context->Dr0 = x86_thread_data()->dr0;
|
|
|
|
context->Dr1 = x86_thread_data()->dr1;
|
|
|
|
context->Dr2 = x86_thread_data()->dr2;
|
|
|
|
context->Dr3 = x86_thread_data()->dr3;
|
|
|
|
context->Dr6 = x86_thread_data()->dr6;
|
|
|
|
context->Dr7 = x86_thread_data()->dr7;
|
|
|
|
context->ContextFlags |= CONTEXT_DEBUG_REGISTERS;
|
|
|
|
|
2019-09-18 18:09:11 +02:00
|
|
|
RtlRaiseStatus( NtRaiseException( rec, context, TRUE ));
|
2019-01-02 17:24:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-10 13:14:05 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlRaiseException (NTDLL.@)
|
|
|
|
*/
|
2017-07-20 13:35:53 +02:00
|
|
|
__ASM_STDCALL_FUNC( RtlRaiseException, 4,
|
2017-07-24 10:39:42 +02:00
|
|
|
"pushl %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
|
|
|
"movl %esp,%ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
2017-07-20 13:35:53 +02:00
|
|
|
"leal -0x2cc(%esp),%esp\n\t" /* sizeof(CONTEXT) */
|
|
|
|
"pushl %esp\n\t" /* context */
|
2019-05-16 18:13:45 +02:00
|
|
|
"call " __ASM_STDCALL("RtlCaptureContext",4) "\n\t"
|
2017-07-24 10:39:42 +02:00
|
|
|
"movl 4(%ebp),%eax\n\t" /* return address */
|
|
|
|
"movl 8(%ebp),%ecx\n\t" /* rec */
|
2017-07-20 13:35:53 +02:00
|
|
|
"movl %eax,12(%ecx)\n\t" /* rec->ExceptionAddress */
|
2017-07-24 10:39:42 +02:00
|
|
|
"leal 12(%ebp),%eax\n\t"
|
2017-07-20 13:35:53 +02:00
|
|
|
"movl %eax,0xc4(%esp)\n\t" /* context->Esp */
|
|
|
|
"movl %esp,%eax\n\t"
|
|
|
|
"pushl %eax\n\t"
|
|
|
|
"pushl %ecx\n\t"
|
2019-01-02 17:24:48 +01:00
|
|
|
"call " __ASM_NAME("raise_exception_full_context") "\n\t"
|
2017-07-24 10:39:42 +02:00
|
|
|
"leave\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
2017-07-20 13:35:53 +02:00
|
|
|
"ret $4" ) /* actually never returns */
|
2009-04-10 13:14:05 +02:00
|
|
|
|
|
|
|
|
2009-11-11 17:19:23 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* RtlCaptureStackBackTrace (NTDLL.@)
|
|
|
|
*/
|
|
|
|
USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
|
|
|
|
{
|
2009-11-11 17:38:18 +01:00
|
|
|
CONTEXT context;
|
|
|
|
ULONG i;
|
|
|
|
ULONG *frame;
|
|
|
|
|
|
|
|
RtlCaptureContext( &context );
|
|
|
|
if (hash) *hash = 0;
|
|
|
|
frame = (ULONG *)context.Ebp;
|
|
|
|
|
|
|
|
while (skip--)
|
|
|
|
{
|
2011-02-01 12:18:39 +01:00
|
|
|
if (!is_valid_frame( frame )) return 0;
|
2009-11-11 17:38:18 +01:00
|
|
|
frame = (ULONG *)*frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2011-02-01 12:18:39 +01:00
|
|
|
if (!is_valid_frame( frame )) break;
|
2009-11-11 17:38:18 +01:00
|
|
|
buffer[i] = (void *)frame[1];
|
|
|
|
if (hash) *hash += frame[1];
|
|
|
|
frame = (ULONG *)*frame;
|
|
|
|
}
|
|
|
|
return i;
|
2009-11-11 17:19:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-20 15:27:30 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* signal_start_thread
|
|
|
|
*/
|
|
|
|
__ASM_GLOBAL_FUNC( signal_start_thread,
|
|
|
|
"movl 4(%esp),%esi\n\t" /* context */
|
2021-03-31 12:23:37 +02:00
|
|
|
"leal -12(%esi),%edi\n\t"
|
2020-08-27 11:58:26 +02:00
|
|
|
/* clear the thread stack */
|
2021-03-31 12:23:37 +02:00
|
|
|
"andl $~0xfff,%edi\n\t" /* round down to page size */
|
|
|
|
"movl $0xf0000,%ecx\n\t"
|
|
|
|
"subl %ecx,%edi\n\t"
|
2020-08-27 11:58:26 +02:00
|
|
|
"movl %edi,%esp\n\t"
|
|
|
|
"xorl %eax,%eax\n\t"
|
|
|
|
"shrl $2,%ecx\n\t"
|
|
|
|
"rep; stosl\n\t"
|
2020-08-20 15:27:30 +02:00
|
|
|
/* switch to the initial context */
|
2020-08-27 11:58:26 +02:00
|
|
|
"leal -12(%esi),%esp\n\t"
|
2020-08-20 15:27:30 +02:00
|
|
|
"movl $1,4(%esp)\n\t"
|
|
|
|
"movl %esi,(%esp)\n\t"
|
|
|
|
"call " __ASM_STDCALL("NtContinue", 8) )
|
|
|
|
|
2000-03-07 14:10:21 +01:00
|
|
|
/**********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* DbgBreakPoint (NTDLL.@)
|
2000-03-07 14:10:21 +01:00
|
|
|
*/
|
2020-06-24 10:03:10 +02:00
|
|
|
__ASM_STDCALL_FUNC( DbgBreakPoint, 0, "int $3; ret"
|
|
|
|
"\n\tnop; nop; nop; nop; nop; nop; nop; nop"
|
|
|
|
"\n\tnop; nop; nop; nop; nop; nop" );
|
2000-03-07 14:10:21 +01:00
|
|
|
|
|
|
|
/**********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* DbgUserBreakPoint (NTDLL.@)
|
2000-03-07 14:10:21 +01:00
|
|
|
*/
|
2020-06-24 10:03:10 +02:00
|
|
|
__ASM_STDCALL_FUNC( DbgUserBreakPoint, 0, "int $3; ret"
|
|
|
|
"\n\tnop; nop; nop; nop; nop; nop; nop; nop"
|
|
|
|
"\n\tnop; nop; nop; nop; nop; nop" );
|
2000-03-07 14:10:21 +01:00
|
|
|
|
2009-02-18 13:04:50 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* NtCurrentTeb (NTDLL.@)
|
|
|
|
*/
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC( NtCurrentTeb, 0, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" )
|
2009-02-18 13:04:50 +01:00
|
|
|
|
2005-10-31 15:08:05 +01:00
|
|
|
|
2012-04-02 12:45:43 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* _chkstk (NTDLL.@)
|
|
|
|
*/
|
2020-05-05 16:28:42 +02:00
|
|
|
__ASM_GLOBAL_FUNC( _chkstk,
|
2012-04-02 12:45:43 +02:00
|
|
|
"negl %eax\n\t"
|
|
|
|
"addl %esp,%eax\n\t"
|
|
|
|
"xchgl %esp,%eax\n\t"
|
|
|
|
"movl 0(%eax),%eax\n\t" /* copy return address from old location */
|
|
|
|
"movl %eax,0(%esp)\n\t"
|
|
|
|
"ret" )
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* _alloca_probe (NTDLL.@)
|
|
|
|
*/
|
2020-05-05 16:28:42 +02:00
|
|
|
__ASM_GLOBAL_FUNC( _alloca_probe,
|
2012-04-02 12:45:43 +02:00
|
|
|
"negl %eax\n\t"
|
|
|
|
"addl %esp,%eax\n\t"
|
|
|
|
"xchgl %esp,%eax\n\t"
|
|
|
|
"movl 0(%eax),%eax\n\t" /* copy return address from old location */
|
|
|
|
"movl %eax,0(%esp)\n\t"
|
|
|
|
"ret" )
|
|
|
|
|
|
|
|
|
2005-10-31 15:08:05 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* EXC_CallHandler (internal)
|
2005-11-01 10:21:03 +01:00
|
|
|
*
|
|
|
|
* Some exception handlers depend on EBP to have a fixed position relative to
|
|
|
|
* the exception frame.
|
|
|
|
* Shrinker depends on (*1) doing what it does,
|
|
|
|
* (*2) being the exact instruction it is and (*3) beginning with 0x64
|
|
|
|
* (i.e. the %fs prefix to the movl instruction). It also depends on the
|
|
|
|
* function calling the handler having only 5 parameters (*4).
|
2005-10-31 15:08:05 +01:00
|
|
|
*/
|
|
|
|
__ASM_GLOBAL_FUNC( EXC_CallHandler,
|
2009-06-25 12:02:53 +02:00
|
|
|
"pushl %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
|
|
|
"movl %esp,%ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
|
|
|
"pushl %ebx\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebx,-4\n\t")
|
|
|
|
"movl 28(%ebp), %edx\n\t" /* ugly hack to pass the 6th param needed because of Shrinker */
|
|
|
|
"pushl 24(%ebp)\n\t"
|
|
|
|
"pushl 20(%ebp)\n\t"
|
|
|
|
"pushl 16(%ebp)\n\t"
|
|
|
|
"pushl 12(%ebp)\n\t"
|
|
|
|
"pushl 8(%ebp)\n\t"
|
|
|
|
"call " __ASM_NAME("call_exception_handler") "\n\t"
|
|
|
|
"popl %ebx\n\t"
|
|
|
|
__ASM_CFI(".cfi_same_value %ebx\n\t")
|
|
|
|
"leave\n"
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
|
|
|
"ret" )
|
2005-11-01 10:21:03 +01:00
|
|
|
__ASM_GLOBAL_FUNC(call_exception_handler,
|
2009-06-25 12:02:53 +02:00
|
|
|
"pushl %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
|
|
|
"movl %esp,%ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
|
|
|
"subl $12,%esp\n\t"
|
|
|
|
"pushl 12(%ebp)\n\t" /* make any exceptions in this... */
|
|
|
|
"pushl %edx\n\t" /* handler be handled by... */
|
|
|
|
".byte 0x64\n\t"
|
|
|
|
"pushl (0)\n\t" /* nested_handler (passed in edx). */
|
|
|
|
".byte 0x64\n\t"
|
|
|
|
"movl %esp,(0)\n\t" /* push the new exception frame onto the exception stack. */
|
|
|
|
"pushl 20(%ebp)\n\t"
|
|
|
|
"pushl 16(%ebp)\n\t"
|
|
|
|
"pushl 12(%ebp)\n\t"
|
|
|
|
"pushl 8(%ebp)\n\t"
|
|
|
|
"movl 24(%ebp), %ecx\n\t" /* (*1) */
|
|
|
|
"call *%ecx\n\t" /* call handler. (*2) */
|
|
|
|
".byte 0x64\n\t"
|
|
|
|
"movl (0), %esp\n\t" /* restore previous... (*3) */
|
|
|
|
".byte 0x64\n\t"
|
|
|
|
"popl (0)\n\t" /* exception frame. */
|
|
|
|
"movl %ebp, %esp\n\t" /* restore saved stack, in case it was corrupted */
|
|
|
|
"popl %ebp\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
|
|
|
"ret $20" ) /* (*4) */
|
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
#endif /* __i386__ */
|