2010-09-18 18:02:12 +02:00
|
|
|
/*
|
|
|
|
* ARM signal handling routines
|
|
|
|
*
|
|
|
|
* Copyright 2002 Marcus Meissner, SuSE Linux AG
|
2015-03-26 23:16:49 +01:00
|
|
|
* Copyright 2010-2013, 2015 André Hentschel
|
2010-09-18 18:02:12 +02: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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __arm__
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2013-03-23 17:24:04 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2010-09-18 18:02:12 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "ntdll_misc.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(seh);
|
|
|
|
|
2015-03-26 23:16:49 +01:00
|
|
|
|
2011-04-15 19:37:58 +02: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);
|
|
|
|
}
|
|
|
|
|
2010-09-18 18:02:12 +02:00
|
|
|
|
2015-05-28 22:38:53 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* __chkstk (NTDLL.@)
|
|
|
|
*
|
2015-06-15 21:22:45 +02:00
|
|
|
* Incoming r4 contains words to allocate, converting to bytes then return
|
2015-05-28 22:38:53 +02:00
|
|
|
*/
|
2015-06-15 21:22:45 +02:00
|
|
|
__ASM_GLOBAL_FUNC( __chkstk, "lsl r4, r4, #2\n\t"
|
|
|
|
"bx lr" )
|
2010-09-18 18:02:12 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlCaptureContext (NTDLL.@)
|
|
|
|
*/
|
2011-04-15 19:32:55 +02:00
|
|
|
__ASM_STDCALL_FUNC( RtlCaptureContext, 4,
|
2021-01-18 11:43:55 +01:00
|
|
|
"str r0, [r0, #0x4]\n\t" /* context->R0 */
|
|
|
|
"str r1, [r0, #0x8]\n\t" /* context->R1 */
|
2017-12-14 18:34:19 +01:00
|
|
|
"mov r1, #0x0200000\n\t" /* CONTEXT_ARM */
|
|
|
|
"add r1, r1, #0x3\n\t" /* CONTEXT_FULL */
|
|
|
|
"str r1, [r0]\n\t" /* context->ContextFlags */
|
2011-04-20 20:02:52 +02:00
|
|
|
"str SP, [r0, #0x38]\n\t" /* context->Sp */
|
|
|
|
"str LR, [r0, #0x3c]\n\t" /* context->Lr */
|
2020-07-28 14:16:53 +02:00
|
|
|
"str LR, [r0, #0x40]\n\t" /* context->Pc */
|
2011-04-15 19:32:55 +02:00
|
|
|
"mrs r1, CPSR\n\t"
|
2021-01-18 11:43:55 +01:00
|
|
|
"tst lr, #1\n\t" /* Thumb? */
|
|
|
|
"ite ne\n\t"
|
|
|
|
"orrne r1, r1, #0x20\n\t"
|
|
|
|
"biceq r1, r1, #0x20\n\t"
|
2011-04-20 20:02:52 +02:00
|
|
|
"str r1, [r0, #0x44]\n\t" /* context->Cpsr */
|
2021-01-18 11:43:55 +01:00
|
|
|
"add r0, #0x0c\n\t"
|
|
|
|
"stm r0, {r2-r12}\n\t" /* context->R2..R12 */
|
2015-05-28 22:39:01 +02:00
|
|
|
"bx lr"
|
2011-04-15 19:32:55 +02:00
|
|
|
)
|
2010-09-18 18:02:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* call_stack_handlers
|
|
|
|
*
|
|
|
|
* Call the stack handlers chain.
|
|
|
|
*/
|
|
|
|
static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
|
|
|
|
{
|
2011-04-15 19:37:58 +02:00
|
|
|
EXCEPTION_REGISTRATION_RECORD *frame, *dispatch, *nested_frame;
|
|
|
|
DWORD res;
|
2010-09-18 18:02:12 +02:00
|
|
|
|
2011-04-15 19:37:58 +02:00
|
|
|
frame = NtCurrentTeb()->Tib.ExceptionList;
|
|
|
|
nested_frame = NULL;
|
|
|
|
while (frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL)
|
|
|
|
{
|
|
|
|
/* Check frame address */
|
|
|
|
if (!is_valid_frame( frame ))
|
|
|
|
{
|
|
|
|
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 = frame->Handler( rec, frame, context, &dispatch );
|
|
|
|
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;
|
|
|
|
}
|
2010-09-18 18:02:12 +02:00
|
|
|
return STATUS_UNHANDLED_EXCEPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-06 13:56:19 +02:00
|
|
|
/*******************************************************************
|
|
|
|
* KiUserExceptionDispatcher (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI KiUserExceptionDispatcher( EXCEPTION_RECORD *rec, CONTEXT *context )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
DWORD c;
|
|
|
|
|
|
|
|
TRACE( "code=%x flags=%x addr=%p pc=%08x tid=%04x\n",
|
|
|
|
rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
|
|
|
|
context->Pc, GetCurrentThreadId() );
|
|
|
|
for (c = 0; c < rec->NumberParameters; c++)
|
|
|
|
TRACE( " info[%d]=%08lx\n", c, rec->ExceptionInformation[c] );
|
|
|
|
|
|
|
|
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] );
|
|
|
|
}
|
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( " r0=%08x r1=%08x r2=%08x r3=%08x r4=%08x r5=%08x\n",
|
|
|
|
context->R0, context->R1, context->R2, context->R3, context->R4, context->R5 );
|
|
|
|
TRACE( " r6=%08x r7=%08x r8=%08x r9=%08x r10=%08x r11=%08x\n",
|
|
|
|
context->R6, context->R7, context->R8, context->R9, context->R10, context->R11 );
|
|
|
|
TRACE( " r12=%08x sp=%08x lr=%08x pc=%08x cpsr=%08x\n",
|
|
|
|
context->R12, context->Sp, context->Lr, context->Pc, context->Cpsr );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION)
|
2020-06-06 15:17:07 +02:00
|
|
|
NtContinue( context, FALSE );
|
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 );
|
2020-06-06 13:56:19 +02:00
|
|
|
|
|
|
|
if (status != STATUS_UNHANDLED_EXCEPTION) RtlRaiseStatus( status );
|
|
|
|
return NtRaiseException( rec, context, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-18 18:02:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlUnwind (NTDLL.@)
|
|
|
|
*/
|
2013-02-13 16:36:41 +01:00
|
|
|
void WINAPI RtlUnwind( void *endframe, void *target_ip, EXCEPTION_RECORD *rec, void *retval )
|
2010-09-18 18:02:12 +02:00
|
|
|
{
|
2013-02-13 16:36:41 +01:00
|
|
|
CONTEXT context;
|
|
|
|
EXCEPTION_RECORD record;
|
|
|
|
EXCEPTION_REGISTRATION_RECORD *frame, *dispatch;
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
RtlCaptureContext( &context );
|
|
|
|
context.R0 = (DWORD)retval;
|
|
|
|
|
|
|
|
/* build an exception record, if we do not have one */
|
|
|
|
if (!rec)
|
|
|
|
{
|
|
|
|
record.ExceptionCode = STATUS_UNWIND;
|
|
|
|
record.ExceptionFlags = 0;
|
|
|
|
record.ExceptionRecord = NULL;
|
|
|
|
record.ExceptionAddress = (void *)context.Pc;
|
|
|
|
record.NumberParameters = 0;
|
|
|
|
rec = &record;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec->ExceptionFlags |= EH_UNWINDING | (endframe ? 0 : EH_EXIT_UNWIND);
|
|
|
|
|
|
|
|
TRACE( "code=%x flags=%x\n", rec->ExceptionCode, rec->ExceptionFlags );
|
|
|
|
|
|
|
|
/* get chain of exception frames */
|
|
|
|
frame = NtCurrentTeb()->Tib.ExceptionList;
|
|
|
|
while ((frame != (EXCEPTION_REGISTRATION_RECORD*)~0UL) && (frame != endframe))
|
|
|
|
{
|
|
|
|
/* Check frame address */
|
|
|
|
if (endframe && ((void*)frame > endframe))
|
|
|
|
raise_status( STATUS_INVALID_UNWIND_TARGET, rec );
|
|
|
|
|
|
|
|
if (!is_valid_frame( frame )) raise_status( STATUS_BAD_STACK, rec );
|
|
|
|
|
|
|
|
/* Call handler */
|
|
|
|
TRACE( "calling handler at %p code=%x flags=%x\n",
|
|
|
|
frame->Handler, rec->ExceptionCode, rec->ExceptionFlags );
|
|
|
|
res = frame->Handler(rec, frame, &context, &dispatch);
|
|
|
|
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, rec );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = __wine_pop_frame( frame );
|
|
|
|
}
|
2010-09-18 18:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlRaiseException (NTDLL.@)
|
|
|
|
*/
|
2020-07-28 13:40:13 +02:00
|
|
|
__ASM_STDCALL_FUNC( RtlRaiseException, 4,
|
|
|
|
"push {r0, lr}\n\t"
|
|
|
|
"sub sp, sp, #0x1a0\n\t" /* sizeof(CONTEXT) */
|
|
|
|
"mov r0, sp\n\t" /* context */
|
|
|
|
"bl " __ASM_NAME("RtlCaptureContext") "\n\t"
|
|
|
|
"ldr r0, [sp, #0x1a0]\n\t" /* rec */
|
|
|
|
"ldr r1, [sp, #0x1a4]\n\t"
|
|
|
|
"str r1, [sp, #0x40]\n\t" /* context->Pc */
|
2021-01-18 11:43:55 +01:00
|
|
|
"ldr r2, [sp, #0x44]\n\t" /* context->Cpsr */
|
|
|
|
"tst r1, #1\n\t" /* Thumb? */
|
|
|
|
"ite ne\n\t"
|
|
|
|
"orrne r2, r2, #0x20\n\t"
|
|
|
|
"biceq r2, r2, #0x20\n\t"
|
|
|
|
"str r2, [sp, #0x44]\n\t" /* context->Cpsr */
|
2020-07-28 13:40:13 +02:00
|
|
|
"str r1, [r0, #12]\n\t" /* rec->ExceptionAddress */
|
|
|
|
"add r1, sp, #0x1a8\n\t"
|
|
|
|
"str r1, [sp, #0x38]\n\t" /* context->Sp */
|
|
|
|
"mov r1, sp\n\t"
|
|
|
|
"mov r2, #1\n\t"
|
|
|
|
"bl " __ASM_NAME("NtRaiseException") "\n\t"
|
|
|
|
"bl " __ASM_NAME("RtlRaiseStatus") )
|
2010-09-18 18:02:12 +02:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* RtlCaptureStackBackTrace (NTDLL.@)
|
|
|
|
*/
|
|
|
|
USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
|
|
|
|
{
|
|
|
|
FIXME( "(%d, %d, %p, %p) stub!\n", skip, count, buffer, hash );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-20 15:27:30 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* signal_start_thread
|
|
|
|
*/
|
|
|
|
__ASM_GLOBAL_FUNC( signal_start_thread,
|
|
|
|
"mov sp, r0\n\t" /* context */
|
|
|
|
"mov r1, #1\n\t"
|
|
|
|
"b " __ASM_NAME("NtContinue") )
|
|
|
|
|
2010-09-18 18:02:12 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* DbgBreakPoint (NTDLL.@)
|
|
|
|
*/
|
2020-06-29 10:40:28 +02:00
|
|
|
__ASM_STDCALL_FUNC( DbgBreakPoint, 0, "bkpt #0; bx lr; nop; nop; nop; nop" );
|
2010-09-18 18:02:12 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DbgUserBreakPoint (NTDLL.@)
|
|
|
|
*/
|
2020-06-29 10:40:28 +02:00
|
|
|
__ASM_STDCALL_FUNC( DbgUserBreakPoint, 0, "bkpt #0; bx lr; nop; nop; nop; nop" );
|
2010-09-18 18:02:12 +02:00
|
|
|
|
|
|
|
#endif /* __arm__ */
|