2002-08-27 02:30:20 +02:00
|
|
|
/*
|
|
|
|
* PowerPC signal handling routines
|
|
|
|
*
|
|
|
|
* Copyright 2002 Marcus Meissner, SuSE Linux AG
|
|
|
|
*
|
|
|
|
* 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-08-27 02:30:20 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __powerpc__
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2005-09-14 12:36:58 +02:00
|
|
|
#include <assert.h>
|
2002-08-27 02:30:20 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-08-27 02:30:20 +02:00
|
|
|
#include <stdio.h>
|
2014-07-23 16:30:13 +02:00
|
|
|
#include <sys/types.h>
|
2002-08-29 01:42:34 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-08-27 02:30:20 +02:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
# include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYSCALL_H
|
|
|
|
# include <syscall.h>
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_SYS_SYSCALL_H
|
|
|
|
# include <sys/syscall.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SIGNAL_H
|
|
|
|
# include <sys/signal.h>
|
|
|
|
#endif
|
2014-07-23 16:30:13 +02:00
|
|
|
#ifdef HAVE_SYS_UCONTEXT_H
|
|
|
|
# include <sys/ucontext.h>
|
|
|
|
#endif
|
2002-08-27 02:30:20 +02: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"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2002-08-27 02:30:20 +02:00
|
|
|
#include "wine/library.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "wine/exception.h"
|
2003-06-30 23:00:15 +02:00
|
|
|
#include "ntdll_misc.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(seh);
|
2017-11-29 19:42:53 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
2002-09-13 00:07:02 +02:00
|
|
|
|
2009-02-18 13:04:50 +01:00
|
|
|
static pthread_key_t teb_key;
|
2002-08-27 02:30:20 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* signal context platform-specific definitions
|
|
|
|
*/
|
2003-05-13 05:35:01 +02:00
|
|
|
#ifdef linux
|
2002-08-27 02:30:20 +02:00
|
|
|
|
2003-05-13 05:35:01 +02:00
|
|
|
/* All Registers access - only for local access */
|
|
|
|
# define REG_sig(reg_name, context) ((context)->uc_mcontext.regs->reg_name)
|
|
|
|
|
|
|
|
|
|
|
|
/* Gpr Registers access */
|
2003-07-21 22:03:07 +02:00
|
|
|
# define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context)
|
2003-05-13 05:35:01 +02:00
|
|
|
|
|
|
|
# define IAR_sig(context) REG_sig(nip, context) /* Program counter */
|
|
|
|
# define MSR_sig(context) REG_sig(msr, context) /* Machine State Register (Supervisor) */
|
|
|
|
# define CTR_sig(context) REG_sig(ctr, context) /* Count register */
|
|
|
|
|
2003-07-21 22:03:07 +02:00
|
|
|
# define XER_sig(context) REG_sig(xer, context) /* User's integer exception register */
|
|
|
|
# define LR_sig(context) REG_sig(link, context) /* Link register */
|
|
|
|
# define CR_sig(context) REG_sig(ccr, context) /* Condition register */
|
2003-05-13 05:35:01 +02:00
|
|
|
|
|
|
|
/* Float Registers access */
|
2003-07-21 22:03:07 +02:00
|
|
|
# define FLOAT_sig(reg_num, context) (((double*)((char*)((context)->uc_mcontext.regs+48*4)))[reg_num])
|
2003-05-13 05:35:01 +02:00
|
|
|
|
2003-07-21 22:03:07 +02:00
|
|
|
# define FPSCR_sig(context) (*(int*)((char*)((context)->uc_mcontext.regs+(48+32*2)*4)))
|
2003-05-13 05:35:01 +02:00
|
|
|
|
|
|
|
/* Exception Registers access */
|
2003-07-21 22:03:07 +02:00
|
|
|
# define DAR_sig(context) REG_sig(dar, context)
|
|
|
|
# define DSISR_sig(context) REG_sig(dsisr, context)
|
|
|
|
# define TRAP_sig(context) REG_sig(trap, context)
|
2003-05-13 05:35:01 +02:00
|
|
|
|
|
|
|
#endif /* linux */
|
|
|
|
|
2003-07-17 01:29:40 +02:00
|
|
|
#ifdef __APPLE__
|
2003-05-13 05:35:01 +02:00
|
|
|
|
|
|
|
/* All Registers access - only for local access */
|
|
|
|
# define REG_sig(reg_name, context) ((context)->uc_mcontext->ss.reg_name)
|
|
|
|
# define FLOATREG_sig(reg_name, context) ((context)->uc_mcontext->fs.reg_name)
|
|
|
|
# define EXCEPREG_sig(reg_name, context) ((context)->uc_mcontext->es.reg_name)
|
|
|
|
# define VECREG_sig(reg_name, context) ((context)->uc_mcontext->vs.reg_name)
|
|
|
|
|
|
|
|
/* Gpr Registers access */
|
|
|
|
# define GPR_sig(reg_num, context) REG_sig(r##reg_num, context)
|
|
|
|
|
|
|
|
# define IAR_sig(context) REG_sig(srr0, context) /* Program counter */
|
|
|
|
# define MSR_sig(context) REG_sig(srr1, context) /* Machine State Register (Supervisor) */
|
|
|
|
# define CTR_sig(context) REG_sig(ctr, context)
|
|
|
|
|
|
|
|
# define XER_sig(context) REG_sig(xer, context) /* Link register */
|
|
|
|
# define LR_sig(context) REG_sig(lr, context) /* User's integer exception register */
|
|
|
|
# define CR_sig(context) REG_sig(cr, context) /* Condition register */
|
|
|
|
|
|
|
|
/* Float Registers access */
|
|
|
|
# define FLOAT_sig(reg_num, context) FLOATREG_sig(fpregs[reg_num], context)
|
|
|
|
|
2005-05-05 11:49:13 +02:00
|
|
|
# define FPSCR_sig(context) FLOATREG_sig(fpscr, context)
|
2003-05-13 05:35:01 +02:00
|
|
|
|
|
|
|
/* Exception Registers access */
|
|
|
|
# define DAR_sig(context) EXCEPREG_sig(dar, context) /* Fault registers for coredump */
|
|
|
|
# define DSISR_sig(context) EXCEPREG_sig(dsisr, context)
|
|
|
|
# define TRAP_sig(context) EXCEPREG_sig(exception, context) /* number of powerpc exception taken */
|
|
|
|
|
|
|
|
/* Signal defs : Those are undefined on darwin
|
|
|
|
SIGBUS
|
|
|
|
#undef BUS_ADRERR
|
|
|
|
#undef BUS_OBJERR
|
|
|
|
SIGILL
|
|
|
|
#undef ILL_ILLOPN
|
|
|
|
#undef ILL_ILLTRP
|
|
|
|
#undef ILL_ILLADR
|
|
|
|
#undef ILL_COPROC
|
|
|
|
#undef ILL_PRVREG
|
|
|
|
#undef ILL_BADSTK
|
|
|
|
SIGTRAP
|
|
|
|
#undef TRAP_BRKPT
|
|
|
|
#undef TRAP_TRACE
|
|
|
|
SIGFPE
|
|
|
|
*/
|
|
|
|
|
2003-07-17 01:29:40 +02:00
|
|
|
#endif /* __APPLE__ */
|
2003-05-13 05:35:01 +02:00
|
|
|
|
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
|
2002-08-30 02:00:57 +02:00
|
|
|
typedef int (*wine_signal_handler)(unsigned int sig);
|
2002-08-27 02:30:20 +02:00
|
|
|
|
|
|
|
static wine_signal_handler handlers[256];
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* dispatch_signal
|
|
|
|
*/
|
2007-03-17 11:28:32 +01:00
|
|
|
static inline int dispatch_signal(unsigned int sig)
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
|
|
|
if (handlers[sig] == NULL) return 0;
|
|
|
|
return handlers[sig](sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* save_context
|
|
|
|
*
|
|
|
|
* Set the register values from a sigcontext.
|
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static void save_context( CONTEXT *context, const ucontext_t *sigcontext )
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
2003-05-13 05:35:01 +02:00
|
|
|
|
|
|
|
#define C(x) context->Gpr##x = GPR_sig(x,sigcontext)
|
|
|
|
/* Save Gpr registers */
|
2002-08-27 02:30:20 +02:00
|
|
|
C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
|
|
|
|
C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
|
|
|
|
C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
|
|
|
|
C(31);
|
2003-05-13 05:35:01 +02:00
|
|
|
#undef C
|
|
|
|
|
|
|
|
context->Iar = IAR_sig(sigcontext); /* Program Counter */
|
|
|
|
context->Msr = MSR_sig(sigcontext); /* Machine State Register (Supervisor) */
|
|
|
|
context->Ctr = CTR_sig(sigcontext);
|
|
|
|
|
|
|
|
context->Xer = XER_sig(sigcontext);
|
|
|
|
context->Lr = LR_sig(sigcontext);
|
|
|
|
context->Cr = CR_sig(sigcontext);
|
|
|
|
|
|
|
|
/* Saving Exception regs */
|
|
|
|
context->Dar = DAR_sig(sigcontext);
|
|
|
|
context->Dsisr = DSISR_sig(sigcontext);
|
|
|
|
context->Trap = TRAP_sig(sigcontext);
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* restore_context
|
|
|
|
*
|
|
|
|
* Build a sigcontext from the register values.
|
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static void restore_context( const CONTEXT *context, ucontext_t *sigcontext )
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
2003-05-13 05:35:01 +02:00
|
|
|
|
|
|
|
#define C(x) GPR_sig(x,sigcontext) = context->Gpr##x
|
2002-08-27 02:30:20 +02:00
|
|
|
C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
|
|
|
|
C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
|
|
|
|
C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
|
|
|
|
C(31);
|
2003-05-13 05:35:01 +02:00
|
|
|
#undef C
|
|
|
|
|
|
|
|
IAR_sig(sigcontext) = context->Iar; /* Program Counter */
|
|
|
|
MSR_sig(sigcontext) = context->Msr; /* Machine State Register (Supervisor) */
|
|
|
|
CTR_sig(sigcontext) = context->Ctr;
|
|
|
|
|
|
|
|
XER_sig(sigcontext) = context->Xer;
|
|
|
|
LR_sig(sigcontext) = context->Lr;
|
|
|
|
CR_sig(sigcontext) = context->Cr;
|
|
|
|
|
|
|
|
/* Setting Exception regs */
|
|
|
|
DAR_sig(sigcontext) = context->Dar;
|
|
|
|
DSISR_sig(sigcontext) = context->Dsisr;
|
|
|
|
TRAP_sig(sigcontext) = context->Trap;
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* save_fpu
|
|
|
|
*
|
|
|
|
* Set the FPU context from a sigcontext.
|
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static inline void save_fpu( CONTEXT *context, const ucontext_t *sigcontext )
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
2003-05-13 05:35:01 +02:00
|
|
|
#define C(x) context->Fpr##x = FLOAT_sig(x,sigcontext)
|
|
|
|
C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
|
|
|
|
C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
|
|
|
|
C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
|
|
|
|
C(31);
|
|
|
|
#undef C
|
|
|
|
context->Fpscr = FPSCR_sig(sigcontext);
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* restore_fpu
|
|
|
|
*
|
|
|
|
* Restore the FPU context to a sigcontext.
|
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static inline void restore_fpu( CONTEXT *context, const ucontext_t *sigcontext )
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
2003-05-13 05:35:01 +02:00
|
|
|
#define C(x) FLOAT_sig(x,sigcontext) = context->Fpr##x
|
|
|
|
C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
|
|
|
|
C(11); C(12); C(13); C(14); C(15); C(16); C(17); C(18); C(19); C(20);
|
|
|
|
C(21); C(22); C(23); C(24); C(25); C(26); C(27); C(28); C(29); C(30);
|
|
|
|
C(31);
|
|
|
|
#undef C
|
|
|
|
FPSCR_sig(sigcontext) = context->Fpscr;
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
2009-01-06 17:50:34 +01:00
|
|
|
void WINAPI RtlCaptureContext( CONTEXT *context )
|
2006-04-20 15:40:28 +02:00
|
|
|
{
|
|
|
|
FIXME("not implemented\n");
|
2009-01-06 17:50:34 +01:00
|
|
|
memset( context, 0, sizeof(*context) );
|
2006-04-20 15:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-11 20:20:32 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* set_cpu_context
|
|
|
|
*
|
|
|
|
* Set the new CPU context.
|
|
|
|
*/
|
2017-07-18 11:08:37 +02:00
|
|
|
static void set_cpu_context( const CONTEXT *context )
|
2006-01-11 20:20:32 +01:00
|
|
|
{
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-12 10:46:27 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_server_context_flags
|
|
|
|
*
|
|
|
|
* Convert CPU-specific flags to generic server flags
|
|
|
|
*/
|
|
|
|
static unsigned int get_server_context_flags( DWORD flags )
|
|
|
|
{
|
|
|
|
unsigned int ret = 0;
|
|
|
|
|
|
|
|
if (flags & CONTEXT_CONTROL) ret |= SERVER_CTX_CONTROL;
|
|
|
|
if (flags & CONTEXT_INTEGER) ret |= SERVER_CTX_INTEGER;
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT) ret |= SERVER_CTX_FLOATING_POINT;
|
|
|
|
if (flags & CONTEXT_DEBUG_REGISTERS) ret |= SERVER_CTX_DEBUG_REGISTERS;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-13 11:31:25 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* copy_context
|
|
|
|
*
|
|
|
|
* Copy a register context according to the flags.
|
|
|
|
*/
|
2017-07-18 11:15:46 +02:00
|
|
|
static void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags )
|
2009-03-13 11:31:25 +01:00
|
|
|
{
|
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
2009-04-08 19:38:02 +02:00
|
|
|
to->Msr = from->Msr;
|
|
|
|
to->Ctr = from->Ctr;
|
|
|
|
to->Iar = from->Iar;
|
|
|
|
to->Lr = from->Lr;
|
|
|
|
to->Dar = from->Dar;
|
|
|
|
to->Dsisr = from->Dsisr;
|
|
|
|
to->Trap = from->Trap;
|
2009-03-13 11:31:25 +01:00
|
|
|
}
|
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
to->Gpr0 = from->Gpr0;
|
|
|
|
to->Gpr1 = from->Gpr1;
|
|
|
|
to->Gpr2 = from->Gpr2;
|
|
|
|
to->Gpr3 = from->Gpr3;
|
|
|
|
to->Gpr4 = from->Gpr4;
|
|
|
|
to->Gpr5 = from->Gpr5;
|
|
|
|
to->Gpr6 = from->Gpr6;
|
|
|
|
to->Gpr7 = from->Gpr7;
|
|
|
|
to->Gpr8 = from->Gpr8;
|
|
|
|
to->Gpr9 = from->Gpr9;
|
|
|
|
to->Gpr10 = from->Gpr10;
|
|
|
|
to->Gpr11 = from->Gpr11;
|
|
|
|
to->Gpr12 = from->Gpr12;
|
|
|
|
to->Gpr13 = from->Gpr13;
|
|
|
|
to->Gpr14 = from->Gpr14;
|
|
|
|
to->Gpr15 = from->Gpr15;
|
|
|
|
to->Gpr16 = from->Gpr16;
|
|
|
|
to->Gpr17 = from->Gpr17;
|
|
|
|
to->Gpr18 = from->Gpr18;
|
|
|
|
to->Gpr19 = from->Gpr19;
|
|
|
|
to->Gpr20 = from->Gpr20;
|
|
|
|
to->Gpr21 = from->Gpr21;
|
|
|
|
to->Gpr22 = from->Gpr22;
|
|
|
|
to->Gpr23 = from->Gpr23;
|
|
|
|
to->Gpr24 = from->Gpr24;
|
|
|
|
to->Gpr25 = from->Gpr25;
|
|
|
|
to->Gpr26 = from->Gpr26;
|
|
|
|
to->Gpr27 = from->Gpr27;
|
|
|
|
to->Gpr28 = from->Gpr28;
|
|
|
|
to->Gpr29 = from->Gpr29;
|
|
|
|
to->Gpr30 = from->Gpr30;
|
|
|
|
to->Gpr31 = from->Gpr31;
|
|
|
|
to->Xer = from->Xer;
|
|
|
|
to->Cr = from->Cr;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
to->Fpr0 = from->Fpr0;
|
|
|
|
to->Fpr1 = from->Fpr1;
|
|
|
|
to->Fpr2 = from->Fpr2;
|
|
|
|
to->Fpr3 = from->Fpr3;
|
|
|
|
to->Fpr4 = from->Fpr4;
|
|
|
|
to->Fpr5 = from->Fpr5;
|
|
|
|
to->Fpr6 = from->Fpr6;
|
|
|
|
to->Fpr7 = from->Fpr7;
|
|
|
|
to->Fpr8 = from->Fpr8;
|
|
|
|
to->Fpr9 = from->Fpr9;
|
|
|
|
to->Fpr10 = from->Fpr10;
|
|
|
|
to->Fpr11 = from->Fpr11;
|
|
|
|
to->Fpr12 = from->Fpr12;
|
|
|
|
to->Fpr13 = from->Fpr13;
|
|
|
|
to->Fpr14 = from->Fpr14;
|
|
|
|
to->Fpr15 = from->Fpr15;
|
|
|
|
to->Fpr16 = from->Fpr16;
|
|
|
|
to->Fpr17 = from->Fpr17;
|
|
|
|
to->Fpr18 = from->Fpr18;
|
|
|
|
to->Fpr19 = from->Fpr19;
|
|
|
|
to->Fpr20 = from->Fpr20;
|
|
|
|
to->Fpr21 = from->Fpr21;
|
|
|
|
to->Fpr22 = from->Fpr22;
|
|
|
|
to->Fpr23 = from->Fpr23;
|
|
|
|
to->Fpr24 = from->Fpr24;
|
|
|
|
to->Fpr25 = from->Fpr25;
|
|
|
|
to->Fpr26 = from->Fpr26;
|
|
|
|
to->Fpr27 = from->Fpr27;
|
|
|
|
to->Fpr28 = from->Fpr28;
|
|
|
|
to->Fpr29 = from->Fpr29;
|
|
|
|
to->Fpr30 = from->Fpr30;
|
|
|
|
to->Fpr31 = from->Fpr31;
|
|
|
|
to->Fpscr = from->Fpscr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-08 19:38:02 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* context_to_server
|
|
|
|
*
|
|
|
|
* Convert a register context to the server format.
|
|
|
|
*/
|
|
|
|
NTSTATUS context_to_server( context_t *to, const CONTEXT *from )
|
|
|
|
{
|
|
|
|
DWORD flags = from->ContextFlags; /* no CPU id? */
|
|
|
|
|
|
|
|
memset( to, 0, sizeof(*to) );
|
|
|
|
to->cpu = CPU_POWERPC;
|
|
|
|
|
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
to->flags |= SERVER_CTX_CONTROL;
|
|
|
|
to->ctl.powerpc_regs.iar = from->Iar;
|
|
|
|
to->ctl.powerpc_regs.msr = from->Msr;
|
|
|
|
to->ctl.powerpc_regs.ctr = from->Ctr;
|
|
|
|
to->ctl.powerpc_regs.lr = from->Lr;
|
|
|
|
to->ctl.powerpc_regs.dar = from->Dar;
|
|
|
|
to->ctl.powerpc_regs.dsisr = from->Dsisr;
|
|
|
|
to->ctl.powerpc_regs.trap = from->Trap;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
to->flags |= SERVER_CTX_INTEGER;
|
|
|
|
to->integer.powerpc_regs.gpr[0] = from->Gpr0;
|
|
|
|
to->integer.powerpc_regs.gpr[1] = from->Gpr1;
|
|
|
|
to->integer.powerpc_regs.gpr[2] = from->Gpr2;
|
|
|
|
to->integer.powerpc_regs.gpr[3] = from->Gpr3;
|
|
|
|
to->integer.powerpc_regs.gpr[4] = from->Gpr4;
|
|
|
|
to->integer.powerpc_regs.gpr[5] = from->Gpr5;
|
|
|
|
to->integer.powerpc_regs.gpr[6] = from->Gpr6;
|
|
|
|
to->integer.powerpc_regs.gpr[7] = from->Gpr7;
|
|
|
|
to->integer.powerpc_regs.gpr[8] = from->Gpr8;
|
|
|
|
to->integer.powerpc_regs.gpr[9] = from->Gpr9;
|
|
|
|
to->integer.powerpc_regs.gpr[10] = from->Gpr10;
|
|
|
|
to->integer.powerpc_regs.gpr[11] = from->Gpr11;
|
|
|
|
to->integer.powerpc_regs.gpr[12] = from->Gpr12;
|
|
|
|
to->integer.powerpc_regs.gpr[13] = from->Gpr13;
|
|
|
|
to->integer.powerpc_regs.gpr[14] = from->Gpr14;
|
|
|
|
to->integer.powerpc_regs.gpr[15] = from->Gpr15;
|
|
|
|
to->integer.powerpc_regs.gpr[16] = from->Gpr16;
|
|
|
|
to->integer.powerpc_regs.gpr[17] = from->Gpr17;
|
|
|
|
to->integer.powerpc_regs.gpr[18] = from->Gpr18;
|
|
|
|
to->integer.powerpc_regs.gpr[19] = from->Gpr19;
|
|
|
|
to->integer.powerpc_regs.gpr[20] = from->Gpr20;
|
|
|
|
to->integer.powerpc_regs.gpr[21] = from->Gpr21;
|
|
|
|
to->integer.powerpc_regs.gpr[22] = from->Gpr22;
|
|
|
|
to->integer.powerpc_regs.gpr[23] = from->Gpr23;
|
|
|
|
to->integer.powerpc_regs.gpr[24] = from->Gpr24;
|
|
|
|
to->integer.powerpc_regs.gpr[25] = from->Gpr25;
|
|
|
|
to->integer.powerpc_regs.gpr[26] = from->Gpr26;
|
|
|
|
to->integer.powerpc_regs.gpr[27] = from->Gpr27;
|
|
|
|
to->integer.powerpc_regs.gpr[28] = from->Gpr28;
|
|
|
|
to->integer.powerpc_regs.gpr[29] = from->Gpr29;
|
|
|
|
to->integer.powerpc_regs.gpr[30] = from->Gpr30;
|
|
|
|
to->integer.powerpc_regs.gpr[31] = from->Gpr31;
|
|
|
|
to->integer.powerpc_regs.xer = from->Xer;
|
|
|
|
to->integer.powerpc_regs.cr = from->Cr;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
to->flags |= SERVER_CTX_FLOATING_POINT;
|
|
|
|
to->fp.powerpc_regs.fpr[0] = from->Fpr0;
|
|
|
|
to->fp.powerpc_regs.fpr[1] = from->Fpr1;
|
|
|
|
to->fp.powerpc_regs.fpr[2] = from->Fpr2;
|
|
|
|
to->fp.powerpc_regs.fpr[3] = from->Fpr3;
|
|
|
|
to->fp.powerpc_regs.fpr[4] = from->Fpr4;
|
|
|
|
to->fp.powerpc_regs.fpr[5] = from->Fpr5;
|
|
|
|
to->fp.powerpc_regs.fpr[6] = from->Fpr6;
|
|
|
|
to->fp.powerpc_regs.fpr[7] = from->Fpr7;
|
|
|
|
to->fp.powerpc_regs.fpr[8] = from->Fpr8;
|
|
|
|
to->fp.powerpc_regs.fpr[9] = from->Fpr9;
|
|
|
|
to->fp.powerpc_regs.fpr[10] = from->Fpr10;
|
|
|
|
to->fp.powerpc_regs.fpr[11] = from->Fpr11;
|
|
|
|
to->fp.powerpc_regs.fpr[12] = from->Fpr12;
|
|
|
|
to->fp.powerpc_regs.fpr[13] = from->Fpr13;
|
|
|
|
to->fp.powerpc_regs.fpr[14] = from->Fpr14;
|
|
|
|
to->fp.powerpc_regs.fpr[15] = from->Fpr15;
|
|
|
|
to->fp.powerpc_regs.fpr[16] = from->Fpr16;
|
|
|
|
to->fp.powerpc_regs.fpr[17] = from->Fpr17;
|
|
|
|
to->fp.powerpc_regs.fpr[18] = from->Fpr18;
|
|
|
|
to->fp.powerpc_regs.fpr[19] = from->Fpr19;
|
|
|
|
to->fp.powerpc_regs.fpr[20] = from->Fpr20;
|
|
|
|
to->fp.powerpc_regs.fpr[21] = from->Fpr21;
|
|
|
|
to->fp.powerpc_regs.fpr[22] = from->Fpr22;
|
|
|
|
to->fp.powerpc_regs.fpr[23] = from->Fpr23;
|
|
|
|
to->fp.powerpc_regs.fpr[24] = from->Fpr24;
|
|
|
|
to->fp.powerpc_regs.fpr[25] = from->Fpr25;
|
|
|
|
to->fp.powerpc_regs.fpr[26] = from->Fpr26;
|
|
|
|
to->fp.powerpc_regs.fpr[27] = from->Fpr27;
|
|
|
|
to->fp.powerpc_regs.fpr[28] = from->Fpr28;
|
|
|
|
to->fp.powerpc_regs.fpr[29] = from->Fpr29;
|
|
|
|
to->fp.powerpc_regs.fpr[30] = from->Fpr30;
|
|
|
|
to->fp.powerpc_regs.fpr[31] = from->Fpr31;
|
|
|
|
to->fp.powerpc_regs.fpscr = from->Fpscr;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* context_from_server
|
|
|
|
*
|
|
|
|
* Convert a register context from the server format.
|
|
|
|
*/
|
|
|
|
NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
|
|
|
|
{
|
|
|
|
if (from->cpu != CPU_POWERPC) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
to->ContextFlags = 0; /* no CPU id? */
|
|
|
|
if (from->flags & SERVER_CTX_CONTROL)
|
|
|
|
{
|
|
|
|
to->ContextFlags |= CONTEXT_CONTROL;
|
|
|
|
to->Msr = from->ctl.powerpc_regs.msr;
|
|
|
|
to->Ctr = from->ctl.powerpc_regs.ctr;
|
|
|
|
to->Iar = from->ctl.powerpc_regs.iar;
|
|
|
|
to->Lr = from->ctl.powerpc_regs.lr;
|
|
|
|
to->Dar = from->ctl.powerpc_regs.dar;
|
|
|
|
to->Dsisr = from->ctl.powerpc_regs.dsisr;
|
|
|
|
to->Trap = from->ctl.powerpc_regs.trap;
|
|
|
|
}
|
|
|
|
if (from->flags & SERVER_CTX_INTEGER)
|
|
|
|
{
|
|
|
|
to->ContextFlags |= CONTEXT_INTEGER;
|
|
|
|
to->Gpr0 = from->integer.powerpc_regs.gpr[0];
|
|
|
|
to->Gpr1 = from->integer.powerpc_regs.gpr[1];
|
|
|
|
to->Gpr2 = from->integer.powerpc_regs.gpr[2];
|
|
|
|
to->Gpr3 = from->integer.powerpc_regs.gpr[3];
|
|
|
|
to->Gpr4 = from->integer.powerpc_regs.gpr[4];
|
|
|
|
to->Gpr5 = from->integer.powerpc_regs.gpr[5];
|
|
|
|
to->Gpr6 = from->integer.powerpc_regs.gpr[6];
|
|
|
|
to->Gpr7 = from->integer.powerpc_regs.gpr[7];
|
|
|
|
to->Gpr8 = from->integer.powerpc_regs.gpr[8];
|
|
|
|
to->Gpr9 = from->integer.powerpc_regs.gpr[9];
|
|
|
|
to->Gpr10 = from->integer.powerpc_regs.gpr[10];
|
|
|
|
to->Gpr11 = from->integer.powerpc_regs.gpr[11];
|
|
|
|
to->Gpr12 = from->integer.powerpc_regs.gpr[12];
|
|
|
|
to->Gpr13 = from->integer.powerpc_regs.gpr[13];
|
|
|
|
to->Gpr14 = from->integer.powerpc_regs.gpr[14];
|
|
|
|
to->Gpr15 = from->integer.powerpc_regs.gpr[15];
|
|
|
|
to->Gpr16 = from->integer.powerpc_regs.gpr[16];
|
|
|
|
to->Gpr17 = from->integer.powerpc_regs.gpr[17];
|
|
|
|
to->Gpr18 = from->integer.powerpc_regs.gpr[18];
|
|
|
|
to->Gpr19 = from->integer.powerpc_regs.gpr[19];
|
|
|
|
to->Gpr20 = from->integer.powerpc_regs.gpr[20];
|
|
|
|
to->Gpr21 = from->integer.powerpc_regs.gpr[21];
|
|
|
|
to->Gpr22 = from->integer.powerpc_regs.gpr[22];
|
|
|
|
to->Gpr23 = from->integer.powerpc_regs.gpr[23];
|
|
|
|
to->Gpr24 = from->integer.powerpc_regs.gpr[24];
|
|
|
|
to->Gpr25 = from->integer.powerpc_regs.gpr[25];
|
|
|
|
to->Gpr26 = from->integer.powerpc_regs.gpr[26];
|
|
|
|
to->Gpr27 = from->integer.powerpc_regs.gpr[27];
|
|
|
|
to->Gpr28 = from->integer.powerpc_regs.gpr[28];
|
|
|
|
to->Gpr29 = from->integer.powerpc_regs.gpr[29];
|
|
|
|
to->Gpr30 = from->integer.powerpc_regs.gpr[30];
|
|
|
|
to->Gpr31 = from->integer.powerpc_regs.gpr[31];
|
|
|
|
to->Xer = from->integer.powerpc_regs.xer;
|
|
|
|
to->Cr = from->integer.powerpc_regs.cr;
|
|
|
|
}
|
|
|
|
if (from->flags & SERVER_CTX_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
to->ContextFlags |= CONTEXT_FLOATING_POINT;
|
|
|
|
to->Fpr0 = from->fp.powerpc_regs.fpr[0];
|
|
|
|
to->Fpr1 = from->fp.powerpc_regs.fpr[1];
|
|
|
|
to->Fpr2 = from->fp.powerpc_regs.fpr[2];
|
|
|
|
to->Fpr3 = from->fp.powerpc_regs.fpr[3];
|
|
|
|
to->Fpr4 = from->fp.powerpc_regs.fpr[4];
|
|
|
|
to->Fpr5 = from->fp.powerpc_regs.fpr[5];
|
|
|
|
to->Fpr6 = from->fp.powerpc_regs.fpr[6];
|
|
|
|
to->Fpr7 = from->fp.powerpc_regs.fpr[7];
|
|
|
|
to->Fpr8 = from->fp.powerpc_regs.fpr[8];
|
|
|
|
to->Fpr9 = from->fp.powerpc_regs.fpr[9];
|
|
|
|
to->Fpr10 = from->fp.powerpc_regs.fpr[10];
|
|
|
|
to->Fpr11 = from->fp.powerpc_regs.fpr[11];
|
|
|
|
to->Fpr12 = from->fp.powerpc_regs.fpr[12];
|
|
|
|
to->Fpr13 = from->fp.powerpc_regs.fpr[13];
|
|
|
|
to->Fpr14 = from->fp.powerpc_regs.fpr[14];
|
|
|
|
to->Fpr15 = from->fp.powerpc_regs.fpr[15];
|
|
|
|
to->Fpr16 = from->fp.powerpc_regs.fpr[16];
|
|
|
|
to->Fpr17 = from->fp.powerpc_regs.fpr[17];
|
|
|
|
to->Fpr18 = from->fp.powerpc_regs.fpr[18];
|
|
|
|
to->Fpr19 = from->fp.powerpc_regs.fpr[19];
|
|
|
|
to->Fpr20 = from->fp.powerpc_regs.fpr[20];
|
|
|
|
to->Fpr21 = from->fp.powerpc_regs.fpr[21];
|
|
|
|
to->Fpr22 = from->fp.powerpc_regs.fpr[22];
|
|
|
|
to->Fpr23 = from->fp.powerpc_regs.fpr[23];
|
|
|
|
to->Fpr24 = from->fp.powerpc_regs.fpr[24];
|
|
|
|
to->Fpr25 = from->fp.powerpc_regs.fpr[25];
|
|
|
|
to->Fpr26 = from->fp.powerpc_regs.fpr[26];
|
|
|
|
to->Fpr27 = from->fp.powerpc_regs.fpr[27];
|
|
|
|
to->Fpr28 = from->fp.powerpc_regs.fpr[28];
|
|
|
|
to->Fpr29 = from->fp.powerpc_regs.fpr[29];
|
|
|
|
to->Fpr30 = from->fp.powerpc_regs.fpr[30];
|
|
|
|
to->Fpr31 = from->fp.powerpc_regs.fpr[31];
|
|
|
|
to->Fpscr = from->fp.powerpc_regs.fpscr;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 11:08:37 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NtSetContextThread (NTDLL.@)
|
|
|
|
* ZwSetContextThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
BOOL self;
|
2018-06-12 10:46:27 +02:00
|
|
|
context_t server_context;
|
2017-07-18 11:08:37 +02:00
|
|
|
|
2018-06-12 10:46:27 +02:00
|
|
|
context_to_server( &server_context, context );
|
|
|
|
ret = set_thread_context( handle, &server_context, &self );
|
2017-07-18 11:08:37 +02:00
|
|
|
if (self && ret == STATUS_SUCCESS) set_cpu_context( context );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 11:15:46 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* NtGetContextThread (NTDLL.@)
|
|
|
|
* ZwGetContextThread (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
DWORD needed_flags = context->ContextFlags;
|
|
|
|
BOOL self = (handle == GetCurrentThread());
|
|
|
|
|
|
|
|
if (!self)
|
|
|
|
{
|
2018-06-12 10:46:27 +02:00
|
|
|
context_t server_context;
|
|
|
|
unsigned int server_flags = get_server_context_flags( context->ContextFlags );
|
|
|
|
|
|
|
|
if ((ret = get_thread_context( handle, &server_context, server_flags, &self ))) return ret;
|
|
|
|
if ((ret = context_from_server( context, &server_context ))) return ret;
|
2017-07-18 11:15:46 +02:00
|
|
|
needed_flags &= ~context->ContextFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self && needed_flags)
|
|
|
|
{
|
|
|
|
CONTEXT ctx;
|
|
|
|
RtlCaptureContext( &ctx );
|
|
|
|
copy_context( context, &ctx, ctx.ContextFlags & needed_flags );
|
|
|
|
context->ContextFlags |= ctx.ContextFlags & needed_flags;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-30 13:08:32 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* call_stack_handlers
|
|
|
|
*
|
|
|
|
* Call the stack handlers chain.
|
|
|
|
*/
|
|
|
|
static NTSTATUS call_stack_handlers( EXCEPTION_RECORD *rec, CONTEXT *context )
|
|
|
|
{
|
|
|
|
EXCEPTION_POINTERS ptrs;
|
|
|
|
|
|
|
|
FIXME( "not implemented on PowerPC\n" );
|
|
|
|
|
|
|
|
/* hack: call unhandled exception filter directly */
|
|
|
|
ptrs.ExceptionRecord = rec;
|
|
|
|
ptrs.ContextRecord = context;
|
2018-10-09 14:42:30 +02:00
|
|
|
call_unhandled_exception_filter( &ptrs );
|
2009-04-30 13:08:32 +02: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;
|
|
|
|
|
|
|
|
TRACE( "code=%x flags=%x addr=%p ip=%x tid=%04x\n",
|
|
|
|
rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
|
|
|
|
context->Iar, 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] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: dump context */
|
|
|
|
}
|
|
|
|
|
|
|
|
status = send_debug_event( rec, TRUE, context );
|
|
|
|
if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
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
|
|
|
|
ERR("Unhandled exception code %x flags %x addr %p\n",
|
|
|
|
rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
|
2009-10-13 14:15:27 +02:00
|
|
|
NtTerminateProcess( NtCurrentProcess(), rec->ExceptionCode );
|
2009-04-30 13:08:32 +02:00
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
/**********************************************************************
|
2009-05-01 17:57:29 +02:00
|
|
|
* segv_handler
|
2002-08-27 02:30:20 +02:00
|
|
|
*
|
2009-05-01 17:57:29 +02:00
|
|
|
* Handler for SIGSEGV and related errors.
|
2002-08-27 02:30:20 +02:00
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
|
|
|
EXCEPTION_RECORD rec;
|
2009-05-01 17:57:29 +02:00
|
|
|
CONTEXT context;
|
2009-04-10 13:09:06 +02:00
|
|
|
NTSTATUS status;
|
2002-08-27 02:30:20 +02:00
|
|
|
|
2009-05-01 17:57:29 +02:00
|
|
|
save_context( &context, sigcontext );
|
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
rec.ExceptionRecord = NULL;
|
|
|
|
rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
|
2009-05-01 17:57:29 +02:00
|
|
|
rec.ExceptionAddress = (LPVOID)context.Iar;
|
2002-08-27 02:30:20 +02:00
|
|
|
rec.NumberParameters = 0;
|
2009-05-01 17:57:29 +02:00
|
|
|
|
|
|
|
switch (signal)
|
|
|
|
{
|
2002-08-27 02:30:20 +02:00
|
|
|
case SIGSEGV:
|
2009-05-01 17:57:29 +02:00
|
|
|
switch (siginfo->si_code & 0xffff)
|
|
|
|
{
|
2002-08-27 02:30:20 +02:00
|
|
|
case SEGV_MAPERR:
|
|
|
|
case SEGV_ACCERR:
|
2009-05-01 17:57:29 +02:00
|
|
|
rec.NumberParameters = 2;
|
|
|
|
rec.ExceptionInformation[0] = 0; /* FIXME ? */
|
|
|
|
rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
|
2015-02-10 14:54:25 +01:00
|
|
|
if (!(rec.ExceptionCode = virtual_handle_fault(siginfo->si_addr, rec.ExceptionInformation[0], FALSE)))
|
2009-05-01 17:57:29 +02:00
|
|
|
goto done;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled SIGSEGV/%x\n",siginfo->si_code);
|
|
|
|
break;
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIGBUS:
|
2009-05-01 17:57:29 +02:00
|
|
|
switch (siginfo->si_code & 0xffff)
|
|
|
|
{
|
2002-08-27 02:30:20 +02:00
|
|
|
case BUS_ADRALN:
|
2009-05-01 17:57:29 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#ifdef BUS_ADRERR
|
2002-08-27 02:30:20 +02:00
|
|
|
case BUS_ADRERR:
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef BUS_OBJERR
|
2002-08-27 02:30:20 +02:00
|
|
|
case BUS_OBJERR:
|
2009-05-01 17:57:29 +02:00
|
|
|
/* FIXME: correct for all cases ? */
|
|
|
|
rec.NumberParameters = 2;
|
|
|
|
rec.ExceptionInformation[0] = 0; /* FIXME ? */
|
|
|
|
rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
|
2015-02-10 14:54:25 +01:00
|
|
|
if (!(rec.ExceptionCode = virtual_handle_fault(siginfo->si_addr, rec.ExceptionInformation[0], FALSE)))
|
2009-05-01 17:57:29 +02:00
|
|
|
goto done;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
2009-05-01 17:57:29 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled SIGBUS/%x\n",siginfo->si_code);
|
|
|
|
break;
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SIGILL:
|
2009-05-01 17:57:29 +02:00
|
|
|
switch (siginfo->si_code & 0xffff)
|
|
|
|
{
|
2002-08-27 02:30:20 +02:00
|
|
|
case ILL_ILLOPC: /* illegal opcode */
|
2003-05-13 05:35:01 +02:00
|
|
|
#ifdef ILL_ILLOPN
|
2002-08-27 02:30:20 +02:00
|
|
|
case ILL_ILLOPN: /* illegal operand */
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_ILLADR
|
2002-08-27 02:30:20 +02:00
|
|
|
case ILL_ILLADR: /* illegal addressing mode */
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_ILLTRP
|
2002-08-27 02:30:20 +02:00
|
|
|
case ILL_ILLTRP: /* illegal trap */
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef ILL_COPROC
|
2002-08-27 02:30:20 +02:00
|
|
|
case ILL_COPROC: /* coprocessor error */
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
2009-05-01 17:57:29 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
|
|
|
|
break;
|
2002-08-27 02:30:20 +02:00
|
|
|
case ILL_PRVOPC: /* privileged opcode */
|
2003-05-13 05:35:01 +02:00
|
|
|
#ifdef ILL_PRVREG
|
2002-08-27 02:30:20 +02:00
|
|
|
case ILL_PRVREG: /* privileged register */
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
2009-05-01 17:57:29 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#ifdef ILL_BADSTK
|
2002-08-27 02:30:20 +02:00
|
|
|
case ILL_BADSTK: /* internal stack error */
|
2009-05-01 17:57:29 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_STACK_OVERFLOW;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
2009-05-01 17:57:29 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled SIGILL/%x\n", siginfo->si_code);
|
|
|
|
break;
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-05-01 17:57:29 +02:00
|
|
|
status = raise_exception( &rec, &context, TRUE );
|
2009-04-10 13:09:06 +02:00
|
|
|
if (status) raise_status( status, &rec );
|
2009-05-01 17:57:29 +02:00
|
|
|
done:
|
|
|
|
restore_context( &context, sigcontext );
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2009-05-01 17:57:29 +02:00
|
|
|
* trap_handler
|
2002-08-27 02:30:20 +02:00
|
|
|
*
|
2009-05-01 17:57:29 +02:00
|
|
|
* Handler for SIGTRAP.
|
2002-08-27 02:30:20 +02:00
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static void trap_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
|
|
|
EXCEPTION_RECORD rec;
|
2009-05-01 17:57:29 +02:00
|
|
|
CONTEXT context;
|
2009-04-10 13:09:06 +02:00
|
|
|
NTSTATUS status;
|
2002-08-27 02:30:20 +02:00
|
|
|
|
2009-05-01 17:57:29 +02:00
|
|
|
save_context( &context, sigcontext );
|
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
|
|
|
|
rec.ExceptionRecord = NULL;
|
2009-05-01 17:57:29 +02:00
|
|
|
rec.ExceptionAddress = (LPVOID)context.Iar;
|
2002-08-27 02:30:20 +02:00
|
|
|
rec.NumberParameters = 0;
|
|
|
|
|
|
|
|
/* FIXME: check if we might need to modify PC */
|
2009-05-01 17:57:29 +02:00
|
|
|
switch (siginfo->si_code & 0xffff)
|
|
|
|
{
|
2003-05-13 05:35:01 +02:00
|
|
|
#ifdef TRAP_BRKPT
|
2002-08-27 02:30:20 +02:00
|
|
|
case TRAP_BRKPT:
|
|
|
|
rec.ExceptionCode = EXCEPTION_BREAKPOINT;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef TRAP_TRACE
|
2002-08-27 02:30:20 +02:00
|
|
|
case TRAP_TRACE:
|
|
|
|
rec.ExceptionCode = EXCEPTION_SINGLE_STEP;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
2009-05-01 17:57:29 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled SIGTRAP/%x\n", siginfo->si_code);
|
|
|
|
break;
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
2009-05-01 17:57:29 +02:00
|
|
|
status = raise_exception( &rec, &context, TRUE );
|
2009-04-10 13:09:06 +02:00
|
|
|
if (status) raise_status( status, &rec );
|
2009-05-01 17:57:29 +02:00
|
|
|
restore_context( &context, sigcontext );
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2009-05-01 17:57:29 +02:00
|
|
|
* fpe_handler
|
2002-08-27 02:30:20 +02:00
|
|
|
*
|
2009-05-01 17:57:29 +02:00
|
|
|
* Handler for SIGFPE.
|
2002-08-27 02:30:20 +02:00
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static void fpe_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
|
|
|
EXCEPTION_RECORD rec;
|
2009-05-01 17:57:29 +02:00
|
|
|
CONTEXT context;
|
2009-04-10 13:09:06 +02:00
|
|
|
NTSTATUS status;
|
2002-08-27 02:30:20 +02:00
|
|
|
|
2009-05-01 17:57:29 +02:00
|
|
|
save_fpu( &context, sigcontext );
|
|
|
|
save_context( &context, sigcontext );
|
|
|
|
|
|
|
|
switch (siginfo->si_code & 0xffff )
|
|
|
|
{
|
2003-05-13 05:35:01 +02:00
|
|
|
#ifdef FPE_FLTSUB
|
2002-08-27 02:30:20 +02:00
|
|
|
case FPE_FLTSUB:
|
|
|
|
rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_INTDIV
|
2002-08-27 02:30:20 +02:00
|
|
|
case FPE_INTDIV:
|
|
|
|
rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_INTOVF
|
2002-08-27 02:30:20 +02:00
|
|
|
case FPE_INTOVF:
|
|
|
|
rec.ExceptionCode = EXCEPTION_INT_OVERFLOW;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTDIV
|
2002-08-27 02:30:20 +02:00
|
|
|
case FPE_FLTDIV:
|
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTOVF
|
2002-08-27 02:30:20 +02:00
|
|
|
case FPE_FLTOVF:
|
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTUND
|
2002-08-27 02:30:20 +02:00
|
|
|
case FPE_FLTUND:
|
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTRES
|
2002-08-27 02:30:20 +02:00
|
|
|
case FPE_FLTRES:
|
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT;
|
|
|
|
break;
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FPE_FLTINV
|
2002-08-27 02:30:20 +02:00
|
|
|
case FPE_FLTINV:
|
2003-05-13 05:35:01 +02:00
|
|
|
#endif
|
2002-08-27 02:30:20 +02:00
|
|
|
default:
|
|
|
|
rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
|
|
|
|
rec.ExceptionRecord = NULL;
|
2009-05-01 17:57:29 +02:00
|
|
|
rec.ExceptionAddress = (LPVOID)context.Iar;
|
2002-08-27 02:30:20 +02:00
|
|
|
rec.NumberParameters = 0;
|
2009-05-01 17:57:29 +02:00
|
|
|
status = raise_exception( &rec, &context, TRUE );
|
2009-04-10 13:09:06 +02:00
|
|
|
if (status) raise_status( status, &rec );
|
2003-05-13 05:35:01 +02:00
|
|
|
|
2009-05-01 17:57:29 +02:00
|
|
|
restore_context( &context, sigcontext );
|
|
|
|
restore_fpu( &context, sigcontext );
|
2003-05-13 05:35:01 +02:00
|
|
|
}
|
2002-08-27 02:30:20 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* int_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGINT.
|
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static void int_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
|
|
|
if (!dispatch_signal(SIGINT))
|
|
|
|
{
|
|
|
|
EXCEPTION_RECORD rec;
|
|
|
|
CONTEXT context;
|
2009-04-10 13:09:06 +02:00
|
|
|
NTSTATUS status;
|
2002-08-27 02:30:20 +02:00
|
|
|
|
2009-05-01 17:57:29 +02:00
|
|
|
save_context( &context, sigcontext );
|
2002-08-27 02:30:20 +02:00
|
|
|
rec.ExceptionCode = CONTROL_C_EXIT;
|
|
|
|
rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
|
|
|
|
rec.ExceptionRecord = NULL;
|
2002-08-30 02:00:57 +02:00
|
|
|
rec.ExceptionAddress = (LPVOID)context.Iar;
|
2002-08-27 02:30:20 +02:00
|
|
|
rec.NumberParameters = 0;
|
2009-04-10 13:09:06 +02:00
|
|
|
status = raise_exception( &rec, &context, TRUE );
|
|
|
|
if (status) raise_status( status, &rec );
|
2009-05-01 17:57:29 +02:00
|
|
|
restore_context( &context, sigcontext );
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-04 23:18:43 +01:00
|
|
|
|
2002-10-29 00:56:58 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* abrt_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGABRT.
|
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static void abrt_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2002-10-29 00:56:58 +01:00
|
|
|
{
|
|
|
|
EXCEPTION_RECORD rec;
|
|
|
|
CONTEXT context;
|
2009-04-10 13:09:06 +02:00
|
|
|
NTSTATUS status;
|
2002-10-29 00:56:58 +01:00
|
|
|
|
2009-05-01 17:57:29 +02:00
|
|
|
save_context( &context, sigcontext );
|
2002-10-29 00:56:58 +01:00
|
|
|
rec.ExceptionCode = EXCEPTION_WINE_ASSERTION;
|
|
|
|
rec.ExceptionFlags = EH_NONCONTINUABLE;
|
|
|
|
rec.ExceptionRecord = NULL;
|
2002-10-30 21:25:55 +01:00
|
|
|
rec.ExceptionAddress = (LPVOID)context.Iar;
|
2002-10-29 00:56:58 +01:00
|
|
|
rec.NumberParameters = 0;
|
2009-04-10 13:09:06 +02:00
|
|
|
status = raise_exception( &rec, &context, TRUE );
|
|
|
|
if (status) raise_status( status, &rec );
|
2009-05-01 17:57:29 +02:00
|
|
|
restore_context( &context, sigcontext );
|
2002-10-29 00:56:58 +01:00
|
|
|
}
|
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
|
2003-03-22 00:45:26 +01:00
|
|
|
/**********************************************************************
|
2007-12-20 12:19:35 +01:00
|
|
|
* quit_handler
|
2003-03-22 00:45:26 +01:00
|
|
|
*
|
2007-12-20 12:19:35 +01:00
|
|
|
* Handler for SIGQUIT.
|
2003-03-22 00:45:26 +01:00
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static void quit_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2003-03-22 00:45:26 +01:00
|
|
|
{
|
2009-02-20 11:23:08 +01:00
|
|
|
abort_thread(0);
|
2003-03-22 00:45:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-04 23:18:43 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* usr1_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGUSR1, used to signal a thread that it got suspended.
|
|
|
|
*/
|
2009-05-01 17:57:29 +02:00
|
|
|
static void usr1_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2003-03-04 23:18:43 +01:00
|
|
|
{
|
2005-11-02 21:54:12 +01:00
|
|
|
CONTEXT context;
|
2003-04-04 01:57:11 +02:00
|
|
|
|
2009-05-01 17:57:29 +02:00
|
|
|
save_context( &context, sigcontext );
|
2005-11-02 21:54:12 +01:00
|
|
|
wait_suspend( &context );
|
2009-05-01 17:57:29 +02:00
|
|
|
restore_context( &context, sigcontext );
|
2003-03-04 23:18:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* __wine_set_signal_handler (NTDLL.@)
|
|
|
|
*/
|
2008-12-16 16:37:46 +01:00
|
|
|
int CDECL __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh)
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
2018-08-02 21:54:37 +02:00
|
|
|
if (sig >= ARRAY_SIZE(handlers)) return -1;
|
2002-08-27 02:30:20 +02:00
|
|
|
if (handlers[sig] != NULL) return -2;
|
|
|
|
handlers[sig] = wsh;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-19 12:25:52 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* signal_alloc_thread
|
|
|
|
*/
|
|
|
|
NTSTATUS signal_alloc_thread( TEB **teb )
|
|
|
|
{
|
2019-06-13 12:48:31 +02:00
|
|
|
static size_t sigstack_alignment;
|
2009-11-19 12:25:52 +01:00
|
|
|
SIZE_T size;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2019-06-13 12:48:31 +02:00
|
|
|
if (!sigstack_alignment)
|
2009-11-19 12:25:52 +01:00
|
|
|
{
|
2013-01-08 14:00:06 +01:00
|
|
|
size_t min_size = page_size; /* this is just for the TEB, we don't use a signal stack yet */
|
2009-11-19 12:25:52 +01:00
|
|
|
/* find the first power of two not smaller than min_size */
|
2019-06-13 12:48:31 +02:00
|
|
|
while ((1u << sigstack_alignment) < min_size) sigstack_alignment++;
|
2009-11-19 12:25:52 +01:00
|
|
|
assert( sizeof(TEB) <= min_size );
|
|
|
|
}
|
|
|
|
|
2019-06-13 12:48:31 +02:00
|
|
|
size = 1 << sigstack_alignment;
|
2009-11-19 12:25:52 +01:00
|
|
|
*teb = NULL;
|
2019-06-13 12:48:31 +02:00
|
|
|
if (!(status = virtual_alloc_aligned( (void **)teb, 0, &size, MEM_COMMIT | MEM_TOP_DOWN,
|
|
|
|
PAGE_READWRITE, sigstack_alignment )))
|
2009-11-19 12:25:52 +01:00
|
|
|
{
|
|
|
|
(*teb)->Tib.Self = &(*teb)->Tib;
|
|
|
|
(*teb)->Tib.ExceptionList = (void *)~0UL;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* signal_free_thread
|
|
|
|
*/
|
|
|
|
void signal_free_thread( TEB *teb )
|
|
|
|
{
|
2017-11-29 10:43:39 +01:00
|
|
|
SIZE_T size = 0;
|
2009-11-19 12:25:52 +01:00
|
|
|
|
|
|
|
NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
/**********************************************************************
|
2008-07-03 20:18:23 +02:00
|
|
|
* signal_init_thread
|
2002-08-27 02:30:20 +02:00
|
|
|
*/
|
2009-02-18 13:04:50 +01:00
|
|
|
void signal_init_thread( TEB *teb )
|
2008-07-03 20:18:23 +02:00
|
|
|
{
|
2013-10-29 21:54:12 +01:00
|
|
|
static BOOL init_done;
|
2009-02-18 13:04:50 +01:00
|
|
|
|
|
|
|
if (!init_done)
|
|
|
|
{
|
|
|
|
pthread_key_create( &teb_key, NULL );
|
2013-10-29 21:54:12 +01:00
|
|
|
init_done = TRUE;
|
2009-02-18 13:04:50 +01:00
|
|
|
}
|
|
|
|
pthread_setspecific( teb_key, teb );
|
2008-07-03 20:18:23 +02:00
|
|
|
}
|
|
|
|
|
2009-02-18 13:04:50 +01:00
|
|
|
|
2008-07-03 20:18:23 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* signal_init_process
|
|
|
|
*/
|
2017-11-29 17:11:10 +01:00
|
|
|
void signal_init_process(void)
|
2002-08-27 02:30:20 +02:00
|
|
|
{
|
2009-05-01 17:57:29 +02:00
|
|
|
struct sigaction sig_act;
|
|
|
|
|
|
|
|
sig_act.sa_mask = server_block_set;
|
|
|
|
sig_act.sa_flags = SA_RESTART | SA_SIGINFO;
|
|
|
|
|
|
|
|
sig_act.sa_sigaction = int_handler;
|
|
|
|
if (sigaction( SIGINT, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = fpe_handler;
|
|
|
|
if (sigaction( SIGFPE, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = abrt_handler;
|
|
|
|
if (sigaction( SIGABRT, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = quit_handler;
|
|
|
|
if (sigaction( SIGQUIT, &sig_act, NULL ) == -1) goto error;
|
|
|
|
sig_act.sa_sigaction = usr1_handler;
|
|
|
|
if (sigaction( SIGUSR1, &sig_act, NULL ) == -1) goto error;
|
|
|
|
|
|
|
|
sig_act.sa_sigaction = segv_handler;
|
|
|
|
if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error;
|
|
|
|
if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error;
|
2002-08-27 02:30:20 +02:00
|
|
|
#ifdef SIGBUS
|
2009-05-01 17:57:29 +02:00
|
|
|
if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error;
|
2002-08-27 02:30:20 +02:00
|
|
|
#endif
|
2009-05-01 17:57:29 +02:00
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
#ifdef SIGTRAP
|
2009-05-01 17:57:29 +02:00
|
|
|
sig_act.sa_sigaction = trap_handler;
|
|
|
|
if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
|
2002-08-27 02:30:20 +02:00
|
|
|
#endif
|
2008-07-03 20:18:23 +02:00
|
|
|
return;
|
2002-08-27 02:30:20 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
perror("sigaction");
|
2008-07-03 20:18:23 +02:00
|
|
|
exit(1);
|
2002-08-27 02:30:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-30 13:08:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlUnwind (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlUnwind( PVOID pEndFrame, PVOID targetIp, PEXCEPTION_RECORD pRecord, PVOID retval )
|
|
|
|
{
|
|
|
|
FIXME( "Not implemented on PowerPC\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* NtRaiseException (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
|
|
|
|
{
|
|
|
|
NTSTATUS status = raise_exception( rec, context, first_chance );
|
|
|
|
if (status == STATUS_SUCCESS) NtSetContextThread( GetCurrentThread(), context );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-04-10 13:14:05 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RtlRaiseException (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI RtlRaiseException( EXCEPTION_RECORD *rec )
|
|
|
|
{
|
|
|
|
CONTEXT context;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
RtlCaptureContext( &context );
|
2009-04-10 13:17:12 +02:00
|
|
|
rec->ExceptionAddress = (void *)context.Iar;
|
2009-04-10 13:14:05 +02:00
|
|
|
status = raise_exception( rec, &context, TRUE );
|
|
|
|
if (status) raise_status( status, rec );
|
|
|
|
}
|
|
|
|
|
2009-11-11 17:19:23 +01: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;
|
|
|
|
}
|
|
|
|
|
2009-06-18 16:38:30 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* call_thread_entry_point
|
|
|
|
*/
|
2017-12-04 13:13:05 +01:00
|
|
|
static void WINAPI call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg )
|
2009-06-18 16:38:30 +02:00
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
2017-12-01 19:24:21 +01:00
|
|
|
TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg );
|
2017-12-14 10:54:56 +01:00
|
|
|
RtlExitUserThread( entry( arg ));
|
2009-06-18 16:38:30 +02:00
|
|
|
}
|
2018-10-09 14:42:30 +02:00
|
|
|
__EXCEPT(call_unhandled_exception_filter)
|
2009-06-18 16:38:30 +02:00
|
|
|
{
|
|
|
|
NtTerminateThread( GetCurrentThread(), GetExceptionCode() );
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
abort(); /* should not be reached */
|
|
|
|
}
|
|
|
|
|
2017-12-04 13:13:05 +01:00
|
|
|
typedef void (WINAPI *thread_start_func)(LPTHREAD_START_ROUTINE,void *);
|
|
|
|
|
2017-12-01 19:24:21 +01:00
|
|
|
struct startup_info
|
|
|
|
{
|
2017-12-04 13:13:05 +01:00
|
|
|
thread_start_func start;
|
2017-12-01 19:24:21 +01:00
|
|
|
LPTHREAD_START_ROUTINE entry;
|
|
|
|
void *arg;
|
|
|
|
BOOL suspend;
|
|
|
|
};
|
|
|
|
|
2020-01-29 10:48:39 +01:00
|
|
|
/* FIXME: should set the full context instead */
|
|
|
|
extern void DECLSPEC_NORETURN switch_to_stack( void (*func)(void *), void *arg, void *stack );
|
|
|
|
__ASM_GLOBAL_FUNC( switch_to_stack,
|
|
|
|
"subi 5, 5, 16\n\t" /* reserve space on new stack */
|
|
|
|
"mtctr 3\n\t" /* func -> ctr */
|
|
|
|
"mr 3,4\n\t" /* args -> function param 1 (r3) */
|
|
|
|
"mr 1,5\n\t" /* stack */
|
|
|
|
"li 0, 0\n\t" /* zero */
|
|
|
|
"stw 0, 0(1)\n\t" /* bottom of stack */
|
|
|
|
"stwu 1, -16(1)\n\t" /* create a frame for this function */
|
|
|
|
"bctrl" ) /* call ctr */
|
|
|
|
|
2017-12-01 19:24:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* thread_startup
|
|
|
|
*/
|
|
|
|
static void thread_startup( void *param )
|
|
|
|
{
|
|
|
|
CONTEXT context = { 0 };
|
|
|
|
struct startup_info *info = param;
|
|
|
|
|
|
|
|
/* build the initial context */
|
|
|
|
context.ContextFlags = CONTEXT_FULL;
|
|
|
|
context.Gpr1 = (DWORD)NtCurrentTeb()->Tib.StackBase;
|
|
|
|
context.Gpr3 = (DWORD)info->entry;
|
|
|
|
context.Gpr4 = (DWORD)info->arg;
|
2017-12-04 13:13:05 +01:00
|
|
|
context.Iar = (DWORD)info->start;
|
2017-12-01 19:24:21 +01:00
|
|
|
|
2018-01-22 15:17:25 +01:00
|
|
|
if (info->suspend) wait_suspend( &context );
|
2019-02-14 16:49:09 +01:00
|
|
|
LdrInitializeThunk( &context, (void **)&context.Gpr3, 0, 0 );
|
2017-12-01 19:24:21 +01:00
|
|
|
|
2017-12-04 13:13:05 +01:00
|
|
|
((thread_start_func)context.Iar)( (LPTHREAD_START_ROUTINE)context.Gpr3, (void *)context.Gpr4 );
|
2017-12-01 19:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* signal_start_thread
|
|
|
|
*
|
|
|
|
* Thread startup sequence:
|
|
|
|
* signal_start_thread()
|
|
|
|
* -> thread_startup()
|
|
|
|
* -> call_thread_entry_point()
|
|
|
|
*/
|
|
|
|
void signal_start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend )
|
|
|
|
{
|
2017-12-04 13:13:05 +01:00
|
|
|
struct startup_info info = { call_thread_entry_point, entry, arg, suspend };
|
2020-01-29 10:48:39 +01:00
|
|
|
switch_to_stack( thread_startup, &info, NtCurrentTeb()->Tib.StackBase );
|
2017-12-01 19:24:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* signal_start_process
|
|
|
|
*
|
|
|
|
* Process startup sequence:
|
|
|
|
* signal_start_process()
|
|
|
|
* -> thread_startup()
|
2017-12-04 13:13:05 +01:00
|
|
|
* -> kernel32_start_process()
|
2017-12-01 19:24:21 +01:00
|
|
|
*/
|
|
|
|
void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend )
|
|
|
|
{
|
2017-12-04 13:13:05 +01:00
|
|
|
struct startup_info info = { kernel32_start_process, entry, NtCurrentTeb()->Peb, suspend };
|
2020-01-29 10:48:39 +01:00
|
|
|
switch_to_stack( thread_startup, &info, NtCurrentTeb()->Tib.StackBase );
|
2017-12-01 19:24:21 +01:00
|
|
|
}
|
|
|
|
|
2009-06-18 16:50:34 +02:00
|
|
|
/***********************************************************************
|
2017-12-14 10:54:56 +01:00
|
|
|
* signal_exit_thread
|
2009-06-18 16:50:34 +02:00
|
|
|
*/
|
2017-12-14 10:54:56 +01:00
|
|
|
void signal_exit_thread( int status )
|
2009-06-18 16:50:34 +02:00
|
|
|
{
|
|
|
|
exit_thread( status );
|
|
|
|
}
|
|
|
|
|
2009-08-28 11:52:21 +02:00
|
|
|
/***********************************************************************
|
2017-12-14 10:54:56 +01:00
|
|
|
* signal_exit_process
|
2009-08-28 11:52:21 +02:00
|
|
|
*/
|
2017-12-14 10:54:56 +01:00
|
|
|
void signal_exit_process( int status )
|
2009-08-28 11:52:21 +02:00
|
|
|
{
|
2017-12-14 10:54:56 +01:00
|
|
|
exit( status );
|
2009-08-28 11:52:21 +02:00
|
|
|
}
|
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* DbgBreakPoint (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI DbgBreakPoint(void)
|
|
|
|
{
|
|
|
|
kill(getpid(), SIGTRAP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* DbgUserBreakPoint (NTDLL.@)
|
|
|
|
*/
|
|
|
|
void WINAPI DbgUserBreakPoint(void)
|
|
|
|
{
|
|
|
|
kill(getpid(), SIGTRAP);
|
|
|
|
}
|
|
|
|
|
2009-02-18 13:04:50 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* NtCurrentTeb (NTDLL.@)
|
|
|
|
*/
|
|
|
|
TEB * WINAPI NtCurrentTeb(void)
|
|
|
|
{
|
|
|
|
return pthread_getspecific( teb_key );
|
|
|
|
}
|
|
|
|
|
2002-08-27 02:30:20 +02:00
|
|
|
#endif /* __powerpc__ */
|