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 "config.h"
|
2002-04-25 23:40:56 +02:00
|
|
|
#include "wine/port.h"
|
1999-09-27 12:58:45 +02:00
|
|
|
|
|
|
|
#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>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
1999-09-27 12:58:45 +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
|
2000-11-29 21:04:09 +01:00
|
|
|
#ifdef HAVE_SYS_SIGNAL_H
|
|
|
|
# include <sys/signal.h>
|
|
|
|
#endif
|
2006-09-07 18:08:46 +02:00
|
|
|
#ifdef HAVE_SYS_SYSCTL_H
|
|
|
|
# include <sys/sysctl.h>
|
|
|
|
#endif
|
2014-07-23 16:30:13 +02:00
|
|
|
#ifdef HAVE_SYS_UCONTEXT_H
|
|
|
|
# include <sys/ucontext.h>
|
|
|
|
#endif
|
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"
|
2002-05-16 22:32:16 +02:00
|
|
|
#include "wine/library.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
|
|
|
|
2006-02-14 13:06:29 +01:00
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
#include <valgrind/memcheck.h>
|
|
|
|
#endif
|
|
|
|
|
2007-03-14 09:53:59 +01:00
|
|
|
#undef ERR /* Solaris needs to define this */
|
|
|
|
|
2017-11-29 19:42:53 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(seh);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
|
|
|
|
2008-01-15 18:08:29 +01:00
|
|
|
/* not defined for x86, so copy the x86_64 definition */
|
|
|
|
typedef struct DECLSPEC_ALIGN(16) _M128A
|
|
|
|
{
|
|
|
|
ULONGLONG Low;
|
|
|
|
LONGLONG High;
|
|
|
|
} M128A;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
WORD ControlWord;
|
|
|
|
WORD StatusWord;
|
|
|
|
BYTE TagWord;
|
|
|
|
BYTE Reserved1;
|
|
|
|
WORD ErrorOpcode;
|
|
|
|
DWORD ErrorOffset;
|
|
|
|
WORD ErrorSelector;
|
|
|
|
WORD Reserved2;
|
|
|
|
DWORD DataOffset;
|
|
|
|
WORD DataSelector;
|
|
|
|
WORD Reserved3;
|
|
|
|
DWORD MxCsr;
|
|
|
|
DWORD MxCsr_Mask;
|
|
|
|
M128A FloatRegisters[8];
|
|
|
|
M128A XmmRegisters[16];
|
|
|
|
BYTE Reserved4[96];
|
|
|
|
} XMM_SAVE_AREA32;
|
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* signal context platform-specific definitions
|
|
|
|
*/
|
|
|
|
|
2014-07-23 19:30:14 +02:00
|
|
|
#ifdef __linux__
|
2013-07-30 14:11:42 +02:00
|
|
|
|
2014-07-23 16:32:33 +02:00
|
|
|
#ifndef HAVE_SYS_UCONTEXT_H
|
2014-07-23 19:30:14 +02:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
REG_GS, REG_FS, REG_ES, REG_DS, REG_EDI, REG_ESI, REG_EBP, REG_ESP,
|
|
|
|
REG_EBX, REG_EDX, REG_ECX, REG_EAX, REG_TRAPNO, REG_ERR, REG_EIP,
|
|
|
|
REG_CS, REG_EFL, REG_UESP, REG_SS, NGREG
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef int greg_t;
|
|
|
|
typedef greg_t gregset_t[NGREG];
|
|
|
|
|
|
|
|
struct _libc_fpreg
|
|
|
|
{
|
|
|
|
unsigned short significand[4];
|
|
|
|
unsigned short exponent;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _libc_fpstate
|
|
|
|
{
|
|
|
|
unsigned long cw;
|
|
|
|
unsigned long sw;
|
|
|
|
unsigned long tag;
|
|
|
|
unsigned long ipoff;
|
|
|
|
unsigned long cssel;
|
|
|
|
unsigned long dataoff;
|
|
|
|
unsigned long datasel;
|
|
|
|
struct _libc_fpreg _st[8];
|
|
|
|
unsigned long status;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _libc_fpstate* fpregset_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gregset_t gregs;
|
|
|
|
fpregset_t fpregs;
|
|
|
|
unsigned long oldmask;
|
|
|
|
unsigned long cr2;
|
|
|
|
} mcontext_t;
|
|
|
|
|
2013-07-30 14:11:42 +02:00
|
|
|
typedef struct ucontext
|
|
|
|
{
|
|
|
|
unsigned long uc_flags;
|
|
|
|
struct ucontext *uc_link;
|
|
|
|
stack_t uc_stack;
|
2014-07-23 19:30:14 +02:00
|
|
|
mcontext_t uc_mcontext;
|
2013-07-30 14:11:42 +02:00
|
|
|
sigset_t uc_sigmask;
|
2014-07-23 16:32:33 +02:00
|
|
|
} ucontext_t;
|
2014-07-23 19:30:14 +02:00
|
|
|
#endif /* HAVE_SYS_UCONTEXT_H */
|
1999-09-27 12:58:45 +02:00
|
|
|
|
2006-08-11 14:14:38 +02:00
|
|
|
#define EAX_sig(context) ((context)->uc_mcontext.gregs[REG_EAX])
|
|
|
|
#define EBX_sig(context) ((context)->uc_mcontext.gregs[REG_EBX])
|
|
|
|
#define ECX_sig(context) ((context)->uc_mcontext.gregs[REG_ECX])
|
|
|
|
#define EDX_sig(context) ((context)->uc_mcontext.gregs[REG_EDX])
|
|
|
|
#define ESI_sig(context) ((context)->uc_mcontext.gregs[REG_ESI])
|
|
|
|
#define EDI_sig(context) ((context)->uc_mcontext.gregs[REG_EDI])
|
|
|
|
#define EBP_sig(context) ((context)->uc_mcontext.gregs[REG_EBP])
|
|
|
|
#define ESP_sig(context) ((context)->uc_mcontext.gregs[REG_ESP])
|
|
|
|
|
|
|
|
#define CS_sig(context) ((context)->uc_mcontext.gregs[REG_CS])
|
|
|
|
#define DS_sig(context) ((context)->uc_mcontext.gregs[REG_DS])
|
|
|
|
#define ES_sig(context) ((context)->uc_mcontext.gregs[REG_ES])
|
|
|
|
#define SS_sig(context) ((context)->uc_mcontext.gregs[REG_SS])
|
|
|
|
#define FS_sig(context) ((context)->uc_mcontext.gregs[REG_FS])
|
|
|
|
#define GS_sig(context) ((context)->uc_mcontext.gregs[REG_GS])
|
|
|
|
|
|
|
|
#define EFL_sig(context) ((context)->uc_mcontext.gregs[REG_EFL])
|
|
|
|
#define EIP_sig(context) ((context)->uc_mcontext.gregs[REG_EIP])
|
|
|
|
#define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO])
|
|
|
|
#define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR])
|
|
|
|
|
|
|
|
#define FPU_sig(context) ((FLOATING_SAVE_AREA*)((context)->uc_mcontext.fpregs))
|
2008-01-22 10:20:12 +01:00
|
|
|
#define FPUX_sig(context) (FPU_sig(context) && !((context)->uc_mcontext.fpregs->status >> 16) ? (XMM_SAVE_AREA32 *)(FPU_sig(context) + 1) : NULL)
|
2006-08-05 22:34:11 +02:00
|
|
|
|
2014-07-23 19:30:14 +02:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
/* custom signal restorer since we may have unmapped the one in vdso, and bionic doesn't check for that */
|
|
|
|
void rt_sigreturn(void);
|
|
|
|
__ASM_GLOBAL_FUNC( rt_sigreturn,
|
|
|
|
"movl $173,%eax\n\t" /* NR_rt_sigreturn */
|
|
|
|
"int $0x80" );
|
|
|
|
#endif
|
|
|
|
|
2012-04-09 21:04:23 +02:00
|
|
|
#elif defined (__BSDI__)
|
1999-09-27 12:58:45 +02:00
|
|
|
|
2006-08-11 14:45:11 +02:00
|
|
|
#include <machine/frame.h>
|
2014-07-23 16:32:33 +02:00
|
|
|
typedef struct trapframe ucontext_t;
|
2006-08-11 14:45:11 +02:00
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
#define EAX_sig(context) ((context)->tf_eax)
|
|
|
|
#define EBX_sig(context) ((context)->tf_ebx)
|
|
|
|
#define ECX_sig(context) ((context)->tf_ecx)
|
|
|
|
#define EDX_sig(context) ((context)->tf_edx)
|
|
|
|
#define ESI_sig(context) ((context)->tf_esi)
|
|
|
|
#define EDI_sig(context) ((context)->tf_edi)
|
|
|
|
#define EBP_sig(context) ((context)->tf_ebp)
|
2002-06-01 01:06:46 +02:00
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
#define CS_sig(context) ((context)->tf_cs)
|
|
|
|
#define DS_sig(context) ((context)->tf_ds)
|
|
|
|
#define ES_sig(context) ((context)->tf_es)
|
|
|
|
#define SS_sig(context) ((context)->tf_ss)
|
|
|
|
|
|
|
|
#define EFL_sig(context) ((context)->tf_eflags)
|
|
|
|
|
|
|
|
#define EIP_sig(context) (*((unsigned long*)&(context)->tf_eip))
|
|
|
|
#define ESP_sig(context) (*((unsigned long*)&(context)->tf_esp))
|
|
|
|
|
2008-01-15 18:08:29 +01:00
|
|
|
#define FPU_sig(context) NULL /* FIXME */
|
|
|
|
#define FPUX_sig(context) NULL /* FIXME */
|
|
|
|
|
2012-04-09 21:04:23 +02:00
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
1999-09-27 12:58:45 +02:00
|
|
|
|
2011-01-16 00:53:13 +01:00
|
|
|
#include <machine/trap.h>
|
|
|
|
|
2014-07-24 19:23:55 +02:00
|
|
|
#define EAX_sig(context) ((context)->uc_mcontext.mc_eax)
|
|
|
|
#define EBX_sig(context) ((context)->uc_mcontext.mc_ebx)
|
|
|
|
#define ECX_sig(context) ((context)->uc_mcontext.mc_ecx)
|
|
|
|
#define EDX_sig(context) ((context)->uc_mcontext.mc_edx)
|
|
|
|
#define ESI_sig(context) ((context)->uc_mcontext.mc_esi)
|
|
|
|
#define EDI_sig(context) ((context)->uc_mcontext.mc_edi)
|
|
|
|
#define EBP_sig(context) ((context)->uc_mcontext.mc_ebp)
|
|
|
|
|
|
|
|
#define CS_sig(context) ((context)->uc_mcontext.mc_cs)
|
|
|
|
#define DS_sig(context) ((context)->uc_mcontext.mc_ds)
|
|
|
|
#define ES_sig(context) ((context)->uc_mcontext.mc_es)
|
|
|
|
#define FS_sig(context) ((context)->uc_mcontext.mc_fs)
|
|
|
|
#define GS_sig(context) ((context)->uc_mcontext.mc_gs)
|
|
|
|
#define SS_sig(context) ((context)->uc_mcontext.mc_ss)
|
|
|
|
|
|
|
|
#define TRAP_sig(context) ((context)->uc_mcontext.mc_trapno)
|
|
|
|
#define ERROR_sig(context) ((context)->uc_mcontext.mc_err)
|
|
|
|
#define EFL_sig(context) ((context)->uc_mcontext.mc_eflags)
|
|
|
|
|
|
|
|
#define EIP_sig(context) ((context)->uc_mcontext.mc_eip)
|
|
|
|
#define ESP_sig(context) ((context)->uc_mcontext.mc_esp)
|
2006-08-05 22:34:11 +02:00
|
|
|
|
2008-01-15 18:08:29 +01:00
|
|
|
#define FPU_sig(context) NULL /* FIXME */
|
|
|
|
#define FPUX_sig(context) NULL /* FIXME */
|
|
|
|
|
2012-04-09 21:04:23 +02:00
|
|
|
#elif defined (__OpenBSD__)
|
2009-04-01 12:37:05 +02:00
|
|
|
|
|
|
|
#define EAX_sig(context) ((context)->sc_eax)
|
|
|
|
#define EBX_sig(context) ((context)->sc_ebx)
|
|
|
|
#define ECX_sig(context) ((context)->sc_ecx)
|
|
|
|
#define EDX_sig(context) ((context)->sc_edx)
|
|
|
|
#define ESI_sig(context) ((context)->sc_esi)
|
|
|
|
#define EDI_sig(context) ((context)->sc_edi)
|
|
|
|
#define EBP_sig(context) ((context)->sc_ebp)
|
|
|
|
|
|
|
|
#define CS_sig(context) ((context)->sc_cs)
|
|
|
|
#define DS_sig(context) ((context)->sc_ds)
|
|
|
|
#define ES_sig(context) ((context)->sc_es)
|
|
|
|
#define FS_sig(context) ((context)->sc_fs)
|
|
|
|
#define GS_sig(context) ((context)->sc_gs)
|
|
|
|
#define SS_sig(context) ((context)->sc_ss)
|
|
|
|
|
|
|
|
#define TRAP_sig(context) ((context)->sc_trapno)
|
|
|
|
#define ERROR_sig(context) ((context)->sc_err)
|
|
|
|
#define EFL_sig(context) ((context)->sc_eflags)
|
|
|
|
|
|
|
|
#define EIP_sig(context) ((context)->sc_eip)
|
|
|
|
#define ESP_sig(context) ((context)->sc_esp)
|
|
|
|
|
|
|
|
#define FPU_sig(context) NULL /* FIXME */
|
|
|
|
#define FPUX_sig(context) NULL /* FIXME */
|
|
|
|
|
|
|
|
#define T_MCHK T_MACHK
|
|
|
|
#define T_XMMFLT T_XFTRAP
|
|
|
|
|
2012-04-09 21:04:23 +02:00
|
|
|
#elif defined(__svr4__) || defined(_SCO_DS) || defined(__sun)
|
1999-09-27 12:58:45 +02:00
|
|
|
|
2019-10-06 22:18:18 +02:00
|
|
|
#if defined(_SCO_DS) || defined(__sun)
|
1999-09-27 12:58:45 +02:00
|
|
|
#include <sys/regset.h>
|
2019-10-06 22:18:18 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _SCO_DS
|
2006-08-05 22:34:11 +02:00
|
|
|
#define gregs regs
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define EAX_sig(context) ((context)->uc_mcontext.gregs[EAX])
|
|
|
|
#define EBX_sig(context) ((context)->uc_mcontext.gregs[EBX])
|
|
|
|
#define ECX_sig(context) ((context)->uc_mcontext.gregs[ECX])
|
|
|
|
#define EDX_sig(context) ((context)->uc_mcontext.gregs[EDX])
|
|
|
|
#define ESI_sig(context) ((context)->uc_mcontext.gregs[ESI])
|
|
|
|
#define EDI_sig(context) ((context)->uc_mcontext.gregs[EDI])
|
|
|
|
#define EBP_sig(context) ((context)->uc_mcontext.gregs[EBP])
|
|
|
|
|
|
|
|
#define CS_sig(context) ((context)->uc_mcontext.gregs[CS])
|
|
|
|
#define DS_sig(context) ((context)->uc_mcontext.gregs[DS])
|
|
|
|
#define ES_sig(context) ((context)->uc_mcontext.gregs[ES])
|
|
|
|
#define SS_sig(context) ((context)->uc_mcontext.gregs[SS])
|
|
|
|
|
|
|
|
#define FS_sig(context) ((context)->uc_mcontext.gregs[FS])
|
|
|
|
#define GS_sig(context) ((context)->uc_mcontext.gregs[GS])
|
|
|
|
|
|
|
|
#define EFL_sig(context) ((context)->uc_mcontext.gregs[EFL])
|
|
|
|
|
|
|
|
#define EIP_sig(context) ((context)->uc_mcontext.gregs[EIP])
|
|
|
|
#ifdef UESP
|
|
|
|
#define ESP_sig(context) ((context)->uc_mcontext.gregs[UESP])
|
|
|
|
#elif defined(R_ESP)
|
|
|
|
#define ESP_sig(context) ((context)->uc_mcontext.gregs[R_ESP])
|
|
|
|
#else
|
|
|
|
#define ESP_sig(context) ((context)->uc_mcontext.gregs[ESP])
|
|
|
|
#endif
|
2007-03-14 09:53:59 +01:00
|
|
|
#ifdef ERR
|
|
|
|
#define ERROR_sig(context) ((context)->uc_mcontext.gregs[ERR])
|
|
|
|
#endif
|
2006-08-05 22:34:11 +02:00
|
|
|
#ifdef TRAPNO
|
|
|
|
#define TRAP_sig(context) ((context)->uc_mcontext.gregs[TRAPNO])
|
|
|
|
#endif
|
|
|
|
|
2008-01-15 18:08:29 +01:00
|
|
|
#define FPU_sig(context) NULL /* FIXME */
|
|
|
|
#define FPUX_sig(context) NULL /* FIXME */
|
|
|
|
|
2012-04-09 21:04:23 +02:00
|
|
|
#elif defined (__APPLE__)
|
2004-08-24 04:26:59 +02:00
|
|
|
|
2007-03-12 16:14:18 +01:00
|
|
|
/* work around silly renaming of struct members in OS X 10.5 */
|
|
|
|
#if __DARWIN_UNIX03 && defined(_STRUCT_X86_EXCEPTION_STATE32)
|
|
|
|
#define EAX_sig(context) ((context)->uc_mcontext->__ss.__eax)
|
|
|
|
#define EBX_sig(context) ((context)->uc_mcontext->__ss.__ebx)
|
|
|
|
#define ECX_sig(context) ((context)->uc_mcontext->__ss.__ecx)
|
|
|
|
#define EDX_sig(context) ((context)->uc_mcontext->__ss.__edx)
|
|
|
|
#define ESI_sig(context) ((context)->uc_mcontext->__ss.__esi)
|
|
|
|
#define EDI_sig(context) ((context)->uc_mcontext->__ss.__edi)
|
|
|
|
#define EBP_sig(context) ((context)->uc_mcontext->__ss.__ebp)
|
|
|
|
#define CS_sig(context) ((context)->uc_mcontext->__ss.__cs)
|
|
|
|
#define DS_sig(context) ((context)->uc_mcontext->__ss.__ds)
|
|
|
|
#define ES_sig(context) ((context)->uc_mcontext->__ss.__es)
|
|
|
|
#define FS_sig(context) ((context)->uc_mcontext->__ss.__fs)
|
|
|
|
#define GS_sig(context) ((context)->uc_mcontext->__ss.__gs)
|
|
|
|
#define SS_sig(context) ((context)->uc_mcontext->__ss.__ss)
|
|
|
|
#define EFL_sig(context) ((context)->uc_mcontext->__ss.__eflags)
|
|
|
|
#define EIP_sig(context) (*((unsigned long*)&(context)->uc_mcontext->__ss.__eip))
|
|
|
|
#define ESP_sig(context) (*((unsigned long*)&(context)->uc_mcontext->__ss.__esp))
|
|
|
|
#define TRAP_sig(context) ((context)->uc_mcontext->__es.__trapno)
|
|
|
|
#define ERROR_sig(context) ((context)->uc_mcontext->__es.__err)
|
2008-01-15 20:27:14 +01:00
|
|
|
#define FPU_sig(context) NULL
|
|
|
|
#define FPUX_sig(context) ((XMM_SAVE_AREA32 *)&(context)->uc_mcontext->__fs.__fpu_fcw)
|
2007-03-12 16:14:18 +01:00
|
|
|
#else
|
2005-11-15 19:15:56 +01:00
|
|
|
#define EAX_sig(context) ((context)->uc_mcontext->ss.eax)
|
|
|
|
#define EBX_sig(context) ((context)->uc_mcontext->ss.ebx)
|
|
|
|
#define ECX_sig(context) ((context)->uc_mcontext->ss.ecx)
|
|
|
|
#define EDX_sig(context) ((context)->uc_mcontext->ss.edx)
|
|
|
|
#define ESI_sig(context) ((context)->uc_mcontext->ss.esi)
|
|
|
|
#define EDI_sig(context) ((context)->uc_mcontext->ss.edi)
|
|
|
|
#define EBP_sig(context) ((context)->uc_mcontext->ss.ebp)
|
|
|
|
#define CS_sig(context) ((context)->uc_mcontext->ss.cs)
|
|
|
|
#define DS_sig(context) ((context)->uc_mcontext->ss.ds)
|
|
|
|
#define ES_sig(context) ((context)->uc_mcontext->ss.es)
|
|
|
|
#define FS_sig(context) ((context)->uc_mcontext->ss.fs)
|
|
|
|
#define GS_sig(context) ((context)->uc_mcontext->ss.gs)
|
|
|
|
#define SS_sig(context) ((context)->uc_mcontext->ss.ss)
|
|
|
|
#define EFL_sig(context) ((context)->uc_mcontext->ss.eflags)
|
|
|
|
#define EIP_sig(context) (*((unsigned long*)&(context)->uc_mcontext->ss.eip))
|
|
|
|
#define ESP_sig(context) (*((unsigned long*)&(context)->uc_mcontext->ss.esp))
|
|
|
|
#define TRAP_sig(context) ((context)->uc_mcontext->es.trapno)
|
|
|
|
#define ERROR_sig(context) ((context)->uc_mcontext->es.err)
|
2008-01-15 20:27:14 +01:00
|
|
|
#define FPU_sig(context) NULL
|
|
|
|
#define FPUX_sig(context) ((XMM_SAVE_AREA32 *)&(context)->uc_mcontext->fs.fpu_fcw)
|
2007-03-12 16:14:18 +01:00
|
|
|
#endif
|
2005-11-15 19:15:56 +01:00
|
|
|
|
2012-04-09 21:04:23 +02:00
|
|
|
#elif defined(__NetBSD__)
|
2009-01-16 22:39:21 +01:00
|
|
|
|
|
|
|
#define EAX_sig(context) ((context)->uc_mcontext.__gregs[_REG_EAX])
|
|
|
|
#define EBX_sig(context) ((context)->uc_mcontext.__gregs[_REG_EBX])
|
|
|
|
#define ECX_sig(context) ((context)->uc_mcontext.__gregs[_REG_ECX])
|
|
|
|
#define EDX_sig(context) ((context)->uc_mcontext.__gregs[_REG_EDX])
|
|
|
|
#define ESI_sig(context) ((context)->uc_mcontext.__gregs[_REG_ESI])
|
|
|
|
#define EDI_sig(context) ((context)->uc_mcontext.__gregs[_REG_EDI])
|
|
|
|
#define EBP_sig(context) ((context)->uc_mcontext.__gregs[_REG_EBP])
|
|
|
|
#define ESP_sig(context) _UC_MACHINE_SP(context)
|
|
|
|
|
|
|
|
#define CS_sig(context) ((context)->uc_mcontext.__gregs[_REG_CS])
|
|
|
|
#define DS_sig(context) ((context)->uc_mcontext.__gregs[_REG_DS])
|
|
|
|
#define ES_sig(context) ((context)->uc_mcontext.__gregs[_REG_ES])
|
|
|
|
#define SS_sig(context) ((context)->uc_mcontext.__gregs[_REG_SS])
|
|
|
|
#define FS_sig(context) ((context)->uc_mcontext.__gregs[_REG_FS])
|
|
|
|
#define GS_sig(context) ((context)->uc_mcontext.__gregs[_REG_GS])
|
|
|
|
|
|
|
|
#define EFL_sig(context) ((context)->uc_mcontext.__gregs[_REG_EFL])
|
|
|
|
#define EIP_sig(context) _UC_MACHINE_PC(context)
|
|
|
|
#define TRAP_sig(context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
|
|
|
|
#define ERROR_sig(context) ((context)->uc_mcontext.__gregs[_REG_ERR])
|
|
|
|
|
|
|
|
#define FPU_sig(context) NULL
|
|
|
|
#define FPUX_sig(context) ((XMM_SAVE_AREA32 *)&((context)->uc_mcontext.__fpregs))
|
|
|
|
|
|
|
|
#define T_MCHK T_MCA
|
|
|
|
#define T_XMMFLT T_XMM
|
|
|
|
|
2014-01-06 02:32:43 +01:00
|
|
|
#elif defined(__GNU__)
|
|
|
|
|
|
|
|
#define EAX_sig(context) ((context)->uc_mcontext.gregs[REG_EAX])
|
|
|
|
#define EBX_sig(context) ((context)->uc_mcontext.gregs[REG_EBX])
|
|
|
|
#define ECX_sig(context) ((context)->uc_mcontext.gregs[REG_ECX])
|
|
|
|
#define EDX_sig(context) ((context)->uc_mcontext.gregs[REG_EDX])
|
|
|
|
#define ESI_sig(context) ((context)->uc_mcontext.gregs[REG_ESI])
|
|
|
|
#define EDI_sig(context) ((context)->uc_mcontext.gregs[REG_EDI])
|
|
|
|
#define EBP_sig(context) ((context)->uc_mcontext.gregs[REG_EBP])
|
|
|
|
#define ESP_sig(context) ((context)->uc_mcontext.gregs[REG_ESP])
|
|
|
|
|
|
|
|
#define CS_sig(context) ((context)->uc_mcontext.gregs[REG_CS])
|
|
|
|
#define DS_sig(context) ((context)->uc_mcontext.gregs[REG_DS])
|
|
|
|
#define ES_sig(context) ((context)->uc_mcontext.gregs[REG_ES])
|
|
|
|
#define SS_sig(context) ((context)->uc_mcontext.gregs[REG_SS])
|
|
|
|
#define FS_sig(context) ((context)->uc_mcontext.gregs[REG_FS])
|
|
|
|
#define GS_sig(context) ((context)->uc_mcontext.gregs[REG_GS])
|
|
|
|
|
|
|
|
#define EFL_sig(context) ((context)->uc_mcontext.gregs[REG_EFL])
|
|
|
|
#define EIP_sig(context) ((context)->uc_mcontext.gregs[REG_EIP])
|
|
|
|
#define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO])
|
|
|
|
#define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR])
|
|
|
|
|
|
|
|
#define FPU_sig(context) ((FLOATING_SAVE_AREA *)&(context)->uc_mcontext.fpregs.fp_reg_set.fpchip_state)
|
|
|
|
#define FPUX_sig(context) NULL
|
|
|
|
|
2012-04-09 21:04:23 +02:00
|
|
|
#else
|
|
|
|
#error You must define the signal context functions for your platform
|
|
|
|
#endif /* linux */
|
2009-01-16 22:39:21 +01:00
|
|
|
|
2019-09-12 19:20:14 +02:00
|
|
|
/* stack layout when calling an exception raise function */
|
|
|
|
struct stack_layout
|
|
|
|
{
|
2019-09-12 21:02:29 +02:00
|
|
|
void *ret_addr; /* return address from raise_generic_exception */
|
|
|
|
EXCEPTION_RECORD *rec_ptr; /* first arg for raise_generic_exception */
|
|
|
|
CONTEXT *context_ptr; /* second arg for raise_generic_exception */
|
2019-09-12 19:20:14 +02:00
|
|
|
CONTEXT context;
|
|
|
|
EXCEPTION_RECORD rec;
|
|
|
|
DWORD ebp;
|
|
|
|
DWORD eip;
|
|
|
|
};
|
|
|
|
|
2002-08-09 03:07:29 +02:00
|
|
|
typedef int (*wine_signal_handler)(unsigned int sig);
|
2002-07-31 20:46:09 +02:00
|
|
|
|
2009-02-18 13:04:50 +01:00
|
|
|
static const size_t teb_size = 4096; /* we reserve one page for the TEB */
|
2005-09-14 12:36:58 +02:00
|
|
|
static size_t signal_stack_mask;
|
|
|
|
static size_t signal_stack_size;
|
|
|
|
|
2002-07-31 20:46:09 +02:00
|
|
|
static wine_signal_handler handlers[256];
|
|
|
|
|
2006-02-03 12:30:55 +01:00
|
|
|
enum i386_trap_code
|
|
|
|
{
|
|
|
|
TRAP_x86_UNKNOWN = -1, /* Unknown fault (TRAP_sig not defined) */
|
2012-06-02 18:53:57 +02:00
|
|
|
#if defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
2006-08-05 22:34:11 +02:00
|
|
|
TRAP_x86_DIVIDE = T_DIVIDE, /* Division by zero exception */
|
|
|
|
TRAP_x86_TRCTRAP = T_TRCTRAP, /* Single-step exception */
|
|
|
|
TRAP_x86_NMI = T_NMI, /* NMI interrupt */
|
|
|
|
TRAP_x86_BPTFLT = T_BPTFLT, /* Breakpoint exception */
|
|
|
|
TRAP_x86_OFLOW = T_OFLOW, /* Overflow exception */
|
|
|
|
TRAP_x86_BOUND = T_BOUND, /* Bound range exception */
|
|
|
|
TRAP_x86_PRIVINFLT = T_PRIVINFLT, /* Invalid opcode exception */
|
|
|
|
TRAP_x86_DNA = T_DNA, /* Device not available exception */
|
|
|
|
TRAP_x86_DOUBLEFLT = T_DOUBLEFLT, /* Double fault exception */
|
|
|
|
TRAP_x86_FPOPFLT = T_FPOPFLT, /* Coprocessor segment overrun */
|
|
|
|
TRAP_x86_TSSFLT = T_TSSFLT, /* Invalid TSS exception */
|
|
|
|
TRAP_x86_SEGNPFLT = T_SEGNPFLT, /* Segment not present exception */
|
|
|
|
TRAP_x86_STKFLT = T_STKFLT, /* Stack fault */
|
|
|
|
TRAP_x86_PROTFLT = T_PROTFLT, /* General protection fault */
|
|
|
|
TRAP_x86_PAGEFLT = T_PAGEFLT, /* Page fault */
|
|
|
|
TRAP_x86_ARITHTRAP = T_ARITHTRAP, /* Floating point exception */
|
|
|
|
TRAP_x86_ALIGNFLT = T_ALIGNFLT, /* Alignment check exception */
|
|
|
|
TRAP_x86_MCHK = T_MCHK, /* Machine check exception */
|
|
|
|
TRAP_x86_CACHEFLT = T_XMMFLT /* Cache flush exception */
|
|
|
|
#else
|
2006-02-03 12:30:55 +01:00
|
|
|
TRAP_x86_DIVIDE = 0, /* Division by zero exception */
|
|
|
|
TRAP_x86_TRCTRAP = 1, /* Single-step exception */
|
|
|
|
TRAP_x86_NMI = 2, /* NMI interrupt */
|
|
|
|
TRAP_x86_BPTFLT = 3, /* Breakpoint exception */
|
|
|
|
TRAP_x86_OFLOW = 4, /* Overflow exception */
|
|
|
|
TRAP_x86_BOUND = 5, /* Bound range exception */
|
|
|
|
TRAP_x86_PRIVINFLT = 6, /* Invalid opcode exception */
|
|
|
|
TRAP_x86_DNA = 7, /* Device not available exception */
|
|
|
|
TRAP_x86_DOUBLEFLT = 8, /* Double fault exception */
|
|
|
|
TRAP_x86_FPOPFLT = 9, /* Coprocessor segment overrun */
|
|
|
|
TRAP_x86_TSSFLT = 10, /* Invalid TSS exception */
|
|
|
|
TRAP_x86_SEGNPFLT = 11, /* Segment not present exception */
|
|
|
|
TRAP_x86_STKFLT = 12, /* Stack fault */
|
|
|
|
TRAP_x86_PROTFLT = 13, /* General protection fault */
|
|
|
|
TRAP_x86_PAGEFLT = 14, /* Page fault */
|
|
|
|
TRAP_x86_ARITHTRAP = 16, /* Floating point exception */
|
|
|
|
TRAP_x86_ALIGNFLT = 17, /* Alignment check exception */
|
|
|
|
TRAP_x86_MCHK = 18, /* Machine check exception */
|
2007-03-08 22:48:14 +01:00
|
|
|
TRAP_x86_CACHEFLT = 19 /* SIMD exception (via SIGFPE) if CPU is SSE capable
|
|
|
|
otherwise Cache flush exception (via SIGSEV) */
|
2006-08-05 22:34:11 +02:00
|
|
|
#endif
|
2006-02-03 12:30:55 +01:00
|
|
|
};
|
|
|
|
|
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 */
|
|
|
|
/* the ntdll_thread_data structure follows here */
|
2017-07-19 15:14:24 +02:00
|
|
|
};
|
|
|
|
|
2017-07-19 15:20:42 +02:00
|
|
|
C_ASSERT( offsetof( TEB, SystemReserved2 ) + offsetof( struct x86_thread_data, gs ) == 0x1d8 );
|
2017-12-15 12:36:16 +01:00
|
|
|
C_ASSERT( offsetof( TEB, SystemReserved2 ) + 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)
|
|
|
|
{
|
2017-07-19 15:20:42 +02:00
|
|
|
return (struct x86_thread_data *)NtCurrentTeb()->SystemReserved2;
|
2017-07-19 15:14:24 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2002-07-31 20:46:09 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* dispatch_signal
|
|
|
|
*/
|
2007-03-17 11:28:32 +01:00
|
|
|
static inline int dispatch_signal(unsigned int sig)
|
2002-07-31 20:46:09 +02:00
|
|
|
{
|
|
|
|
if (handlers[sig] == NULL) return 0;
|
|
|
|
return handlers[sig](sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-28 15:15:27 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_trap_code
|
|
|
|
*
|
|
|
|
* Get the trap code for a signal.
|
|
|
|
*/
|
2014-07-23 16:32:33 +02:00
|
|
|
static inline enum i386_trap_code get_trap_code( const ucontext_t *sigcontext )
|
1999-09-28 15:15:27 +02:00
|
|
|
{
|
|
|
|
#ifdef TRAP_sig
|
|
|
|
return TRAP_sig(sigcontext);
|
|
|
|
#else
|
2006-02-03 12:30:55 +01:00
|
|
|
return TRAP_x86_UNKNOWN; /* unknown trap code */
|
1999-09-28 15:15:27 +02:00
|
|
|
#endif
|
|
|
|
}
|
1999-09-27 12:58:45 +02:00
|
|
|
|
2000-09-18 04:15:07 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_error_code
|
|
|
|
*
|
|
|
|
* Get the error code for a signal.
|
|
|
|
*/
|
2014-07-23 16:32:33 +02:00
|
|
|
static inline WORD get_error_code( const ucontext_t *sigcontext )
|
2000-09-18 04:15:07 +02:00
|
|
|
{
|
|
|
|
#ifdef ERROR_sig
|
|
|
|
return ERROR_sig(sigcontext);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-10-31 00:15:56 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* get_signal_stack
|
|
|
|
*
|
|
|
|
* Get the base of the signal stack for the current thread.
|
|
|
|
*/
|
|
|
|
static inline void *get_signal_stack(void)
|
|
|
|
{
|
2003-11-04 05:50:18 +01:00
|
|
|
return (char *)NtCurrentTeb() + 4096;
|
2003-10-31 00:15:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 19:46:16 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* has_fpux
|
|
|
|
*/
|
|
|
|
static inline int has_fpux(void)
|
|
|
|
{
|
|
|
|
return (cpu_info.FeatureSet & CPU_FEATURE_FXSR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-05 01:52:29 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* get_current_teb
|
|
|
|
*
|
|
|
|
* Get the current teb based on the stack pointer.
|
|
|
|
*/
|
|
|
|
static inline TEB *get_current_teb(void)
|
|
|
|
{
|
|
|
|
unsigned long esp;
|
|
|
|
__asm__("movl %%esp,%0" : "=g" (esp) );
|
2005-09-14 12:36:58 +02:00
|
|
|
return (TEB *)(esp & ~signal_stack_mask);
|
2003-11-05 01:52:29 +01: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* 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=%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] );
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fix up instruction pointer in context for EXCEPTION_BREAKPOINT */
|
|
|
|
if (rec->ExceptionCode == EXCEPTION_BREAKPOINT) context->Eip--;
|
|
|
|
|
2019-09-18 18:09:11 +02:00
|
|
|
if (call_vectored_handlers( rec, context ) == EXCEPTION_CONTINUE_EXECUTION) goto done;
|
2009-04-30 13:08:32 +02:00
|
|
|
|
2019-09-18 18:09:11 +02:00
|
|
|
if ((status = call_stack_handlers( rec, context )) == STATUS_SUCCESS) goto done;
|
|
|
|
if (status != STATUS_UNHANDLED_EXCEPTION) return status;
|
2009-04-30 13:08:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* last chance exception */
|
|
|
|
|
|
|
|
status = send_debug_event( rec, FALSE, context );
|
|
|
|
if (status != DBG_CONTINUE)
|
|
|
|
{
|
|
|
|
if (rec->ExceptionFlags & EH_STACK_INVALID)
|
|
|
|
WINE_ERR("Exception frame is not in stack limits => unable to dispatch exception.\n");
|
|
|
|
else if (rec->ExceptionCode == STATUS_NONCONTINUABLE_EXCEPTION)
|
|
|
|
WINE_ERR("Process attempted to continue execution after noncontinuable exception.\n");
|
|
|
|
else
|
|
|
|
WINE_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
|
|
|
}
|
2019-09-18 18:09:11 +02:00
|
|
|
done:
|
|
|
|
return NtSetContextThread( GetCurrentThread(), context );
|
2009-04-30 13:08:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-10 18:18:16 +02:00
|
|
|
#ifdef __sun
|
|
|
|
|
|
|
|
/* We have to workaround two Solaris breakages:
|
|
|
|
* - Solaris doesn't restore %ds and %es before calling the signal handler so exceptions in 16-bit
|
|
|
|
* code crash badly.
|
|
|
|
* - Solaris inserts a libc trampoline to call our handler, but the trampoline expects that registers
|
|
|
|
* are setup correctly. So we need to insert our own trampoline below the libc trampoline to set %gs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern int sigaction_syscall( int sig, const struct sigaction *new, struct sigaction *old );
|
|
|
|
__ASM_GLOBAL_FUNC( sigaction_syscall,
|
|
|
|
"movl $0x62,%eax\n\t"
|
2008-07-29 20:41:30 +02:00
|
|
|
"int $0x91\n\t"
|
|
|
|
"ret" )
|
2008-07-10 18:18:16 +02:00
|
|
|
|
|
|
|
/* assume the same libc handler is used for all signals */
|
|
|
|
static void (*libc_sigacthandler)( int signal, siginfo_t *siginfo, void *context );
|
|
|
|
|
|
|
|
static void wine_sigacthandler( int signal, siginfo_t *siginfo, void *sigcontext )
|
|
|
|
{
|
2017-07-19 15:14:24 +02:00
|
|
|
struct x86_thread_data *thread_data;
|
2008-07-10 18:18:16 +02:00
|
|
|
|
|
|
|
__asm__ __volatile__("mov %ss,%ax; mov %ax,%ds; mov %ax,%es");
|
|
|
|
|
2017-07-19 15:14:24 +02:00
|
|
|
thread_data = (struct x86_thread_data *)get_current_teb()->SystemReserved2;
|
2008-07-10 18:18:16 +02:00
|
|
|
wine_set_fs( thread_data->fs );
|
|
|
|
wine_set_gs( thread_data->gs );
|
|
|
|
|
|
|
|
libc_sigacthandler( signal, siginfo, sigcontext );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int solaris_sigaction( int sig, const struct sigaction *new, struct sigaction *old )
|
|
|
|
{
|
|
|
|
struct sigaction real_act;
|
|
|
|
|
|
|
|
if (sigaction( sig, new, old ) == -1) return -1;
|
|
|
|
|
|
|
|
/* retrieve the real handler and flags with a direct syscall */
|
|
|
|
sigaction_syscall( sig, NULL, &real_act );
|
|
|
|
libc_sigacthandler = real_act.sa_sigaction;
|
|
|
|
real_act.sa_sigaction = wine_sigacthandler;
|
|
|
|
sigaction_syscall( sig, &real_act, NULL );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#define sigaction(sig,new,old) solaris_sigaction(sig,new,old)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-04-19 22:36:22 +02:00
|
|
|
extern void clear_alignment_flag(void);
|
|
|
|
__ASM_GLOBAL_FUNC( clear_alignment_flag,
|
|
|
|
"pushfl\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
"andl $~0x40000,(%esp)\n\t"
|
|
|
|
"popfl\n\t"
|
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
|
|
|
|
"ret" )
|
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
|
2003-03-04 23:18:43 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* init_handler
|
|
|
|
*
|
|
|
|
* Handler initialization when the full context is not needed.
|
2008-07-08 20:54:40 +02:00
|
|
|
* Return the stack pointer to use for pushing the exception data.
|
2003-03-04 23:18:43 +01:00
|
|
|
*/
|
2014-07-23 16:32:33 +02:00
|
|
|
static inline void *init_handler( const ucontext_t *sigcontext, WORD *fs, WORD *gs )
|
2003-03-04 23:18:43 +01:00
|
|
|
{
|
2003-11-05 01:52:29 +01:00
|
|
|
TEB *teb = get_current_teb();
|
2003-10-31 00:15:56 +01:00
|
|
|
|
2010-04-19 22:36:22 +02:00
|
|
|
clear_alignment_flag();
|
|
|
|
|
2005-11-02 21:54:12 +01:00
|
|
|
/* get %fs and %gs at time of the fault */
|
|
|
|
#ifdef FS_sig
|
|
|
|
*fs = LOWORD(FS_sig(sigcontext));
|
|
|
|
#else
|
|
|
|
*fs = wine_get_fs();
|
|
|
|
#endif
|
|
|
|
#ifdef GS_sig
|
|
|
|
*gs = LOWORD(GS_sig(sigcontext));
|
|
|
|
#else
|
|
|
|
*gs = wine_get_gs();
|
|
|
|
#endif
|
|
|
|
|
2008-07-10 18:18:16 +02:00
|
|
|
#ifndef __sun /* see above for Solaris handling */
|
2009-03-05 14:40:16 +01:00
|
|
|
{
|
2017-07-19 15:14:24 +02:00
|
|
|
struct x86_thread_data *thread_data = (struct x86_thread_data *)teb->SystemReserved2;
|
2009-03-05 14:40:16 +01:00
|
|
|
wine_set_fs( thread_data->fs );
|
|
|
|
wine_set_gs( thread_data->gs );
|
|
|
|
}
|
2008-07-10 18:18:16 +02:00
|
|
|
#endif
|
2003-11-05 01:52:29 +01:00
|
|
|
|
2003-11-17 21:12:56 +01:00
|
|
|
if (!wine_ldt_is_system(CS_sig(sigcontext)) ||
|
|
|
|
!wine_ldt_is_system(SS_sig(sigcontext))) /* 16-bit mode */
|
2003-03-04 23:18:43 +01:00
|
|
|
{
|
2003-10-31 00:15:56 +01:00
|
|
|
/*
|
|
|
|
* Win16 or DOS protected mode. Note that during switch
|
|
|
|
* from 16-bit mode to linear mode, CS may be set to system
|
|
|
|
* segment before FS is restored. Fortunately, in this case
|
|
|
|
* SS is still non-system segment. This is why both CS and SS
|
|
|
|
* are checked.
|
|
|
|
*/
|
2008-07-08 20:54:40 +02:00
|
|
|
return teb->WOW32Reserved;
|
2003-03-04 23:18:43 +01:00
|
|
|
}
|
2008-07-08 20:54:40 +02:00
|
|
|
return (void *)(ESP_sig(sigcontext) & ~3);
|
2003-03-04 23:18:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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 */
|
|
|
|
char buffer[sizeof(XMM_SAVE_AREA32) + 16];
|
|
|
|
XMM_SAVE_AREA32 *state = (XMM_SAVE_AREA32 *)(((ULONG_PTR)buffer + 15) & ~15);
|
|
|
|
|
|
|
|
if (!has_fpux()) return;
|
|
|
|
context->ContextFlags |= CONTEXT_EXTENDED_REGISTERS;
|
|
|
|
__asm__ __volatile__( "fxsave %0" : "=m" (*state) );
|
|
|
|
memcpy( context->ExtendedRegisters, state, sizeof(*state) );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* restore_fpu
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
* Restore the FPU context to a sigcontext.
|
1999-09-27 12:58:45 +02:00
|
|
|
*/
|
2007-03-17 11:28:32 +01:00
|
|
|
static inline void restore_fpu( const CONTEXT *context )
|
1999-09-27 12:58:45 +02:00
|
|
|
{
|
2006-01-11 20:20:32 +01:00
|
|
|
FLOATING_SAVE_AREA float_status = context->FloatSave;
|
2000-06-23 18:49:09 +02:00
|
|
|
/* reset the current interrupt status */
|
2006-01-11 20:20:32 +01:00
|
|
|
float_status.StatusWord &= float_status.ControlWord | 0xffffff80;
|
1999-09-27 12:58:45 +02:00
|
|
|
#ifdef __GNUC__
|
2006-01-11 20:20:32 +01:00
|
|
|
__asm__ __volatile__( "frstor %0; fwait" : : "m" (float_status) );
|
1999-09-27 12:58:45 +02:00
|
|
|
#endif /* __GNUC__ */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-15 18:08:29 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* restore_fpux
|
|
|
|
*
|
|
|
|
* Restore the FPU extended context to a sigcontext.
|
|
|
|
*/
|
|
|
|
static inline void restore_fpux( const CONTEXT *context )
|
|
|
|
{
|
|
|
|
#ifdef __GNUC__
|
|
|
|
/* we have to enforce alignment by hand */
|
|
|
|
char buffer[sizeof(XMM_SAVE_AREA32) + 16];
|
|
|
|
XMM_SAVE_AREA32 *state = (XMM_SAVE_AREA32 *)(((ULONG_PTR)buffer + 15) & ~15);
|
|
|
|
|
|
|
|
memcpy( state, context->ExtendedRegisters, sizeof(*state) );
|
|
|
|
/* reset the current interrupt status */
|
|
|
|
state->StatusWord &= state->ControlWord | 0xff80;
|
|
|
|
__asm__ __volatile__( "fxrstor %0" : : "m" (*state) );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-15 20:27:14 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fpux_to_fpu
|
|
|
|
*
|
|
|
|
* Build a standard FPU context from an extended one.
|
|
|
|
*/
|
|
|
|
static void fpux_to_fpu( FLOATING_SAVE_AREA *fpu, const XMM_SAVE_AREA32 *fpux )
|
|
|
|
{
|
|
|
|
unsigned int i, tag, stack_top;
|
|
|
|
|
|
|
|
fpu->ControlWord = fpux->ControlWord | 0xffff0000;
|
|
|
|
fpu->StatusWord = fpux->StatusWord | 0xffff0000;
|
|
|
|
fpu->ErrorOffset = fpux->ErrorOffset;
|
|
|
|
fpu->ErrorSelector = fpux->ErrorSelector | (fpux->ErrorOpcode << 16);
|
|
|
|
fpu->DataOffset = fpux->DataOffset;
|
|
|
|
fpu->DataSelector = fpux->DataSelector;
|
|
|
|
fpu->Cr0NpxState = fpux->StatusWord | 0xffff0000;
|
|
|
|
|
|
|
|
stack_top = (fpux->StatusWord >> 11) & 7;
|
|
|
|
fpu->TagWord = 0xffff0000;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
memcpy( &fpu->RegisterArea[10 * i], &fpux->FloatRegisters[i], 10 );
|
|
|
|
if (!(fpux->TagWord & (1 << i))) tag = 3; /* empty */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const M128A *reg = &fpux->FloatRegisters[(i - stack_top) & 7];
|
|
|
|
if ((reg->High & 0x7fff) == 0x7fff) /* exponent all ones */
|
|
|
|
{
|
|
|
|
tag = 2; /* special */
|
|
|
|
}
|
|
|
|
else if (!(reg->High & 0x7fff)) /* exponent all zeroes */
|
|
|
|
{
|
|
|
|
if (reg->Low) tag = 2; /* special */
|
|
|
|
else tag = 1; /* zero */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (reg->Low >> 63) tag = 0; /* valid */
|
|
|
|
else tag = 2; /* special */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fpu->TagWord |= tag << (2 * i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-02 21:54:12 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* save_context
|
|
|
|
*
|
|
|
|
* Build a context structure from the signal info.
|
|
|
|
*/
|
2014-07-23 16:32:33 +02:00
|
|
|
static inline void save_context( CONTEXT *context, const ucontext_t *sigcontext, WORD fs, WORD gs )
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2008-01-15 18:08:29 +01:00
|
|
|
FLOATING_SAVE_AREA *fpu = FPU_sig(sigcontext);
|
|
|
|
XMM_SAVE_AREA32 *fpux = FPUX_sig(sigcontext);
|
2006-01-13 13:58:14 +01:00
|
|
|
|
2006-01-27 16:17:51 +01:00
|
|
|
memset(context, 0, sizeof(*context));
|
2006-01-13 13:58:14 +01:00
|
|
|
context->ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
|
2005-11-02 21:54:12 +01:00
|
|
|
context->Eax = EAX_sig(sigcontext);
|
|
|
|
context->Ebx = EBX_sig(sigcontext);
|
|
|
|
context->Ecx = ECX_sig(sigcontext);
|
|
|
|
context->Edx = EDX_sig(sigcontext);
|
|
|
|
context->Esi = ESI_sig(sigcontext);
|
|
|
|
context->Edi = EDI_sig(sigcontext);
|
|
|
|
context->Ebp = EBP_sig(sigcontext);
|
|
|
|
context->EFlags = EFL_sig(sigcontext);
|
|
|
|
context->Eip = EIP_sig(sigcontext);
|
|
|
|
context->Esp = ESP_sig(sigcontext);
|
|
|
|
context->SegCs = LOWORD(CS_sig(sigcontext));
|
|
|
|
context->SegDs = LOWORD(DS_sig(sigcontext));
|
|
|
|
context->SegEs = LOWORD(ES_sig(sigcontext));
|
|
|
|
context->SegFs = fs;
|
|
|
|
context->SegGs = gs;
|
|
|
|
context->SegSs = LOWORD(SS_sig(sigcontext));
|
2017-07-19 15:14:24 +02:00
|
|
|
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;
|
2006-04-03 21:39:33 +02:00
|
|
|
|
2008-01-15 18:08:29 +01:00
|
|
|
if (fpu)
|
2006-04-03 21:39:33 +02:00
|
|
|
{
|
|
|
|
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
2008-01-15 18:08:29 +01:00
|
|
|
context->FloatSave = *fpu;
|
2006-04-03 21:39:33 +02:00
|
|
|
}
|
2008-01-15 18:08:29 +01:00
|
|
|
if (fpux)
|
2006-04-03 21:39:33 +02:00
|
|
|
{
|
2008-01-15 20:27:14 +01:00
|
|
|
context->ContextFlags |= CONTEXT_FLOATING_POINT | CONTEXT_EXTENDED_REGISTERS;
|
2008-01-15 18:08:29 +01:00
|
|
|
memcpy( context->ExtendedRegisters, fpux, sizeof(*fpux) );
|
2008-01-15 20:27:14 +01:00
|
|
|
if (!fpu) fpux_to_fpu( &context->FloatSave, fpux );
|
2006-04-03 21:39:33 +02:00
|
|
|
}
|
2008-01-15 18:08:29 +01:00
|
|
|
if (!fpu && !fpux) save_fpu( context );
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* restore_context
|
|
|
|
*
|
|
|
|
* Restore the signal info from the context.
|
|
|
|
*/
|
2014-07-23 16:32:33 +02:00
|
|
|
static inline void restore_context( const CONTEXT *context, ucontext_t *sigcontext )
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2008-01-15 18:08:29 +01:00
|
|
|
FLOATING_SAVE_AREA *fpu = FPU_sig(sigcontext);
|
|
|
|
XMM_SAVE_AREA32 *fpux = FPUX_sig(sigcontext);
|
2006-01-13 13:58:14 +01:00
|
|
|
|
2017-07-19 15:14:24 +02:00
|
|
|
x86_thread_data()->dr0 = context->Dr0;
|
|
|
|
x86_thread_data()->dr1 = context->Dr1;
|
|
|
|
x86_thread_data()->dr2 = context->Dr2;
|
|
|
|
x86_thread_data()->dr3 = context->Dr3;
|
|
|
|
x86_thread_data()->dr6 = context->Dr6;
|
|
|
|
x86_thread_data()->dr7 = context->Dr7;
|
2005-11-02 21:54:12 +01:00
|
|
|
EAX_sig(sigcontext) = context->Eax;
|
|
|
|
EBX_sig(sigcontext) = context->Ebx;
|
|
|
|
ECX_sig(sigcontext) = context->Ecx;
|
|
|
|
EDX_sig(sigcontext) = context->Edx;
|
|
|
|
ESI_sig(sigcontext) = context->Esi;
|
|
|
|
EDI_sig(sigcontext) = context->Edi;
|
|
|
|
EBP_sig(sigcontext) = context->Ebp;
|
|
|
|
EFL_sig(sigcontext) = context->EFlags;
|
|
|
|
EIP_sig(sigcontext) = context->Eip;
|
|
|
|
ESP_sig(sigcontext) = context->Esp;
|
|
|
|
CS_sig(sigcontext) = context->SegCs;
|
|
|
|
DS_sig(sigcontext) = context->SegDs;
|
|
|
|
ES_sig(sigcontext) = context->SegEs;
|
|
|
|
SS_sig(sigcontext) = context->SegSs;
|
|
|
|
#ifdef GS_sig
|
|
|
|
GS_sig(sigcontext) = context->SegGs;
|
|
|
|
#else
|
|
|
|
wine_set_gs( context->SegGs );
|
|
|
|
#endif
|
|
|
|
#ifdef FS_sig
|
|
|
|
FS_sig(sigcontext) = context->SegFs;
|
|
|
|
#else
|
|
|
|
wine_set_fs( context->SegFs );
|
|
|
|
#endif
|
2006-04-03 21:39:33 +02:00
|
|
|
|
2008-01-15 18:08:29 +01:00
|
|
|
if (fpu) *fpu = context->FloatSave;
|
|
|
|
if (fpux) memcpy( fpux, context->ExtendedRegisters, sizeof(*fpux) );
|
|
|
|
if (!fpu && !fpux) restore_fpu( context );
|
2005-11-02 21:54:12 +01: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
|
|
|
*/
|
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
|
|
|
|
2017-07-26 10:22:05 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* set_full_cpu_context
|
|
|
|
*
|
|
|
|
* Set the new CPU context.
|
|
|
|
*/
|
|
|
|
extern void set_full_cpu_context( const CONTEXT *context );
|
|
|
|
__ASM_GLOBAL_FUNC( set_full_cpu_context,
|
|
|
|
"movl 4(%esp),%ecx\n\t"
|
|
|
|
"movw 0x8c(%ecx),%gs\n\t" /* SegGs */
|
|
|
|
"movw 0x90(%ecx),%fs\n\t" /* SegFs */
|
|
|
|
"movw 0x94(%ecx),%es\n\t" /* SegEs */
|
|
|
|
"movl 0x9c(%ecx),%edi\n\t" /* Edi */
|
|
|
|
"movl 0xa0(%ecx),%esi\n\t" /* Esi */
|
|
|
|
"movl 0xa4(%ecx),%ebx\n\t" /* Ebx */
|
|
|
|
"movl 0xb4(%ecx),%ebp\n\t" /* Ebp */
|
|
|
|
"movw %ss,%ax\n\t"
|
|
|
|
"cmpw 0xc8(%ecx),%ax\n\t" /* SegSs */
|
|
|
|
"jne 1f\n\t"
|
|
|
|
/* As soon as we have switched stacks the context structure could
|
|
|
|
* be invalid (when signal handlers are executed for example). Copy
|
|
|
|
* values on the target stack before changing ESP. */
|
|
|
|
"movl 0xc4(%ecx),%eax\n\t" /* Esp */
|
|
|
|
"leal -4*4(%eax),%eax\n\t"
|
|
|
|
"movl 0xc0(%ecx),%edx\n\t" /* EFlags */
|
|
|
|
"movl %edx,3*4(%eax)\n\t"
|
|
|
|
"movl 0xbc(%ecx),%edx\n\t" /* SegCs */
|
|
|
|
"movl %edx,2*4(%eax)\n\t"
|
|
|
|
"movl 0xb8(%ecx),%edx\n\t" /* Eip */
|
|
|
|
"movl %edx,1*4(%eax)\n\t"
|
|
|
|
"movl 0xb0(%ecx),%edx\n\t" /* Eax */
|
|
|
|
"movl %edx,0*4(%eax)\n\t"
|
|
|
|
"pushl 0x98(%ecx)\n\t" /* SegDs */
|
|
|
|
"movl 0xa8(%ecx),%edx\n\t" /* Edx */
|
|
|
|
"movl 0xac(%ecx),%ecx\n\t" /* Ecx */
|
|
|
|
"popl %ds\n\t"
|
|
|
|
"movl %eax,%esp\n\t"
|
|
|
|
"popl %eax\n\t"
|
|
|
|
"iret\n"
|
|
|
|
/* Restore the context when the stack segment changes. We can't use
|
|
|
|
* the same code as above because we do not know if the stack segment
|
|
|
|
* is 16 or 32 bit, and 'movl' will throw an exception when we try to
|
|
|
|
* access memory above the limit. */
|
|
|
|
"1:\n\t"
|
|
|
|
"movl 0xa8(%ecx),%edx\n\t" /* Edx */
|
|
|
|
"movl 0xb0(%ecx),%eax\n\t" /* Eax */
|
|
|
|
"movw 0xc8(%ecx),%ss\n\t" /* SegSs */
|
|
|
|
"movl 0xc4(%ecx),%esp\n\t" /* Esp */
|
|
|
|
"pushl 0xc0(%ecx)\n\t" /* EFlags */
|
|
|
|
"pushl 0xbc(%ecx)\n\t" /* SegCs */
|
|
|
|
"pushl 0xb8(%ecx)\n\t" /* Eip */
|
|
|
|
"pushl 0x98(%ecx)\n\t" /* SegDs */
|
|
|
|
"movl 0xac(%ecx),%ecx\n\t" /* Ecx */
|
|
|
|
"popl %ds\n\t"
|
|
|
|
"iret" )
|
|
|
|
|
2006-04-20 15:40:28 +02:00
|
|
|
|
2005-12-19 09:59:50 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* set_cpu_context
|
|
|
|
*
|
2006-01-13 13:58:14 +01:00
|
|
|
* Set the new CPU context. Used by NtSetContextThread.
|
2005-12-19 09:59:50 +01:00
|
|
|
*/
|
2017-12-04 13:56:32 +01:00
|
|
|
void DECLSPEC_HIDDEN set_cpu_context( const CONTEXT *context )
|
2005-12-19 09:59:50 +01:00
|
|
|
{
|
|
|
|
DWORD flags = context->ContextFlags & ~CONTEXT_i386;
|
|
|
|
|
2019-02-14 19:46:16 +01:00
|
|
|
if ((flags & CONTEXT_EXTENDED_REGISTERS) && has_fpux()) restore_fpux( context );
|
2008-01-15 18:08:29 +01:00
|
|
|
else if (flags & CONTEXT_FLOATING_POINT) restore_fpu( context );
|
2006-01-11 20:20:32 +01:00
|
|
|
|
2006-01-13 13:58:14 +01:00
|
|
|
if (flags & CONTEXT_DEBUG_REGISTERS)
|
|
|
|
{
|
2017-07-19 15:14:24 +02:00
|
|
|
x86_thread_data()->dr0 = context->Dr0;
|
|
|
|
x86_thread_data()->dr1 = context->Dr1;
|
|
|
|
x86_thread_data()->dr2 = context->Dr2;
|
|
|
|
x86_thread_data()->dr3 = context->Dr3;
|
|
|
|
x86_thread_data()->dr6 = context->Dr6;
|
|
|
|
x86_thread_data()->dr7 = context->Dr7;
|
2006-01-13 13:58:14 +01:00
|
|
|
}
|
2006-01-11 20:20:32 +01:00
|
|
|
if (flags & CONTEXT_FULL)
|
|
|
|
{
|
2007-05-08 20:09:25 +02:00
|
|
|
if (!(flags & CONTEXT_CONTROL))
|
2006-10-16 13:49:06 +02:00
|
|
|
FIXME( "setting partial context (%x) not supported\n", flags );
|
2007-05-08 20:09:25 +02:00
|
|
|
else if (flags & CONTEXT_SEGMENTS)
|
2017-07-26 10:22:05 +02:00
|
|
|
set_full_cpu_context( context );
|
2007-05-08 20:09:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CONTEXT newcontext = *context;
|
|
|
|
newcontext.SegDs = wine_get_ds();
|
|
|
|
newcontext.SegEs = wine_get_es();
|
|
|
|
newcontext.SegFs = wine_get_fs();
|
|
|
|
newcontext.SegGs = wine_get_gs();
|
2017-07-26 10:22:05 +02:00
|
|
|
set_full_cpu_context( &newcontext );
|
2007-05-08 20:09:25 +02:00
|
|
|
}
|
2006-01-11 20:20:32 +01:00
|
|
|
}
|
2005-12-19 09:59:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
flags &= ~CONTEXT_i386; /* get rid of CPU id */
|
|
|
|
if (flags & CONTEXT_CONTROL) ret |= SERVER_CTX_CONTROL;
|
|
|
|
if (flags & CONTEXT_INTEGER) ret |= SERVER_CTX_INTEGER;
|
|
|
|
if (flags & CONTEXT_SEGMENTS) ret |= SERVER_CTX_SEGMENTS;
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT) ret |= SERVER_CTX_FLOATING_POINT;
|
|
|
|
if (flags & CONTEXT_DEBUG_REGISTERS) ret |= SERVER_CTX_DEBUG_REGISTERS;
|
|
|
|
if (flags & CONTEXT_EXTENDED_REGISTERS) ret |= SERVER_CTX_EXTENDED_REGISTERS;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 & ~CONTEXT_i386; /* get rid of CPU id */
|
|
|
|
|
|
|
|
memset( to, 0, sizeof(*to) );
|
|
|
|
to->cpu = CPU_x86;
|
|
|
|
|
|
|
|
if (flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
to->flags |= SERVER_CTX_CONTROL;
|
|
|
|
to->ctl.i386_regs.ebp = from->Ebp;
|
|
|
|
to->ctl.i386_regs.esp = from->Esp;
|
|
|
|
to->ctl.i386_regs.eip = from->Eip;
|
|
|
|
to->ctl.i386_regs.cs = from->SegCs;
|
|
|
|
to->ctl.i386_regs.ss = from->SegSs;
|
|
|
|
to->ctl.i386_regs.eflags = from->EFlags;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_INTEGER)
|
|
|
|
{
|
|
|
|
to->flags |= SERVER_CTX_INTEGER;
|
|
|
|
to->integer.i386_regs.eax = from->Eax;
|
|
|
|
to->integer.i386_regs.ebx = from->Ebx;
|
|
|
|
to->integer.i386_regs.ecx = from->Ecx;
|
|
|
|
to->integer.i386_regs.edx = from->Edx;
|
|
|
|
to->integer.i386_regs.esi = from->Esi;
|
|
|
|
to->integer.i386_regs.edi = from->Edi;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_SEGMENTS)
|
|
|
|
{
|
|
|
|
to->flags |= SERVER_CTX_SEGMENTS;
|
|
|
|
to->seg.i386_regs.ds = from->SegDs;
|
|
|
|
to->seg.i386_regs.es = from->SegEs;
|
|
|
|
to->seg.i386_regs.fs = from->SegFs;
|
|
|
|
to->seg.i386_regs.gs = from->SegGs;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
to->flags |= SERVER_CTX_FLOATING_POINT;
|
|
|
|
to->fp.i386_regs.ctrl = from->FloatSave.ControlWord;
|
|
|
|
to->fp.i386_regs.status = from->FloatSave.StatusWord;
|
|
|
|
to->fp.i386_regs.tag = from->FloatSave.TagWord;
|
|
|
|
to->fp.i386_regs.err_off = from->FloatSave.ErrorOffset;
|
|
|
|
to->fp.i386_regs.err_sel = from->FloatSave.ErrorSelector;
|
|
|
|
to->fp.i386_regs.data_off = from->FloatSave.DataOffset;
|
|
|
|
to->fp.i386_regs.data_sel = from->FloatSave.DataSelector;
|
|
|
|
to->fp.i386_regs.cr0npx = from->FloatSave.Cr0NpxState;
|
|
|
|
memcpy( to->fp.i386_regs.regs, from->FloatSave.RegisterArea, sizeof(to->fp.i386_regs.regs) );
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_DEBUG_REGISTERS)
|
|
|
|
{
|
|
|
|
to->flags |= SERVER_CTX_DEBUG_REGISTERS;
|
|
|
|
to->debug.i386_regs.dr0 = from->Dr0;
|
|
|
|
to->debug.i386_regs.dr1 = from->Dr1;
|
|
|
|
to->debug.i386_regs.dr2 = from->Dr2;
|
|
|
|
to->debug.i386_regs.dr3 = from->Dr3;
|
|
|
|
to->debug.i386_regs.dr6 = from->Dr6;
|
|
|
|
to->debug.i386_regs.dr7 = from->Dr7;
|
|
|
|
}
|
|
|
|
if (flags & CONTEXT_EXTENDED_REGISTERS)
|
|
|
|
{
|
|
|
|
to->flags |= SERVER_CTX_EXTENDED_REGISTERS;
|
|
|
|
memcpy( to->ext.i386_regs, from->ExtendedRegisters, sizeof(to->ext.i386_regs) );
|
|
|
|
}
|
|
|
|
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_x86) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
to->ContextFlags = CONTEXT_i386;
|
|
|
|
if (from->flags & SERVER_CTX_CONTROL)
|
|
|
|
{
|
|
|
|
to->ContextFlags |= CONTEXT_CONTROL;
|
|
|
|
to->Ebp = from->ctl.i386_regs.ebp;
|
|
|
|
to->Esp = from->ctl.i386_regs.esp;
|
|
|
|
to->Eip = from->ctl.i386_regs.eip;
|
|
|
|
to->SegCs = from->ctl.i386_regs.cs;
|
|
|
|
to->SegSs = from->ctl.i386_regs.ss;
|
|
|
|
to->EFlags = from->ctl.i386_regs.eflags;
|
|
|
|
}
|
|
|
|
if (from->flags & SERVER_CTX_INTEGER)
|
|
|
|
{
|
|
|
|
to->ContextFlags |= CONTEXT_INTEGER;
|
|
|
|
to->Eax = from->integer.i386_regs.eax;
|
|
|
|
to->Ebx = from->integer.i386_regs.ebx;
|
|
|
|
to->Ecx = from->integer.i386_regs.ecx;
|
|
|
|
to->Edx = from->integer.i386_regs.edx;
|
|
|
|
to->Esi = from->integer.i386_regs.esi;
|
|
|
|
to->Edi = from->integer.i386_regs.edi;
|
|
|
|
}
|
|
|
|
if (from->flags & SERVER_CTX_SEGMENTS)
|
|
|
|
{
|
|
|
|
to->ContextFlags |= CONTEXT_SEGMENTS;
|
|
|
|
to->SegDs = from->seg.i386_regs.ds;
|
|
|
|
to->SegEs = from->seg.i386_regs.es;
|
|
|
|
to->SegFs = from->seg.i386_regs.fs;
|
|
|
|
to->SegGs = from->seg.i386_regs.gs;
|
|
|
|
}
|
|
|
|
if (from->flags & SERVER_CTX_FLOATING_POINT)
|
|
|
|
{
|
|
|
|
to->ContextFlags |= CONTEXT_FLOATING_POINT;
|
|
|
|
to->FloatSave.ControlWord = from->fp.i386_regs.ctrl;
|
|
|
|
to->FloatSave.StatusWord = from->fp.i386_regs.status;
|
|
|
|
to->FloatSave.TagWord = from->fp.i386_regs.tag;
|
|
|
|
to->FloatSave.ErrorOffset = from->fp.i386_regs.err_off;
|
|
|
|
to->FloatSave.ErrorSelector = from->fp.i386_regs.err_sel;
|
|
|
|
to->FloatSave.DataOffset = from->fp.i386_regs.data_off;
|
|
|
|
to->FloatSave.DataSelector = from->fp.i386_regs.data_sel;
|
|
|
|
to->FloatSave.Cr0NpxState = from->fp.i386_regs.cr0npx;
|
|
|
|
memcpy( to->FloatSave.RegisterArea, from->fp.i386_regs.regs, sizeof(to->FloatSave.RegisterArea) );
|
|
|
|
}
|
|
|
|
if (from->flags & SERVER_CTX_DEBUG_REGISTERS)
|
|
|
|
{
|
|
|
|
to->ContextFlags |= CONTEXT_DEBUG_REGISTERS;
|
|
|
|
to->Dr0 = from->debug.i386_regs.dr0;
|
|
|
|
to->Dr1 = from->debug.i386_regs.dr1;
|
|
|
|
to->Dr2 = from->debug.i386_regs.dr2;
|
|
|
|
to->Dr3 = from->debug.i386_regs.dr3;
|
|
|
|
to->Dr6 = from->debug.i386_regs.dr6;
|
|
|
|
to->Dr7 = from->debug.i386_regs.dr7;
|
|
|
|
}
|
|
|
|
if (from->flags & SERVER_CTX_EXTENDED_REGISTERS)
|
|
|
|
{
|
|
|
|
to->ContextFlags |= CONTEXT_EXTENDED_REGISTERS;
|
|
|
|
memcpy( to->ExtendedRegisters, from->ext.i386_regs, sizeof(to->ExtendedRegisters) );
|
|
|
|
}
|
|
|
|
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 = STATUS_SUCCESS;
|
|
|
|
BOOL self = (handle == GetCurrentThread());
|
|
|
|
|
|
|
|
/* debug registers require a server call */
|
|
|
|
if (self && (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)))
|
2017-07-19 15:14:24 +02:00
|
|
|
self = (x86_thread_data()->dr0 == context->Dr0 &&
|
|
|
|
x86_thread_data()->dr1 == context->Dr1 &&
|
|
|
|
x86_thread_data()->dr2 == context->Dr2 &&
|
|
|
|
x86_thread_data()->dr3 == context->Dr3 &&
|
|
|
|
x86_thread_data()->dr6 == context->Dr6 &&
|
|
|
|
x86_thread_data()->dr7 == context->Dr7);
|
2017-07-18 11:08:37 +02:00
|
|
|
|
2018-06-12 10:46:27 +02:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
context_t server_context;
|
|
|
|
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.@)
|
2017-07-24 10:33:53 +02:00
|
|
|
*
|
|
|
|
* Note: we use a small assembly wrapper to save the necessary registers
|
|
|
|
* in case we are fetching the context of the current thread.
|
2017-07-18 11:15:46 +02:00
|
|
|
*/
|
2017-07-25 11:48:24 +02:00
|
|
|
NTSTATUS CDECL DECLSPEC_HIDDEN __regs_NtGetContextThread( DWORD edi, DWORD esi, DWORD ebx, DWORD eflags,
|
|
|
|
DWORD ebp, DWORD retaddr, HANDLE handle,
|
|
|
|
CONTEXT *context )
|
2017-07-18 11:15:46 +02:00
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
2017-07-24 10:33:53 +02:00
|
|
|
DWORD needed_flags = context->ContextFlags & ~CONTEXT_i386;
|
2017-07-18 11:15:46 +02:00
|
|
|
BOOL self = (handle == GetCurrentThread());
|
|
|
|
|
|
|
|
/* debug registers require a server call */
|
2017-07-24 10:33:53 +02:00
|
|
|
if (needed_flags & CONTEXT_DEBUG_REGISTERS) self = FALSE;
|
2017-07-18 11:15:46 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2017-07-24 10:33:53 +02:00
|
|
|
if (needed_flags & CONTEXT_INTEGER)
|
2017-07-18 11:15:46 +02:00
|
|
|
{
|
2017-07-24 10:33:53 +02:00
|
|
|
context->Eax = 0;
|
|
|
|
context->Ebx = ebx;
|
|
|
|
context->Ecx = 0;
|
|
|
|
context->Edx = 0;
|
|
|
|
context->Esi = esi;
|
|
|
|
context->Edi = edi;
|
|
|
|
context->ContextFlags |= CONTEXT_INTEGER;
|
2017-07-18 11:15:46 +02:00
|
|
|
}
|
2017-07-24 10:33:53 +02:00
|
|
|
if (needed_flags & CONTEXT_CONTROL)
|
|
|
|
{
|
|
|
|
context->Ebp = ebp;
|
|
|
|
context->Esp = (DWORD)&retaddr;
|
|
|
|
context->Eip = *(&edi - 1);
|
|
|
|
context->SegCs = wine_get_cs();
|
|
|
|
context->SegSs = wine_get_ss();
|
|
|
|
context->EFlags = eflags;
|
|
|
|
context->ContextFlags |= CONTEXT_CONTROL;
|
|
|
|
}
|
|
|
|
if (needed_flags & CONTEXT_SEGMENTS)
|
|
|
|
{
|
|
|
|
context->SegDs = wine_get_ds();
|
|
|
|
context->SegEs = wine_get_es();
|
|
|
|
context->SegFs = wine_get_fs();
|
|
|
|
context->SegGs = wine_get_gs();
|
|
|
|
context->ContextFlags |= CONTEXT_SEGMENTS;
|
|
|
|
}
|
|
|
|
if (needed_flags & CONTEXT_FLOATING_POINT) save_fpu( context );
|
2019-02-14 19:46:16 +01:00
|
|
|
if (needed_flags & CONTEXT_EXTENDED_REGISTERS) save_fpux( context );
|
|
|
|
/* FIXME: xstate */
|
2017-07-18 11:15:46 +02:00
|
|
|
/* update the cached version of the debug registers */
|
|
|
|
if (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386))
|
|
|
|
{
|
2017-07-19 15:14:24 +02:00
|
|
|
x86_thread_data()->dr0 = context->Dr0;
|
|
|
|
x86_thread_data()->dr1 = context->Dr1;
|
|
|
|
x86_thread_data()->dr2 = context->Dr2;
|
|
|
|
x86_thread_data()->dr3 = context->Dr3;
|
|
|
|
x86_thread_data()->dr6 = context->Dr6;
|
|
|
|
x86_thread_data()->dr7 = context->Dr7;
|
2017-07-18 11:15:46 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-24 10:33:53 +02:00
|
|
|
|
|
|
|
if (context->ContextFlags & (CONTEXT_INTEGER & ~CONTEXT_i386))
|
|
|
|
TRACE( "%p: eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n", handle,
|
|
|
|
context->Eax, context->Ebx, context->Ecx, context->Edx, context->Esi, context->Edi );
|
|
|
|
if (context->ContextFlags & (CONTEXT_CONTROL & ~CONTEXT_i386))
|
|
|
|
TRACE( "%p: ebp=%08x esp=%08x eip=%08x cs=%04x ss=%04x flags=%08x\n", handle,
|
|
|
|
context->Ebp, context->Esp, context->Eip, context->SegCs, context->SegSs, context->EFlags );
|
|
|
|
if (context->ContextFlags & (CONTEXT_SEGMENTS & ~CONTEXT_i386))
|
|
|
|
TRACE( "%p: ds=%04x es=%04x fs=%04x gs=%04x\n", handle,
|
2017-08-09 21:25:38 +02:00
|
|
|
context->SegDs, context->SegEs, context->SegFs, context->SegGs );
|
2017-07-24 10:33:53 +02:00
|
|
|
if (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386))
|
|
|
|
TRACE( "%p: dr0=%08x dr1=%08x dr2=%08x dr3=%08x dr6=%08x dr7=%08x\n", handle,
|
|
|
|
context->Dr0, context->Dr1, context->Dr2, context->Dr3, context->Dr6, context->Dr7 );
|
|
|
|
|
2017-07-18 11:15:46 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2017-07-24 10:33:53 +02:00
|
|
|
__ASM_STDCALL_FUNC( NtGetContextThread, 8,
|
|
|
|
"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")
|
|
|
|
"pushfl\n\t"
|
|
|
|
"pushl %ebx\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebx,-8\n\t")
|
|
|
|
"pushl %esi\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %esi,-12\n\t")
|
|
|
|
"pushl %edi\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %edi,-16\n\t")
|
|
|
|
"call " __ASM_NAME("__regs_NtGetContextThread") "\n\t"
|
|
|
|
"leave\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
|
|
|
"ret $8" )
|
2017-07-18 11:15:46 +02:00
|
|
|
|
|
|
|
|
2005-12-16 16:27:39 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* is_privileged_instr
|
|
|
|
*
|
|
|
|
* Check if the fault location is a privileged instruction.
|
|
|
|
* Based on the instruction emulation code in dlls/kernel/instr.c.
|
|
|
|
*/
|
2010-10-20 15:33:49 +02:00
|
|
|
static inline DWORD is_privileged_instr( CONTEXT *context )
|
2005-12-16 16:27:39 +01:00
|
|
|
{
|
2019-09-13 17:19:38 +02:00
|
|
|
BYTE instr[16];
|
|
|
|
unsigned int i, len, prefix_count = 0;
|
2005-12-16 16:27:39 +01:00
|
|
|
|
|
|
|
if (!wine_ldt_is_system( context->SegCs )) return 0;
|
2019-09-13 17:19:38 +02:00
|
|
|
len = virtual_uninterrupted_read_memory( (BYTE *)context->Eip, instr, sizeof(instr) );
|
2005-12-16 16:27:39 +01:00
|
|
|
|
2019-09-13 17:19:38 +02:00
|
|
|
for (i = 0; i < len; i++) switch (instr[i])
|
2005-12-16 16:27:39 +01:00
|
|
|
{
|
|
|
|
/* instruction prefixes */
|
|
|
|
case 0x2e: /* %cs: */
|
|
|
|
case 0x36: /* %ss: */
|
|
|
|
case 0x3e: /* %ds: */
|
|
|
|
case 0x26: /* %es: */
|
|
|
|
case 0x64: /* %fs: */
|
|
|
|
case 0x65: /* %gs: */
|
|
|
|
case 0x66: /* opcode size */
|
|
|
|
case 0x67: /* addr size */
|
|
|
|
case 0xf0: /* lock */
|
|
|
|
case 0xf2: /* repne */
|
|
|
|
case 0xf3: /* repe */
|
2007-03-14 12:02:43 +01:00
|
|
|
if (++prefix_count >= 15) return EXCEPTION_ILLEGAL_INSTRUCTION;
|
2005-12-16 16:27:39 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0x0f: /* extended instruction */
|
2019-09-13 17:19:38 +02:00
|
|
|
if (i == len - 1) return 0;
|
|
|
|
switch(instr[i + 1])
|
2005-12-16 16:27:39 +01:00
|
|
|
{
|
|
|
|
case 0x20: /* mov crX, reg */
|
|
|
|
case 0x21: /* mov drX, reg */
|
|
|
|
case 0x22: /* mov reg, crX */
|
|
|
|
case 0x23: /* mov reg drX */
|
2007-03-14 12:02:43 +01:00
|
|
|
return EXCEPTION_PRIV_INSTRUCTION;
|
2005-12-16 16:27:39 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case 0x6c: /* insb (%dx) */
|
|
|
|
case 0x6d: /* insl (%dx) */
|
|
|
|
case 0x6e: /* outsb (%dx) */
|
|
|
|
case 0x6f: /* outsl (%dx) */
|
|
|
|
case 0xcd: /* int $xx */
|
|
|
|
case 0xe4: /* inb al,XX */
|
|
|
|
case 0xe5: /* in (e)ax,XX */
|
|
|
|
case 0xe6: /* outb XX,al */
|
|
|
|
case 0xe7: /* out XX,(e)ax */
|
|
|
|
case 0xec: /* inb (%dx),%al */
|
|
|
|
case 0xed: /* inl (%dx),%eax */
|
|
|
|
case 0xee: /* outb %al,(%dx) */
|
|
|
|
case 0xef: /* outl %eax,(%dx) */
|
|
|
|
case 0xf4: /* hlt */
|
|
|
|
case 0xfa: /* cli */
|
|
|
|
case 0xfb: /* sti */
|
2007-03-14 12:02:43 +01:00
|
|
|
return EXCEPTION_PRIV_INSTRUCTION;
|
2005-12-16 16:27:39 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2019-09-13 17:19:38 +02:00
|
|
|
return 0;
|
2005-12-16 16:27:39 +01:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:18:05 +01:00
|
|
|
|
2013-02-12 15:21:15 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* check_invalid_gs
|
|
|
|
*
|
|
|
|
* Check for fault caused by invalid %gs value (some copy protection schemes mess with it).
|
|
|
|
*/
|
2019-09-12 20:00:48 +02:00
|
|
|
static inline BOOL check_invalid_gs( ucontext_t *sigcontext, CONTEXT *context )
|
2013-02-12 15:21:15 +01:00
|
|
|
{
|
2019-09-17 16:02:55 +02:00
|
|
|
unsigned int prefix_count = 0;
|
|
|
|
const BYTE *instr = (BYTE *)context->Eip;
|
2017-07-19 15:14:24 +02:00
|
|
|
WORD system_gs = x86_thread_data()->gs;
|
2013-02-12 15:21:15 +01:00
|
|
|
|
|
|
|
if (context->SegGs == system_gs) return FALSE;
|
|
|
|
if (!wine_ldt_is_system( context->SegCs )) return FALSE;
|
|
|
|
/* only handle faults in system libraries */
|
2019-09-17 16:02:55 +02:00
|
|
|
if (virtual_is_valid_code_address( instr, 1 )) return FALSE;
|
2013-02-12 15:21:15 +01:00
|
|
|
|
2019-09-17 16:02:55 +02:00
|
|
|
for (;;) switch(*instr)
|
2013-02-12 15:21:15 +01:00
|
|
|
{
|
|
|
|
/* instruction prefixes */
|
|
|
|
case 0x2e: /* %cs: */
|
|
|
|
case 0x36: /* %ss: */
|
|
|
|
case 0x3e: /* %ds: */
|
|
|
|
case 0x26: /* %es: */
|
|
|
|
case 0x64: /* %fs: */
|
|
|
|
case 0x66: /* opcode size */
|
|
|
|
case 0x67: /* addr size */
|
|
|
|
case 0xf0: /* lock */
|
|
|
|
case 0xf2: /* repne */
|
|
|
|
case 0xf3: /* repe */
|
2019-09-17 16:02:55 +02:00
|
|
|
if (++prefix_count >= 15) return FALSE;
|
|
|
|
instr++;
|
2013-02-12 15:21:15 +01:00
|
|
|
continue;
|
|
|
|
case 0x65: /* %gs: */
|
|
|
|
TRACE( "%04x/%04x at %p, fixing up\n", context->SegGs, system_gs, instr );
|
2019-09-12 20:00:48 +02:00
|
|
|
#ifdef GS_sig
|
|
|
|
GS_sig(sigcontext) = system_gs;
|
|
|
|
#endif
|
2013-02-12 15:21:15 +01:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-16 16:27:39 +01:00
|
|
|
|
2006-02-10 15:13:59 +01:00
|
|
|
#include "pshpack1.h"
|
2014-10-21 05:55:27 +02:00
|
|
|
union atl_thunk
|
2006-02-10 15:13:59 +01:00
|
|
|
{
|
2014-10-21 05:55:27 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
DWORD movl; /* movl this,4(%esp) */
|
|
|
|
DWORD this;
|
|
|
|
BYTE jmp; /* jmp func */
|
|
|
|
int func;
|
|
|
|
} t1;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
BYTE movl; /* movl this,ecx */
|
|
|
|
DWORD this;
|
|
|
|
BYTE jmp; /* jmp func */
|
|
|
|
int func;
|
|
|
|
} t2;
|
2014-10-21 06:00:20 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
BYTE movl1; /* movl this,edx */
|
|
|
|
DWORD this;
|
|
|
|
BYTE movl2; /* movl func,ecx */
|
|
|
|
DWORD func;
|
|
|
|
WORD jmp; /* jmp ecx */
|
|
|
|
} t3;
|
2014-10-21 06:02:02 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
BYTE movl1; /* movl this,ecx */
|
|
|
|
DWORD this;
|
|
|
|
BYTE movl2; /* movl func,eax */
|
|
|
|
DWORD func;
|
|
|
|
WORD jmp; /* jmp eax */
|
|
|
|
} t4;
|
2014-10-21 06:03:57 +02:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
DWORD inst1; /* pop ecx
|
|
|
|
* pop eax
|
|
|
|
* push ecx
|
|
|
|
* jmp 4(%eax) */
|
|
|
|
WORD inst2;
|
|
|
|
} t5;
|
2006-02-10 15:13:59 +01:00
|
|
|
};
|
|
|
|
#include "poppack.h"
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* check_atl_thunk
|
|
|
|
*
|
|
|
|
* Check if code destination is an ATL thunk, and emulate it if so.
|
|
|
|
*/
|
2019-09-12 20:50:16 +02:00
|
|
|
static BOOL check_atl_thunk( ucontext_t *sigcontext, struct stack_layout *stack )
|
2006-02-10 15:13:59 +01:00
|
|
|
{
|
2019-09-12 20:50:16 +02:00
|
|
|
const union atl_thunk *thunk = (const union atl_thunk *)stack->rec.ExceptionInformation[1];
|
2014-10-21 05:55:27 +02:00
|
|
|
union atl_thunk thunk_copy;
|
|
|
|
SIZE_T thunk_len;
|
2006-09-27 16:51:07 +02:00
|
|
|
|
2014-10-21 05:55:27 +02:00
|
|
|
thunk_len = virtual_uninterrupted_read_memory( thunk, &thunk_copy, sizeof(*thunk) );
|
|
|
|
if (!thunk_len) return FALSE;
|
2013-02-12 19:56:08 +01:00
|
|
|
|
2014-10-21 05:55:27 +02:00
|
|
|
if (thunk_len >= sizeof(thunk_copy.t1) && thunk_copy.t1.movl == 0x042444c7 &&
|
|
|
|
thunk_copy.t1.jmp == 0xe9)
|
2006-09-27 16:51:07 +02:00
|
|
|
{
|
2019-09-12 20:50:16 +02:00
|
|
|
if (!virtual_uninterrupted_write_memory( (DWORD *)stack->context.Esp + 1,
|
2017-09-06 17:16:25 +02:00
|
|
|
&thunk_copy.t1.this, sizeof(DWORD) ))
|
2006-09-27 16:51:07 +02:00
|
|
|
{
|
2019-09-12 20:50:16 +02:00
|
|
|
EIP_sig(sigcontext) = (DWORD_PTR)(&thunk->t1.func + 1) + thunk_copy.t1.func;
|
2014-10-21 05:55:27 +02:00
|
|
|
TRACE( "emulating ATL thunk type 1 at %p, func=%08x arg=%08x\n",
|
2019-09-12 20:50:16 +02:00
|
|
|
thunk, EIP_sig(sigcontext), thunk_copy.t1.this );
|
2014-10-21 05:55:27 +02:00
|
|
|
return TRUE;
|
2006-09-27 16:51:07 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-21 05:55:27 +02:00
|
|
|
else if (thunk_len >= sizeof(thunk_copy.t2) && thunk_copy.t2.movl == 0xb9 &&
|
|
|
|
thunk_copy.t2.jmp == 0xe9)
|
|
|
|
{
|
2019-09-12 20:50:16 +02:00
|
|
|
ECX_sig(sigcontext) = thunk_copy.t2.this;
|
|
|
|
EIP_sig(sigcontext) = (DWORD_PTR)(&thunk->t2.func + 1) + thunk_copy.t2.func;
|
2014-10-21 05:55:27 +02:00
|
|
|
TRACE( "emulating ATL thunk type 2 at %p, func=%08x ecx=%08x\n",
|
2019-09-12 20:50:16 +02:00
|
|
|
thunk, EIP_sig(sigcontext), ECX_sig(sigcontext) );
|
2014-10-21 05:55:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-21 06:00:20 +02:00
|
|
|
else if (thunk_len >= sizeof(thunk_copy.t3) && thunk_copy.t3.movl1 == 0xba &&
|
|
|
|
thunk_copy.t3.movl2 == 0xb9 &&
|
|
|
|
thunk_copy.t3.jmp == 0xe1ff)
|
|
|
|
{
|
2019-09-12 20:50:16 +02:00
|
|
|
EDX_sig(sigcontext) = thunk_copy.t3.this;
|
|
|
|
ECX_sig(sigcontext) = thunk_copy.t3.func;
|
|
|
|
EIP_sig(sigcontext) = thunk_copy.t3.func;
|
2014-10-21 06:00:20 +02:00
|
|
|
TRACE( "emulating ATL thunk type 3 at %p, func=%08x ecx=%08x edx=%08x\n",
|
2019-09-12 20:50:16 +02:00
|
|
|
thunk, EIP_sig(sigcontext), ECX_sig(sigcontext), EDX_sig(sigcontext) );
|
2014-10-21 06:00:20 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-21 06:02:02 +02:00
|
|
|
else if (thunk_len >= sizeof(thunk_copy.t4) && thunk_copy.t4.movl1 == 0xb9 &&
|
|
|
|
thunk_copy.t4.movl2 == 0xb8 &&
|
|
|
|
thunk_copy.t4.jmp == 0xe0ff)
|
|
|
|
{
|
2019-09-12 20:50:16 +02:00
|
|
|
ECX_sig(sigcontext) = thunk_copy.t4.this;
|
|
|
|
EAX_sig(sigcontext) = thunk_copy.t4.func;
|
|
|
|
EIP_sig(sigcontext) = thunk_copy.t4.func;
|
2014-10-21 06:02:02 +02:00
|
|
|
TRACE( "emulating ATL thunk type 4 at %p, func=%08x eax=%08x ecx=%08x\n",
|
2019-09-12 20:50:16 +02:00
|
|
|
thunk, EIP_sig(sigcontext), EAX_sig(sigcontext), ECX_sig(sigcontext) );
|
2014-10-21 06:02:02 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-21 06:03:57 +02:00
|
|
|
else if (thunk_len >= sizeof(thunk_copy.t5) && thunk_copy.t5.inst1 == 0xff515859 &&
|
|
|
|
thunk_copy.t5.inst2 == 0x0460)
|
|
|
|
{
|
2019-09-12 20:50:16 +02:00
|
|
|
DWORD func, sp[2];
|
|
|
|
if (virtual_uninterrupted_read_memory( (DWORD *)stack->context.Esp, sp, sizeof(sp) ) == sizeof(sp) &&
|
|
|
|
virtual_uninterrupted_read_memory( (DWORD *)sp[1] + 1, &func, sizeof(DWORD) ) == sizeof(DWORD) &&
|
|
|
|
!virtual_uninterrupted_write_memory( (DWORD *)stack->context.Esp + 1, &sp[0], sizeof(sp[0]) ))
|
2014-10-21 06:03:57 +02:00
|
|
|
{
|
2019-09-12 20:50:16 +02:00
|
|
|
ECX_sig(sigcontext) = sp[0];
|
|
|
|
EAX_sig(sigcontext) = sp[1];
|
|
|
|
ESP_sig(sigcontext) += sizeof(DWORD);
|
|
|
|
EIP_sig(sigcontext) = func;
|
2014-10-21 06:03:57 +02:00
|
|
|
TRACE( "emulating ATL thunk type 5 at %p, func=%08x eax=%08x ecx=%08x esp=%08x\n",
|
2019-09-12 20:50:16 +02:00
|
|
|
thunk, EIP_sig(sigcontext), EAX_sig(sigcontext),
|
|
|
|
ECX_sig(sigcontext), ESP_sig(sigcontext) );
|
2014-10-21 06:03:57 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2014-10-14 06:22:55 +02:00
|
|
|
|
2014-10-21 05:55:27 +02:00
|
|
|
return FALSE;
|
2006-02-10 15:13:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-28 01:30:55 +01:00
|
|
|
/***********************************************************************
|
2008-04-01 17:37:17 +02:00
|
|
|
* setup_exception_record
|
2003-10-28 01:30:55 +01:00
|
|
|
*
|
2008-04-01 17:37:17 +02:00
|
|
|
* Setup the exception record and context on the thread stack.
|
2003-10-28 01:30:55 +01:00
|
|
|
*/
|
2019-09-12 19:20:14 +02:00
|
|
|
static struct stack_layout *setup_exception_record( ucontext_t *sigcontext, void *stack_ptr,
|
2019-09-12 19:23:26 +02:00
|
|
|
WORD fs, WORD gs )
|
2003-10-28 01:30:55 +01:00
|
|
|
{
|
2019-09-12 19:20:14 +02:00
|
|
|
struct stack_layout *stack = stack_ptr;
|
2008-04-01 17:40:37 +02:00
|
|
|
DWORD exception_code = 0;
|
2003-10-28 01:30:55 +01:00
|
|
|
|
|
|
|
/* stack sanity checks */
|
|
|
|
|
2003-10-31 00:15:56 +01:00
|
|
|
if ((char *)stack >= (char *)get_signal_stack() &&
|
2005-09-14 12:36:58 +02:00
|
|
|
(char *)stack < (char *)get_signal_stack() + signal_stack_size)
|
2003-10-28 01:30:55 +01:00
|
|
|
{
|
2007-03-14 09:53:59 +01:00
|
|
|
WINE_ERR( "nested exception on signal stack in thread %04x eip %08x esp %08x stack %p-%p\n",
|
|
|
|
GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext),
|
|
|
|
(unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->Tib.StackLimit,
|
|
|
|
NtCurrentTeb()->Tib.StackBase );
|
2009-02-20 11:23:08 +01:00
|
|
|
abort_thread(1);
|
2003-10-28 01:30:55 +01:00
|
|
|
}
|
|
|
|
|
2005-08-25 21:20:21 +02:00
|
|
|
if (stack - 1 > stack || /* check for overflow in subtraction */
|
2008-04-01 17:40:37 +02:00
|
|
|
(char *)stack <= (char *)NtCurrentTeb()->DeallocationStack ||
|
2003-10-28 01:30:55 +01:00
|
|
|
(char *)stack > (char *)NtCurrentTeb()->Tib.StackBase)
|
|
|
|
{
|
2008-04-01 17:40:37 +02:00
|
|
|
WARN( "exception outside of stack limits in thread %04x eip %08x esp %08x stack %p-%p\n",
|
|
|
|
GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext),
|
|
|
|
(unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->Tib.StackLimit,
|
|
|
|
NtCurrentTeb()->Tib.StackBase );
|
|
|
|
}
|
|
|
|
else if ((char *)(stack - 1) < (char *)NtCurrentTeb()->DeallocationStack + 4096)
|
|
|
|
{
|
|
|
|
/* stack overflow on last page, unrecoverable */
|
|
|
|
UINT diff = (char *)NtCurrentTeb()->DeallocationStack + 4096 - (char *)(stack - 1);
|
|
|
|
WINE_ERR( "stack overflow %u bytes in thread %04x eip %08x esp %08x stack %p-%p-%p\n",
|
|
|
|
diff, GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext),
|
|
|
|
(unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->DeallocationStack,
|
|
|
|
NtCurrentTeb()->Tib.StackLimit, NtCurrentTeb()->Tib.StackBase );
|
2009-02-20 11:23:08 +01:00
|
|
|
abort_thread(1);
|
2008-04-01 17:40:37 +02:00
|
|
|
}
|
|
|
|
else if ((char *)(stack - 1) < (char *)NtCurrentTeb()->Tib.StackLimit)
|
|
|
|
{
|
|
|
|
/* stack access below stack limit, may be recoverable */
|
2019-08-24 12:24:09 +02:00
|
|
|
switch (virtual_handle_stack_fault( stack - 1 ))
|
|
|
|
{
|
|
|
|
case 0: /* not handled */
|
2003-11-04 05:50:18 +01:00
|
|
|
{
|
2008-04-01 17:40:37 +02:00
|
|
|
UINT diff = (char *)NtCurrentTeb()->Tib.StackLimit - (char *)(stack - 1);
|
|
|
|
WINE_ERR( "stack overflow %u bytes in thread %04x eip %08x esp %08x stack %p-%p-%p\n",
|
2007-03-14 09:53:59 +01:00
|
|
|
diff, GetCurrentThreadId(), (unsigned int) EIP_sig(sigcontext),
|
2008-04-01 17:40:37 +02:00
|
|
|
(unsigned int) ESP_sig(sigcontext), NtCurrentTeb()->DeallocationStack,
|
|
|
|
NtCurrentTeb()->Tib.StackLimit, NtCurrentTeb()->Tib.StackBase );
|
2009-02-20 11:23:08 +01:00
|
|
|
abort_thread(1);
|
2003-11-04 05:50:18 +01:00
|
|
|
}
|
2019-08-24 12:24:09 +02:00
|
|
|
case -1: /* overflow */
|
|
|
|
exception_code = EXCEPTION_STACK_OVERFLOW;
|
|
|
|
break;
|
|
|
|
}
|
2003-10-28 01:30:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stack--; /* push the stack_layout structure */
|
2007-12-23 14:57:36 +01:00
|
|
|
#if defined(VALGRIND_MAKE_MEM_UNDEFINED)
|
|
|
|
VALGRIND_MAKE_MEM_UNDEFINED(stack, sizeof(*stack));
|
|
|
|
#elif defined(VALGRIND_MAKE_WRITABLE)
|
2006-02-14 13:06:29 +01:00
|
|
|
VALGRIND_MAKE_WRITABLE(stack, sizeof(*stack));
|
|
|
|
#endif
|
2003-10-28 01:30:55 +01:00
|
|
|
stack->rec.ExceptionRecord = NULL;
|
2008-04-01 17:40:37 +02:00
|
|
|
stack->rec.ExceptionCode = exception_code;
|
2003-10-28 01:30:55 +01:00
|
|
|
stack->rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
|
|
|
|
stack->rec.ExceptionAddress = (LPVOID)EIP_sig(sigcontext);
|
|
|
|
stack->rec.NumberParameters = 0;
|
|
|
|
|
2005-11-02 21:54:12 +01:00
|
|
|
save_context( &stack->context, sigcontext, fs, gs );
|
2019-09-12 19:20:14 +02:00
|
|
|
return stack;
|
2003-10-28 01:30:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-01 17:37:17 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* setup_exception
|
|
|
|
*
|
|
|
|
* Setup a proper stack frame for the raise function, and modify the
|
|
|
|
* sigcontext so that the return from the signal handler will call
|
|
|
|
* the raise function.
|
|
|
|
*/
|
2019-09-12 19:23:26 +02:00
|
|
|
static struct stack_layout *setup_exception( ucontext_t *sigcontext )
|
2008-04-01 17:37:17 +02:00
|
|
|
{
|
|
|
|
WORD fs, gs;
|
|
|
|
void *stack = init_handler( sigcontext, &fs, &gs );
|
|
|
|
|
2019-09-12 19:23:26 +02:00
|
|
|
return setup_exception_record( sigcontext, stack, fs, gs );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-12 21:02:29 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* raise_generic_exception
|
|
|
|
*
|
|
|
|
* Generic raise function for exceptions that don't need special treatment.
|
|
|
|
*/
|
|
|
|
static void WINAPI raise_generic_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2019-09-18 18:09:11 +02:00
|
|
|
status = raise_exception( rec, context, TRUE );
|
2019-09-12 21:02:29 +02:00
|
|
|
raise_status( status, rec );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-12 19:23:26 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* setup_raise_exception
|
|
|
|
*
|
|
|
|
* Change context to setup a call to a raise exception function.
|
|
|
|
*/
|
2019-09-12 21:02:29 +02:00
|
|
|
static void setup_raise_exception( ucontext_t *sigcontext, struct stack_layout *stack )
|
2019-09-12 19:23:26 +02:00
|
|
|
{
|
2019-09-18 18:09:11 +02:00
|
|
|
NTSTATUS status = send_debug_event( &stack->rec, TRUE, &stack->context );
|
|
|
|
|
|
|
|
if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
|
|
|
|
{
|
|
|
|
restore_context( &stack->context, sigcontext );
|
|
|
|
return;
|
|
|
|
}
|
2019-09-12 19:23:26 +02:00
|
|
|
ESP_sig(sigcontext) = (DWORD)stack;
|
2019-09-12 21:02:29 +02:00
|
|
|
EIP_sig(sigcontext) = (DWORD)raise_generic_exception;
|
2019-09-12 19:23:26 +02:00
|
|
|
/* clear single-step, direction, and align check flag */
|
|
|
|
EFL_sig(sigcontext) &= ~(0x100|0x400|0x40000);
|
|
|
|
CS_sig(sigcontext) = wine_get_cs();
|
|
|
|
DS_sig(sigcontext) = wine_get_ds();
|
|
|
|
ES_sig(sigcontext) = wine_get_es();
|
|
|
|
FS_sig(sigcontext) = wine_get_fs();
|
|
|
|
GS_sig(sigcontext) = wine_get_gs();
|
|
|
|
SS_sig(sigcontext) = wine_get_ss();
|
2019-09-12 21:02:29 +02:00
|
|
|
stack->ret_addr = (void *)0xdeadbabe; /* raise_generic_exception must not return */
|
|
|
|
stack->rec_ptr = &stack->rec; /* arguments for raise_generic_exception */
|
2019-09-12 19:23:26 +02:00
|
|
|
stack->context_ptr = &stack->context;
|
2008-04-01 17:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* get_fpu_code
|
|
|
|
*
|
|
|
|
* Get the FPU exception code from the FPU status.
|
|
|
|
*/
|
|
|
|
static inline DWORD get_fpu_code( const CONTEXT *context )
|
|
|
|
{
|
2009-01-04 20:38:58 +01:00
|
|
|
DWORD status = context->FloatSave.StatusWord & ~(context->FloatSave.ControlWord & 0x3f);
|
1999-09-27 12:58:45 +02:00
|
|
|
|
|
|
|
if (status & 0x01) /* IE */
|
|
|
|
{
|
|
|
|
if (status & 0x40) /* SF */
|
|
|
|
return EXCEPTION_FLT_STACK_CHECK;
|
|
|
|
else
|
|
|
|
return EXCEPTION_FLT_INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
if (status & 0x02) return EXCEPTION_FLT_DENORMAL_OPERAND; /* DE flag */
|
|
|
|
if (status & 0x04) return EXCEPTION_FLT_DIVIDE_BY_ZERO; /* ZE flag */
|
|
|
|
if (status & 0x08) return EXCEPTION_FLT_OVERFLOW; /* OE flag */
|
|
|
|
if (status & 0x10) return EXCEPTION_FLT_UNDERFLOW; /* UE flag */
|
|
|
|
if (status & 0x20) return EXCEPTION_FLT_INEXACT_RESULT; /* PE flag */
|
|
|
|
return EXCEPTION_FLT_INVALID_OPERATION; /* generic error */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-12 19:48:48 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* handle_interrupt
|
|
|
|
*
|
|
|
|
* Handle an interrupt.
|
|
|
|
*/
|
|
|
|
static BOOL handle_interrupt( unsigned int interrupt, ucontext_t *sigcontext, struct stack_layout *stack )
|
|
|
|
{
|
|
|
|
switch(interrupt)
|
|
|
|
{
|
|
|
|
case 0x2d:
|
|
|
|
if (!is_wow64)
|
|
|
|
{
|
|
|
|
/* On Wow64, the upper DWORD of Rax contains garbage, and the debug
|
|
|
|
* service is usually not recognized when called from usermode. */
|
|
|
|
switch (stack->context.Eax)
|
|
|
|
{
|
|
|
|
case 1: /* BREAKPOINT_PRINT */
|
|
|
|
case 3: /* BREAKPOINT_LOAD_SYMBOLS */
|
|
|
|
case 4: /* BREAKPOINT_UNLOAD_SYMBOLS */
|
|
|
|
case 5: /* BREAKPOINT_COMMAND_STRING (>= Win2003) */
|
|
|
|
EIP_sig(sigcontext) += 3;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stack->context.Eip += 3;
|
|
|
|
stack->rec.ExceptionCode = EXCEPTION_BREAKPOINT;
|
|
|
|
stack->rec.ExceptionAddress = (void *)stack->context.Eip;
|
|
|
|
stack->rec.NumberParameters = is_wow64 ? 1 : 3;
|
|
|
|
stack->rec.ExceptionInformation[0] = stack->context.Eax;
|
|
|
|
stack->rec.ExceptionInformation[1] = stack->context.Ecx;
|
|
|
|
stack->rec.ExceptionInformation[2] = stack->context.Edx;
|
2019-09-12 21:02:29 +02:00
|
|
|
setup_raise_exception( sigcontext, stack );
|
2019-09-12 19:48:48 +02:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-18 04:15:07 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* segv_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGSEGV and related errors.
|
|
|
|
*/
|
2006-08-11 14:45:11 +02:00
|
|
|
static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2000-09-18 04:15:07 +02:00
|
|
|
{
|
2008-04-01 17:37:17 +02:00
|
|
|
WORD fs, gs;
|
2019-09-12 19:20:14 +02:00
|
|
|
struct stack_layout *stack;
|
2014-07-23 16:32:33 +02:00
|
|
|
ucontext_t *context = sigcontext;
|
2019-09-12 19:20:14 +02:00
|
|
|
void *stack_ptr = init_handler( sigcontext, &fs, &gs );
|
2008-04-01 17:37:17 +02:00
|
|
|
|
2015-02-10 14:54:25 +01:00
|
|
|
/* check for exceptions on the signal stack caused by write watches */
|
|
|
|
if (get_trap_code(context) == TRAP_x86_PAGEFLT &&
|
2019-09-12 19:20:14 +02:00
|
|
|
(char *)stack_ptr >= (char *)get_signal_stack() &&
|
|
|
|
(char *)stack_ptr < (char *)get_signal_stack() + signal_stack_size &&
|
2015-02-10 14:54:25 +01:00
|
|
|
!virtual_handle_fault( siginfo->si_addr, (get_error_code(context) >> 1) & 0x09, TRUE ))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-01 17:37:17 +02:00
|
|
|
/* check for page fault inside the thread stack */
|
2019-08-24 12:24:09 +02:00
|
|
|
if (get_trap_code(context) == TRAP_x86_PAGEFLT)
|
2008-04-01 17:40:37 +02:00
|
|
|
{
|
2019-08-24 12:24:09 +02:00
|
|
|
switch (virtual_handle_stack_fault( siginfo->si_addr ))
|
2008-04-01 17:40:37 +02:00
|
|
|
{
|
2019-08-24 12:24:09 +02:00
|
|
|
case 1: /* handled */
|
|
|
|
return;
|
|
|
|
case -1: /* overflow */
|
2019-09-12 19:23:26 +02:00
|
|
|
stack = setup_exception_record( context, stack_ptr, fs, gs );
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_STACK_OVERFLOW;
|
2019-09-12 19:23:26 +02:00
|
|
|
goto done;
|
2008-04-01 17:40:37 +02:00
|
|
|
}
|
|
|
|
}
|
2008-04-01 17:37:17 +02:00
|
|
|
|
2019-09-12 19:23:26 +02:00
|
|
|
stack = setup_exception_record( context, stack_ptr, fs, gs );
|
|
|
|
if (stack->rec.ExceptionCode == EXCEPTION_STACK_OVERFLOW) goto done;
|
2003-05-06 20:50:08 +02:00
|
|
|
|
2006-08-11 14:45:11 +02:00
|
|
|
switch(get_trap_code(context))
|
2003-10-28 01:30:55 +01:00
|
|
|
{
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_OFLOW: /* Overflow exception */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_INT_OVERFLOW;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_BOUND: /* Bound range exception */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_PRIVINFLT: /* Invalid opcode exception */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_STKFLT: /* Stack fault */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_STACK_OVERFLOW;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_SEGNPFLT: /* Segment not present exception */
|
|
|
|
case TRAP_x86_PROTFLT: /* General protection fault */
|
|
|
|
case TRAP_x86_UNKNOWN: /* Unknown fault code */
|
2005-12-16 16:27:39 +01:00
|
|
|
{
|
2006-08-11 14:45:11 +02:00
|
|
|
WORD err = get_error_code(context);
|
2019-09-12 19:20:14 +02:00
|
|
|
if (!err && (stack->rec.ExceptionCode = is_privileged_instr( &stack->context ))) break;
|
2019-09-12 19:48:48 +02:00
|
|
|
if ((err & 7) == 2 && handle_interrupt( err >> 3, context, stack )) return;
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
|
|
|
|
stack->rec.NumberParameters = 2;
|
|
|
|
stack->rec.ExceptionInformation[0] = 0;
|
2005-12-16 16:27:39 +01:00
|
|
|
/* if error contains a LDT selector, use that as fault address */
|
2007-03-14 12:02:43 +01:00
|
|
|
if ((err & 7) == 4 && !wine_ldt_is_system( err | 7 ))
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionInformation[1] = err & ~7;
|
2007-03-14 12:02:43 +01:00
|
|
|
else
|
2019-09-12 20:00:48 +02:00
|
|
|
{
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionInformation[1] = 0xffffffff;
|
2019-09-12 20:00:48 +02:00
|
|
|
if (check_invalid_gs( context, &stack->context )) return;
|
|
|
|
}
|
2005-12-16 16:27:39 +01:00
|
|
|
}
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_PAGEFLT: /* Page fault */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.NumberParameters = 2;
|
|
|
|
stack->rec.ExceptionInformation[0] = (get_error_code(context) >> 1) & 0x09;
|
|
|
|
stack->rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
|
2019-09-12 20:50:16 +02:00
|
|
|
stack->rec.ExceptionCode = virtual_handle_fault( (void *)stack->rec.ExceptionInformation[1],
|
|
|
|
stack->rec.ExceptionInformation[0], FALSE );
|
|
|
|
if (!stack->rec.ExceptionCode) return;
|
|
|
|
if (stack->rec.ExceptionCode == EXCEPTION_ACCESS_VIOLATION &&
|
|
|
|
stack->rec.ExceptionInformation[0] == EXCEPTION_EXECUTE_FAULT)
|
|
|
|
{
|
|
|
|
ULONG flags;
|
|
|
|
NtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
|
|
|
|
&flags, sizeof(flags), NULL );
|
|
|
|
if (!(flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION) && check_atl_thunk( context, stack ))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* send EXCEPTION_EXECUTE_FAULT only if data execution prevention is enabled */
|
|
|
|
if (!(flags & MEM_EXECUTE_OPTION_DISABLE))
|
|
|
|
stack->rec.ExceptionInformation[0] = EXCEPTION_READ_FAULT;
|
|
|
|
}
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_ALIGNFLT: /* Alignment check exception */
|
2019-09-12 19:34:04 +02:00
|
|
|
/* FIXME: pass through exception handler first? */
|
|
|
|
if (stack->context.EFlags & 0x00040000)
|
|
|
|
{
|
|
|
|
EFL_sig(context) &= ~0x00040000; /* disable AC flag */
|
|
|
|
return;
|
|
|
|
}
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
|
|
|
default:
|
2007-03-14 09:53:59 +01:00
|
|
|
WINE_ERR( "Got unexpected trap %d\n", get_trap_code(context) );
|
2003-10-28 01:30:55 +01:00
|
|
|
/* fall through */
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_NMI: /* NMI interrupt */
|
|
|
|
case TRAP_x86_DNA: /* Device not available exception */
|
|
|
|
case TRAP_x86_DOUBLEFLT: /* Double fault exception */
|
|
|
|
case TRAP_x86_TSSFLT: /* Invalid TSS exception */
|
|
|
|
case TRAP_x86_MCHK: /* Machine check exception */
|
|
|
|
case TRAP_x86_CACHEFLT: /* Cache flush exception */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-09-12 19:23:26 +02:00
|
|
|
done:
|
2019-09-12 21:02:29 +02:00
|
|
|
setup_raise_exception( context, stack );
|
2000-09-18 04:15:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* trap_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGTRAP.
|
|
|
|
*/
|
2006-08-11 14:45:11 +02:00
|
|
|
static void trap_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2000-09-18 04:15:07 +02:00
|
|
|
{
|
2014-07-23 16:32:33 +02:00
|
|
|
ucontext_t *context = sigcontext;
|
2019-09-12 19:23:26 +02:00
|
|
|
struct stack_layout *stack = setup_exception( context );
|
2003-10-28 01:30:55 +01:00
|
|
|
|
2006-08-11 14:45:11 +02:00
|
|
|
switch(get_trap_code(context))
|
2003-10-28 01:30:55 +01:00
|
|
|
{
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_TRCTRAP: /* Single-step exception */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_SINGLE_STEP;
|
2019-09-12 19:27:05 +02:00
|
|
|
/* when single stepping can't tell whether this is a hw bp or a
|
|
|
|
* single step interrupt. try to avoid as much overhead as possible
|
|
|
|
* and only do a server call if there is any hw bp enabled. */
|
|
|
|
if (!(stack->context.EFlags & 0x100) || (stack->context.Dr7 & 0xff))
|
|
|
|
{
|
|
|
|
/* (possible) hardware breakpoint, fetch the debug registers */
|
|
|
|
DWORD saved_flags = stack->context.ContextFlags;
|
|
|
|
stack->context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
|
|
|
|
NtGetContextThread( GetCurrentThread(), &stack->context );
|
|
|
|
stack->context.ContextFlags |= saved_flags; /* restore flags */
|
|
|
|
}
|
|
|
|
stack->context.EFlags &= ~0x100; /* clear single-step flag */
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_BPTFLT: /* Breakpoint exception */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionAddress = (char *)stack->rec.ExceptionAddress - 1; /* back up over the int3 instruction */
|
2003-10-28 01:30:55 +01:00
|
|
|
/* fall through */
|
|
|
|
default:
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_BREAKPOINT;
|
|
|
|
stack->rec.NumberParameters = is_wow64 ? 1 : 3;
|
|
|
|
stack->rec.ExceptionInformation[0] = 0;
|
|
|
|
stack->rec.ExceptionInformation[1] = 0; /* FIXME */
|
|
|
|
stack->rec.ExceptionInformation[2] = 0; /* FIXME */
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-09-12 21:02:29 +02:00
|
|
|
setup_raise_exception( context, stack );
|
2000-09-18 04:15:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* fpe_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGFPE.
|
|
|
|
*/
|
2006-08-11 14:45:11 +02:00
|
|
|
static void fpe_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2000-09-18 04:15:07 +02:00
|
|
|
{
|
2014-07-23 16:32:33 +02:00
|
|
|
ucontext_t *context = sigcontext;
|
2019-09-12 19:23:26 +02:00
|
|
|
struct stack_layout *stack = setup_exception( context );
|
2003-10-28 01:30:55 +01:00
|
|
|
|
2006-08-11 14:45:11 +02:00
|
|
|
switch(get_trap_code(context))
|
2003-10-28 01:30:55 +01:00
|
|
|
{
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_DIVIDE: /* Division by zero exception */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_FPOPFLT: /* Coprocessor segment overrun */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_ARITHTRAP: /* Floating point exception */
|
|
|
|
case TRAP_x86_UNKNOWN: /* Unknown fault code */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = get_fpu_code( &stack->context );
|
|
|
|
stack->rec.ExceptionAddress = (LPVOID)stack->context.FloatSave.ErrorOffset;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2007-03-08 22:48:14 +01:00
|
|
|
case TRAP_x86_CACHEFLT: /* SIMD exception */
|
|
|
|
/* TODO:
|
|
|
|
* Behaviour only tested for divide-by-zero exceptions
|
|
|
|
* Check for other SIMD exceptions as well */
|
2015-12-02 17:07:18 +01:00
|
|
|
if(siginfo->si_code != FPE_FLTDIV && siginfo->si_code != FPE_FLTINV)
|
2007-03-08 22:48:14 +01:00
|
|
|
FIXME("untested SIMD exception: %#x. Might not work correctly\n",
|
|
|
|
siginfo->si_code);
|
|
|
|
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = STATUS_FLOAT_MULTIPLE_TRAPS;
|
|
|
|
stack->rec.NumberParameters = 1;
|
2007-09-27 18:57:51 +02:00
|
|
|
/* no idea what meaning is actually behind this but that's what native does */
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionInformation[0] = 0;
|
2007-03-08 22:48:14 +01:00
|
|
|
break;
|
2003-10-28 01:30:55 +01:00
|
|
|
default:
|
2007-03-14 09:53:59 +01:00
|
|
|
WINE_ERR( "Got unexpected trap %d\n", get_trap_code(context) );
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-09-12 19:23:26 +02:00
|
|
|
|
2019-09-12 21:02:29 +02:00
|
|
|
setup_raise_exception( context, stack );
|
1999-09-27 12:58:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* int_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGINT.
|
2005-11-02 21:54:12 +01:00
|
|
|
*
|
|
|
|
* FIXME: should not be calling external functions on the signal stack.
|
1999-09-27 12:58:45 +02:00
|
|
|
*/
|
2006-08-11 14:45:11 +02:00
|
|
|
static void int_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
1999-09-27 12:58:45 +02:00
|
|
|
{
|
2005-11-02 21:54:12 +01:00
|
|
|
WORD fs, gs;
|
2019-09-13 16:58:28 +02:00
|
|
|
void *stack_ptr = init_handler( sigcontext, &fs, &gs );
|
2002-07-31 20:46:09 +02:00
|
|
|
if (!dispatch_signal(SIGINT))
|
2002-06-02 23:22:22 +02:00
|
|
|
{
|
2019-09-13 16:58:28 +02:00
|
|
|
struct stack_layout *stack = setup_exception_record( sigcontext, stack_ptr, fs, gs );
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = CONTROL_C_EXIT;
|
2019-09-12 21:02:29 +02:00
|
|
|
setup_raise_exception( sigcontext, stack );
|
2002-06-02 23:22:22 +02:00
|
|
|
}
|
1999-09-27 12:58:45 +02:00
|
|
|
}
|
|
|
|
|
2002-10-29 00:56:58 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* abrt_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGABRT.
|
|
|
|
*/
|
2006-08-11 14:45:11 +02:00
|
|
|
static void abrt_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2002-10-29 00:56:58 +01:00
|
|
|
{
|
2019-09-12 19:23:26 +02:00
|
|
|
struct stack_layout *stack = setup_exception( sigcontext );
|
2019-09-12 19:20:14 +02:00
|
|
|
stack->rec.ExceptionCode = EXCEPTION_WINE_ASSERTION;
|
|
|
|
stack->rec.ExceptionFlags = EH_NONCONTINUABLE;
|
2019-09-12 21:02:29 +02:00
|
|
|
setup_raise_exception( sigcontext, stack );
|
2002-10-29 00:56:58 +01:00
|
|
|
}
|
|
|
|
|
1999-09-27 12:58:45 +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
|
|
|
*/
|
2007-12-20 12:19:35 +01:00
|
|
|
static void quit_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2003-03-22 00:45:26 +01:00
|
|
|
{
|
2005-11-02 21:54:12 +01:00
|
|
|
WORD fs, gs;
|
2006-08-11 14:45:11 +02:00
|
|
|
init_handler( sigcontext, &fs, &gs );
|
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.
|
|
|
|
*/
|
2006-08-11 14:45:11 +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;
|
2006-08-11 14:45:11 +02:00
|
|
|
WORD fs, gs;
|
2003-04-04 01:57:11 +02:00
|
|
|
|
2006-08-11 14:45:11 +02:00
|
|
|
init_handler( sigcontext, &fs, &gs );
|
|
|
|
save_context( &context, sigcontext, fs, gs );
|
2005-11-02 21:54:12 +01:00
|
|
|
wait_suspend( &context );
|
2006-08-11 14:45:11 +02:00
|
|
|
restore_context( &context, sigcontext );
|
2003-03-04 23:18:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-19 12:25:52 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* __wine_set_signal_handler (NTDLL.@)
|
|
|
|
*/
|
|
|
|
int CDECL __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh)
|
|
|
|
{
|
2018-08-02 21:54:37 +02:00
|
|
|
if (sig >= ARRAY_SIZE(handlers)) return -1;
|
2009-11-19 12:25:52 +01:00
|
|
|
if (handlers[sig] != NULL) return -2;
|
|
|
|
handlers[sig] = wsh;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-29 22:10:50 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* locking for LDT routines
|
|
|
|
*/
|
|
|
|
static RTL_CRITICAL_SECTION ldt_section;
|
|
|
|
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &ldt_section,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": ldt_section") }
|
|
|
|
};
|
|
|
|
static RTL_CRITICAL_SECTION ldt_section = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
static sigset_t ldt_sigset;
|
|
|
|
|
|
|
|
static void ldt_lock(void)
|
|
|
|
{
|
|
|
|
sigset_t sigset;
|
|
|
|
|
|
|
|
pthread_sigmask( SIG_BLOCK, &server_block_set, &sigset );
|
|
|
|
RtlEnterCriticalSection( &ldt_section );
|
|
|
|
if (ldt_section.RecursionCount == 1) ldt_sigset = sigset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ldt_unlock(void)
|
|
|
|
{
|
|
|
|
if (ldt_section.RecursionCount == 1)
|
|
|
|
{
|
|
|
|
sigset_t sigset = ldt_sigset;
|
|
|
|
RtlLeaveCriticalSection( &ldt_section );
|
|
|
|
pthread_sigmask( SIG_SETMASK, &sigset, NULL );
|
|
|
|
}
|
|
|
|
else RtlLeaveCriticalSection( &ldt_section );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-14 12:36:58 +02:00
|
|
|
/**********************************************************************
|
2009-11-19 12:25:52 +01:00
|
|
|
* signal_alloc_thread
|
2005-09-14 12:36:58 +02:00
|
|
|
*/
|
2009-11-19 12:25:52 +01:00
|
|
|
NTSTATUS signal_alloc_thread( TEB **teb )
|
2005-09-14 12:36:58 +02:00
|
|
|
{
|
2019-06-13 12:48:31 +02:00
|
|
|
static size_t sigstack_alignment;
|
2017-07-19 15:14:24 +02:00
|
|
|
struct x86_thread_data *thread_data;
|
2009-11-19 12:25:52 +01:00
|
|
|
SIZE_T size;
|
|
|
|
void *addr = NULL;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2019-06-13 12:48:31 +02:00
|
|
|
if (!sigstack_alignment)
|
2005-09-14 12:36:58 +02:00
|
|
|
{
|
2009-11-19 12:25:52 +01:00
|
|
|
size_t min_size = teb_size + max( MINSIGSTKSZ, 8192 );
|
2005-09-14 12:36:58 +02:00
|
|
|
/* find the first power of two not smaller than min_size */
|
2019-06-13 12:48:31 +02:00
|
|
|
sigstack_alignment = 12;
|
|
|
|
while ((1u << sigstack_alignment) < min_size) sigstack_alignment++;
|
|
|
|
signal_stack_mask = (1 << sigstack_alignment) - 1;
|
|
|
|
signal_stack_size = (1 << sigstack_alignment) - teb_size;
|
2005-09-14 12:36:58 +02:00
|
|
|
}
|
2009-11-19 12:25:52 +01:00
|
|
|
|
|
|
|
size = signal_stack_mask + 1;
|
2019-06-13 12:48:31 +02:00
|
|
|
if (!(status = virtual_alloc_aligned( &addr, 0, &size, MEM_COMMIT | MEM_TOP_DOWN,
|
|
|
|
PAGE_READWRITE, sigstack_alignment )))
|
2009-11-19 12:25:52 +01:00
|
|
|
{
|
|
|
|
*teb = addr;
|
|
|
|
(*teb)->Tib.Self = &(*teb)->Tib;
|
|
|
|
(*teb)->Tib.ExceptionList = (void *)~0UL;
|
2017-07-19 15:14:24 +02:00
|
|
|
thread_data = (struct x86_thread_data *)(*teb)->SystemReserved2;
|
2009-11-19 12:25:52 +01:00
|
|
|
if (!(thread_data->fs = wine_ldt_alloc_fs()))
|
|
|
|
{
|
|
|
|
size = 0;
|
|
|
|
NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
|
|
|
|
status = STATUS_TOO_MANY_THREADS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
2005-09-14 12:36:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-19 12:25:52 +01:00
|
|
|
/**********************************************************************
|
|
|
|
* signal_free_thread
|
2002-07-31 20:46:09 +02:00
|
|
|
*/
|
2009-11-19 12:25:52 +01:00
|
|
|
void signal_free_thread( TEB *teb )
|
2002-07-31 20:46:09 +02:00
|
|
|
{
|
2017-11-29 10:43:39 +01:00
|
|
|
SIZE_T size = 0;
|
2017-07-19 15:14:24 +02:00
|
|
|
struct x86_thread_data *thread_data = (struct x86_thread_data *)teb->SystemReserved2;
|
2009-11-19 12:25:52 +01:00
|
|
|
|
2017-11-29 10:43:39 +01:00
|
|
|
wine_ldt_free_fs( thread_data->fs );
|
2009-11-19 12:25:52 +01:00
|
|
|
NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
|
2002-07-31 20:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
/**********************************************************************
|
2008-07-03 20:18:23 +02:00
|
|
|
* signal_init_thread
|
1999-09-27 12:58:45 +02:00
|
|
|
*/
|
2009-02-18 13:04:50 +01:00
|
|
|
void signal_init_thread( TEB *teb )
|
1999-09-27 12:58:45 +02:00
|
|
|
{
|
2010-06-22 11:19:02 +02:00
|
|
|
const WORD fpu_cw = 0x27f;
|
2017-07-19 15:14:24 +02:00
|
|
|
struct x86_thread_data *thread_data = (struct x86_thread_data *)teb->SystemReserved2;
|
2009-02-18 13:04:50 +01:00
|
|
|
LDT_ENTRY fs_entry;
|
2007-03-12 16:14:18 +01:00
|
|
|
stack_t ss;
|
2006-09-07 18:08:46 +02:00
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
int mib[2], val = 1;
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_THALTSTACK;
|
|
|
|
sysctl( mib, 2, NULL, NULL, &val, sizeof(val) );
|
|
|
|
#endif
|
|
|
|
|
2009-02-18 13:04:50 +01:00
|
|
|
ss.ss_sp = (char *)teb + teb_size;
|
2005-09-14 12:36:58 +02:00
|
|
|
ss.ss_size = signal_stack_size;
|
2003-10-22 05:26:53 +02:00
|
|
|
ss.ss_flags = 0;
|
2008-07-03 20:18:23 +02:00
|
|
|
if (sigaltstack(&ss, NULL) == -1) perror( "sigaltstack" );
|
2008-07-08 20:54:40 +02:00
|
|
|
|
2009-02-18 13:04:50 +01:00
|
|
|
wine_ldt_set_base( &fs_entry, teb );
|
|
|
|
wine_ldt_set_limit( &fs_entry, teb_size - 1 );
|
|
|
|
wine_ldt_set_flags( &fs_entry, WINE_LDT_FLAGS_DATA|WINE_LDT_FLAGS_32BIT );
|
|
|
|
wine_ldt_init_fs( thread_data->fs, &fs_entry );
|
|
|
|
thread_data->gs = wine_get_gs();
|
2010-06-17 10:17:15 +02:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
2010-06-22 11:19:02 +02:00
|
|
|
__asm__ volatile ("fninit; fldcw %0" : : "m" (fpu_cw));
|
2010-06-17 10:17:15 +02:00
|
|
|
#else
|
2010-06-22 11:19:02 +02:00
|
|
|
FIXME("FPU setup not implemented for this platform.\n");
|
2010-06-17 10:17:15 +02:00
|
|
|
#endif
|
2008-07-03 20:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* signal_init_process
|
|
|
|
*/
|
2017-11-29 17:11:10 +01:00
|
|
|
void signal_init_process(void)
|
2008-07-03 20:18:23 +02:00
|
|
|
{
|
|
|
|
struct sigaction sig_act;
|
2001-06-15 21:43:15 +02:00
|
|
|
|
2007-01-18 12:20:56 +01:00
|
|
|
sig_act.sa_mask = server_block_set;
|
2006-08-07 16:45:45 +02:00
|
|
|
sig_act.sa_flags = SA_SIGINFO | SA_RESTART;
|
|
|
|
#ifdef SA_ONSTACK
|
|
|
|
sig_act.sa_flags |= SA_ONSTACK;
|
|
|
|
#endif
|
2014-07-17 14:51:12 +02:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
sig_act.sa_flags |= SA_RESTORER;
|
|
|
|
sig_act.sa_restorer = rt_sigreturn;
|
|
|
|
#endif
|
2006-08-11 14:45:11 +02:00
|
|
|
sig_act.sa_sigaction = int_handler;
|
2006-08-07 16:45:45 +02:00
|
|
|
if (sigaction( SIGINT, &sig_act, NULL ) == -1) goto error;
|
2006-08-11 14:45:11 +02:00
|
|
|
sig_act.sa_sigaction = fpe_handler;
|
2006-08-07 16:45:45 +02:00
|
|
|
if (sigaction( SIGFPE, &sig_act, NULL ) == -1) goto error;
|
2006-08-11 14:45:11 +02:00
|
|
|
sig_act.sa_sigaction = abrt_handler;
|
2006-08-07 16:45:45 +02:00
|
|
|
if (sigaction( SIGABRT, &sig_act, NULL ) == -1) goto error;
|
2007-12-20 12:19:35 +01:00
|
|
|
sig_act.sa_sigaction = quit_handler;
|
|
|
|
if (sigaction( SIGQUIT, &sig_act, NULL ) == -1) goto error;
|
2006-08-11 14:45:11 +02:00
|
|
|
sig_act.sa_sigaction = usr1_handler;
|
2006-08-07 16:45:45 +02:00
|
|
|
if (sigaction( SIGUSR1, &sig_act, NULL ) == -1) goto error;
|
|
|
|
|
2006-08-11 14:45:11 +02:00
|
|
|
sig_act.sa_sigaction = segv_handler;
|
2006-08-07 16:45:45 +02:00
|
|
|
if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error;
|
|
|
|
if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error;
|
1999-09-27 12:58:45 +02:00
|
|
|
#ifdef SIGBUS
|
2006-08-07 16:45:45 +02:00
|
|
|
if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error;
|
1999-09-27 12:58:45 +02:00
|
|
|
#endif
|
2006-08-07 16:45:45 +02:00
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
#ifdef SIGTRAP
|
2006-08-11 14:45:11 +02:00
|
|
|
sig_act.sa_sigaction = trap_handler;
|
2006-08-07 16:45:45 +02:00
|
|
|
if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
|
1999-09-27 12:58:45 +02:00
|
|
|
#endif
|
2001-06-25 23:08:47 +02:00
|
|
|
|
2009-12-29 22:10:50 +01:00
|
|
|
wine_ldt_init_locking( ldt_lock, ldt_unlock );
|
2008-07-03 20:18:23 +02:00
|
|
|
return;
|
1999-09-27 12:58:45 +02:00
|
|
|
|
|
|
|
error:
|
|
|
|
perror("sigaction");
|
2008-07-03 20:18:23 +02:00
|
|
|
exit(1);
|
1999-09-27 12:58:45 +02:00
|
|
|
}
|
|
|
|
|
2000-09-18 04:15:07 +02: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 );
|
|
|
|
}
|
2017-07-24 10:59:45 +02:00
|
|
|
|
|
|
|
NtSetContextThread( GetCurrentThread(), context );
|
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
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* NtRaiseException (NTDLL.@)
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL first_chance )
|
|
|
|
{
|
2019-09-18 18:09:11 +02:00
|
|
|
if (first_chance)
|
|
|
|
{
|
|
|
|
NTSTATUS status = send_debug_event( rec, TRUE, context );
|
|
|
|
if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
|
|
|
|
NtSetContextThread( GetCurrentThread(), context );
|
|
|
|
}
|
|
|
|
return raise_exception( rec, context, first_chance );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 19:18:44 +01:00
|
|
|
extern void DECLSPEC_NORETURN start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend,
|
2017-12-15 12:36:16 +01:00
|
|
|
void *relay );
|
2017-12-01 19:18:44 +01:00
|
|
|
__ASM_GLOBAL_FUNC( start_thread,
|
2011-10-19 12:59:58 +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")
|
|
|
|
"pushl %esi\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
|
|
|
|
"pushl %edi\n\t"
|
|
|
|
__ASM_CFI(".cfi_rel_offset %edi,-12\n\t")
|
2017-12-01 19:18:44 +01:00
|
|
|
/* store exit frame */
|
2017-12-15 12:36:16 +01:00
|
|
|
"movl %ebp,%fs:0x1f4\n\t" /* x86_thread_data()->exit_frame */
|
2017-12-04 13:56:32 +01:00
|
|
|
/* switch to thread stack */
|
2018-01-22 15:14:56 +01:00
|
|
|
"movl %fs:4,%eax\n\t" /* NtCurrentTeb()->StackBase */
|
|
|
|
"leal -0x1000(%eax),%esp\n\t"
|
2017-12-04 13:56:32 +01:00
|
|
|
/* attach dlls */
|
2018-01-22 15:14:56 +01:00
|
|
|
"pushl 20(%ebp)\n\t" /* relay */
|
2017-12-01 19:18:44 +01:00
|
|
|
"pushl 16(%ebp)\n\t" /* suspend */
|
2018-01-22 15:14:56 +01:00
|
|
|
"pushl 12(%ebp)\n\t" /* arg */
|
|
|
|
"pushl 8(%ebp)\n\t" /* entry */
|
2017-12-01 19:18:44 +01:00
|
|
|
"xorl %ebp,%ebp\n\t"
|
2018-01-22 15:14:56 +01:00
|
|
|
"call " __ASM_NAME("attach_thread") "\n\t"
|
|
|
|
"movl %eax,%esi\n\t"
|
|
|
|
"leal -12(%eax),%esp\n\t"
|
2017-12-04 13:56:32 +01:00
|
|
|
/* clear the stack */
|
2018-01-22 15:14:56 +01:00
|
|
|
"andl $~0xfff,%eax\n\t" /* round down to page size */
|
|
|
|
"movl %eax,(%esp)\n\t"
|
2017-12-04 13:56:32 +01:00
|
|
|
"call " __ASM_NAME("virtual_clear_thread_stack") "\n\t"
|
|
|
|
/* switch to the initial context */
|
|
|
|
"movl %esi,(%esp)\n\t"
|
|
|
|
"call " __ASM_NAME("set_cpu_context") )
|
2011-10-19 12:59:58 +02:00
|
|
|
|
2017-12-15 12:36:16 +01:00
|
|
|
extern void DECLSPEC_NORETURN call_thread_exit_func( int status, void (*func)(int) );
|
2011-10-19 12:59:58 +02:00
|
|
|
__ASM_GLOBAL_FUNC( call_thread_exit_func,
|
2018-02-06 16:06:42 +01:00
|
|
|
"movl 8(%esp),%ecx\n\t"
|
2017-12-15 12:36:16 +01:00
|
|
|
/* fetch exit frame */
|
|
|
|
"movl %fs:0x1f4,%edx\n\t" /* x86_thread_data()->exit_frame */
|
|
|
|
"testl %edx,%edx\n\t"
|
|
|
|
"jnz 1f\n\t"
|
|
|
|
"jmp *%ecx\n\t"
|
|
|
|
/* switch to exit frame stack */
|
|
|
|
"1:\tmovl 4(%esp),%eax\n\t"
|
|
|
|
"movl $0,%fs:0x1f4\n\t"
|
|
|
|
"movl %edx,%ebp\n\t"
|
2011-10-19 12:59:58 +02:00
|
|
|
__ASM_CFI(".cfi_def_cfa %ebp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebx,-4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %edi,-12\n\t")
|
|
|
|
"leal -20(%ebp),%esp\n\t"
|
|
|
|
"pushl %eax\n\t"
|
2017-12-15 12:36:16 +01:00
|
|
|
"call *%ecx" )
|
2011-10-19 12:59:58 +02:00
|
|
|
|
2017-12-01 19:18:44 +01:00
|
|
|
extern void call_thread_entry(void) DECLSPEC_HIDDEN;
|
|
|
|
__ASM_GLOBAL_FUNC( call_thread_entry,
|
|
|
|
"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" /* arg */
|
|
|
|
"pushl %eax\n\t" /* entry */
|
|
|
|
"call " __ASM_NAME("call_thread_func") )
|
|
|
|
|
2009-06-18 16:38:30 +02:00
|
|
|
/* wrapper for apps that don't declare the thread function correctly */
|
2017-12-01 19:18:44 +01:00
|
|
|
extern DWORD call_thread_func_wrapper( LPTHREAD_START_ROUTINE entry, void *arg );
|
2011-10-19 12:59:58 +02:00
|
|
|
__ASM_GLOBAL_FUNC(call_thread_func_wrapper,
|
2009-06-18 16:38:30 +02:00
|
|
|
"pushl %ebp\n\t"
|
2009-06-25 12:02:53 +02:00
|
|
|
__ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
|
|
|
|
__ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
|
2009-06-18 16:38:30 +02:00
|
|
|
"movl %esp,%ebp\n\t"
|
2009-06-25 12:02:53 +02:00
|
|
|
__ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
|
2009-06-18 16:38:30 +02:00
|
|
|
"subl $4,%esp\n\t"
|
|
|
|
"pushl 12(%ebp)\n\t"
|
|
|
|
"call *8(%ebp)\n\t"
|
2017-12-01 19:18:44 +01:00
|
|
|
"leave\n\t"
|
|
|
|
__ASM_CFI(".cfi_def_cfa %esp,4\n\t")
|
|
|
|
__ASM_CFI(".cfi_same_value %ebp\n\t")
|
|
|
|
"ret" )
|
2009-06-18 16:38:30 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2011-10-19 12:59:58 +02:00
|
|
|
* call_thread_func
|
2009-06-18 16:38:30 +02:00
|
|
|
*/
|
2017-12-01 19:18:44 +01:00
|
|
|
void DECLSPEC_HIDDEN call_thread_func( LPTHREAD_START_ROUTINE entry, void *arg )
|
2009-06-18 16:38:30 +02:00
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
2017-12-01 19:18:44 +01:00
|
|
|
TRACE_(relay)( "\1Starting thread proc %p (arg=%p)\n", entry, arg );
|
|
|
|
RtlExitUserThread( call_thread_func_wrapper( 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-01 19:18:44 +01:00
|
|
|
|
2018-01-22 15:14:56 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* init_thread_context
|
|
|
|
*/
|
|
|
|
static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry, void *arg, void *relay )
|
|
|
|
{
|
|
|
|
context->SegCs = wine_get_cs();
|
|
|
|
context->SegDs = wine_get_ds();
|
|
|
|
context->SegEs = wine_get_es();
|
|
|
|
context->SegFs = wine_get_fs();
|
|
|
|
context->SegGs = wine_get_gs();
|
|
|
|
context->SegSs = wine_get_ss();
|
|
|
|
context->EFlags = 0x202;
|
|
|
|
context->Eax = (DWORD)entry;
|
|
|
|
context->Ebx = (DWORD)arg;
|
|
|
|
context->Esp = (DWORD)NtCurrentTeb()->Tib.StackBase - 16;
|
|
|
|
context->Eip = (DWORD)relay;
|
|
|
|
context->FloatSave.ControlWord = 0x27f;
|
|
|
|
((XMM_SAVE_AREA32 *)context->ExtendedRegisters)->ControlWord = 0x27f;
|
2019-11-02 14:34:17 +01:00
|
|
|
((XMM_SAVE_AREA32 *)context->ExtendedRegisters)->MxCsr = 0x1f80;
|
2018-01-22 15:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* attach_thread
|
|
|
|
*/
|
|
|
|
PCONTEXT DECLSPEC_HIDDEN attach_thread( LPTHREAD_START_ROUTINE entry, void *arg,
|
|
|
|
BOOL suspend, void *relay )
|
|
|
|
{
|
|
|
|
CONTEXT *ctx;
|
|
|
|
|
|
|
|
if (suspend)
|
|
|
|
{
|
|
|
|
CONTEXT context = { CONTEXT_ALL };
|
|
|
|
|
|
|
|
init_thread_context( &context, entry, arg, relay );
|
|
|
|
wait_suspend( &context );
|
|
|
|
ctx = (CONTEXT *)((ULONG_PTR)context.Esp & ~15) - 1;
|
|
|
|
*ctx = context;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ctx = (CONTEXT *)((char *)NtCurrentTeb()->Tib.StackBase - 16) - 1;
|
|
|
|
init_thread_context( ctx, entry, arg, relay );
|
|
|
|
}
|
2019-11-02 14:34:17 +01:00
|
|
|
ctx->ContextFlags = CONTEXT_FULL | CONTEXT_FLOATING_POINT | CONTEXT_EXTENDED_REGISTERS;
|
2019-02-14 16:49:09 +01:00
|
|
|
LdrInitializeThunk( ctx, (void **)&ctx->Eax, 0, 0 );
|
2018-01-22 15:14:56 +01:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 19:18:44 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* signal_start_thread
|
|
|
|
*
|
|
|
|
* Thread startup sequence:
|
|
|
|
* signal_start_thread()
|
|
|
|
* -> start_thread()
|
2017-12-04 13:56:32 +01:00
|
|
|
* -> call_thread_entry()
|
|
|
|
* -> call_thread_func()
|
2017-12-01 19:18:44 +01:00
|
|
|
*/
|
|
|
|
void signal_start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend )
|
|
|
|
{
|
2017-12-15 12:36:16 +01:00
|
|
|
start_thread( entry, arg, suspend, call_thread_entry );
|
2017-12-01 19:18:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* signal_start_process
|
|
|
|
*
|
|
|
|
* Process startup sequence:
|
|
|
|
* signal_start_process()
|
|
|
|
* -> start_thread()
|
2017-12-04 13:56:32 +01:00
|
|
|
* -> kernel32_start_process()
|
2017-12-01 19:18:44 +01:00
|
|
|
*/
|
|
|
|
void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend )
|
|
|
|
{
|
2017-12-15 12:36:16 +01:00
|
|
|
start_thread( entry, NtCurrentTeb()->Peb, suspend, kernel32_start_process );
|
2017-12-01 19:18:44 +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
|
|
|
{
|
2017-12-15 12:36:16 +01:00
|
|
|
call_thread_exit_func( status, exit_thread );
|
2009-06-18 16:50:34 +02:00
|
|
|
}
|
2009-06-18 16:38:30 +02:00
|
|
|
|
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-15 12:36:16 +01:00
|
|
|
call_thread_exit_func( status, exit );
|
2009-08-28 11:52:21 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC( DbgBreakPoint, 0, "int $3; ret")
|
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
|
|
|
*/
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC( DbgUserBreakPoint, 0, "int $3; ret")
|
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.@)
|
|
|
|
*/
|
|
|
|
__ASM_STDCALL_FUNC( _chkstk, 0,
|
|
|
|
"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.@)
|
|
|
|
*/
|
|
|
|
__ASM_STDCALL_FUNC( _alloca_probe, 0,
|
|
|
|
"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__ */
|