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-09-18 04:15:07 +02:00
|
|
|
#ifdef HAVE_SYS_VM86_H
|
|
|
|
# include <sys/vm86.h>
|
|
|
|
#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
|
2000-11-29 21:04:09 +01:00
|
|
|
|
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 */
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef linux
|
|
|
|
|
2006-08-11 14:14:38 +02:00
|
|
|
typedef ucontext_t SIGCONTEXT;
|
2006-08-05 22:34:11 +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
|
|
|
|
2002-01-04 22:57:04 +01:00
|
|
|
#define VM86_EAX 0 /* the %eax value while vm86_enter is executing */
|
2008-06-02 12:13:33 +02:00
|
|
|
#define VIF_FLAG 0x00080000
|
|
|
|
#define VIP_FLAG 0x00100000
|
2002-01-04 22:57:04 +01:00
|
|
|
|
|
|
|
int vm86_enter( void **vm86_ptr );
|
|
|
|
void vm86_return(void);
|
|
|
|
void vm86_return_end(void);
|
2000-09-24 05:11:54 +02:00
|
|
|
__ASM_GLOBAL_FUNC(vm86_enter,
|
|
|
|
"pushl %ebp\n\t"
|
|
|
|
"movl %esp, %ebp\n\t"
|
|
|
|
"movl $166,%eax\n\t" /*SYS_vm86*/
|
2002-01-04 22:57:04 +01:00
|
|
|
"movl 8(%ebp),%ecx\n\t" /* vm86_ptr */
|
|
|
|
"movl (%ecx),%ecx\n\t"
|
2000-09-24 05:11:54 +02:00
|
|
|
"pushl %ebx\n\t"
|
|
|
|
"movl $1,%ebx\n\t" /*VM86_ENTER*/
|
|
|
|
"pushl %ecx\n\t" /* put vm86plus_struct ptr somewhere we can find it */
|
2000-12-29 04:29:31 +01:00
|
|
|
"pushl %fs\n\t"
|
2003-11-05 01:52:29 +01:00
|
|
|
"pushl %gs\n\t"
|
2000-09-24 05:11:54 +02:00
|
|
|
"int $0x80\n"
|
|
|
|
".globl " __ASM_NAME("vm86_return") "\n\t"
|
2002-07-22 22:47:11 +02:00
|
|
|
__ASM_FUNC("vm86_return") "\n"
|
2000-09-24 05:11:54 +02:00
|
|
|
__ASM_NAME("vm86_return") ":\n\t"
|
2003-03-25 01:36:16 +01:00
|
|
|
"popl %gs\n\t"
|
2003-11-05 01:52:29 +01:00
|
|
|
"popl %fs\n\t"
|
2000-09-24 05:11:54 +02:00
|
|
|
"popl %ecx\n\t"
|
|
|
|
"popl %ebx\n\t"
|
|
|
|
"popl %ebp\n\t"
|
2002-01-04 22:57:04 +01:00
|
|
|
"testl %eax,%eax\n\t"
|
|
|
|
"jl 0f\n\t"
|
|
|
|
"cmpb $0,%al\n\t" /* VM86_SIGNAL */
|
|
|
|
"je " __ASM_NAME("vm86_enter") "\n\t"
|
|
|
|
"0:\n\t"
|
|
|
|
"movl 4(%esp),%ecx\n\t" /* vm86_ptr */
|
|
|
|
"movl $0,(%ecx)\n\t"
|
|
|
|
".globl " __ASM_NAME("vm86_return_end") "\n\t"
|
2002-07-22 22:47:11 +02:00
|
|
|
__ASM_FUNC("vm86_return_end") "\n"
|
2002-01-04 22:57:04 +01:00
|
|
|
__ASM_NAME("vm86_return_end") ":\n\t"
|
2007-01-13 00:38:07 +01:00
|
|
|
"ret" )
|
2000-09-18 04:15:07 +02:00
|
|
|
|
2002-11-08 19:53:32 +01:00
|
|
|
#ifdef HAVE_SYS_VM86_H
|
|
|
|
# define __HAVE_VM86
|
|
|
|
#endif
|
2001-06-25 23:08:47 +02:00
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
#endif /* linux */
|
|
|
|
|
|
|
|
#ifdef BSDI
|
|
|
|
|
2006-08-11 14:45:11 +02:00
|
|
|
#include <machine/frame.h>
|
|
|
|
typedef struct trapframe SIGCONTEXT;
|
|
|
|
|
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 */
|
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
#endif /* bsdi */
|
|
|
|
|
2006-02-05 13:06:50 +01:00
|
|
|
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
|
1999-09-27 12:58:45 +02:00
|
|
|
|
|
|
|
typedef struct sigcontext SIGCONTEXT;
|
|
|
|
|
2006-08-05 22:34:11 +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)
|
|
|
|
|
2008-01-15 18:08:29 +01:00
|
|
|
#define FPU_sig(context) NULL /* FIXME */
|
|
|
|
#define FPUX_sig(context) NULL /* FIXME */
|
|
|
|
|
2004-08-24 04:26:59 +02:00
|
|
|
#endif /* *BSD */
|
1999-09-27 12:58:45 +02:00
|
|
|
|
|
|
|
#if defined(__svr4__) || defined(_SCO_DS) || defined(__sun)
|
|
|
|
|
|
|
|
#ifdef _SCO_DS
|
|
|
|
#include <sys/regset.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/ucontext.h>
|
|
|
|
typedef struct ucontext SIGCONTEXT;
|
|
|
|
|
2006-08-05 22:34:11 +02:00
|
|
|
#ifdef _SCO_DS
|
|
|
|
#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 */
|
|
|
|
|
1999-09-27 12:58:45 +02:00
|
|
|
#endif /* svr4 || SCO_DS */
|
|
|
|
|
2004-08-24 04:26:59 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
# include <sys/ucontext.h>
|
|
|
|
|
2005-09-27 11:36:15 +02:00
|
|
|
typedef ucontext_t SIGCONTEXT;
|
2005-07-03 13:24:54 +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
|
|
|
|
2004-08-24 04:26:59 +02:00
|
|
|
#endif /* __APPLE__ */
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(seh);
|
1999-10-24 23:29:48 +02:00
|
|
|
|
2002-08-09 03:07:29 +02:00
|
|
|
typedef int (*wine_signal_handler)(unsigned int sig);
|
2002-07-31 20:46:09 +02:00
|
|
|
|
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];
|
|
|
|
|
2008-01-15 18:08:29 +01:00
|
|
|
static int fpux_support; /* whether the CPU support extended fpu context */
|
|
|
|
|
2005-12-19 09:59:50 +01:00
|
|
|
extern void DECLSPEC_NORETURN __wine_call_from_32_restore_regs( const CONTEXT *context );
|
1999-09-27 12:58:45 +02:00
|
|
|
|
2006-02-03 12:30:55 +01:00
|
|
|
enum i386_trap_code
|
|
|
|
{
|
|
|
|
TRAP_x86_UNKNOWN = -1, /* Unknown fault (TRAP_sig not defined) */
|
2006-08-05 22:34:11 +02:00
|
|
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
*/
|
2006-02-03 12:30:55 +01:00
|
|
|
static inline enum i386_trap_code get_trap_code( const SIGCONTEXT *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.
|
|
|
|
*/
|
2005-12-16 16:27:39 +01:00
|
|
|
static inline WORD get_error_code( const SIGCONTEXT *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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-02 03:22:10 +02:00
|
|
|
#ifdef __HAVE_VM86
|
2000-12-29 04:29:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* save_vm86_context
|
|
|
|
*
|
|
|
|
* Set the register values from a vm86 structure.
|
|
|
|
*/
|
|
|
|
static void save_vm86_context( CONTEXT *context, const struct vm86plus_struct *vm86 )
|
|
|
|
{
|
2006-03-27 10:12:02 +02:00
|
|
|
context->ContextFlags = CONTEXT_FULL;
|
2000-12-29 04:29:31 +01:00
|
|
|
context->Eax = vm86->regs.eax;
|
|
|
|
context->Ebx = vm86->regs.ebx;
|
|
|
|
context->Ecx = vm86->regs.ecx;
|
|
|
|
context->Edx = vm86->regs.edx;
|
|
|
|
context->Esi = vm86->regs.esi;
|
|
|
|
context->Edi = vm86->regs.edi;
|
|
|
|
context->Esp = vm86->regs.esp;
|
|
|
|
context->Ebp = vm86->regs.ebp;
|
|
|
|
context->Eip = vm86->regs.eip;
|
|
|
|
context->SegCs = vm86->regs.cs;
|
|
|
|
context->SegDs = vm86->regs.ds;
|
|
|
|
context->SegEs = vm86->regs.es;
|
|
|
|
context->SegFs = vm86->regs.fs;
|
|
|
|
context->SegGs = vm86->regs.gs;
|
|
|
|
context->SegSs = vm86->regs.ss;
|
|
|
|
context->EFlags = vm86->regs.eflags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* restore_vm86_context
|
|
|
|
*
|
|
|
|
* Build a vm86 structure from the register values.
|
|
|
|
*/
|
|
|
|
static void restore_vm86_context( const CONTEXT *context, struct vm86plus_struct *vm86 )
|
|
|
|
{
|
|
|
|
vm86->regs.eax = context->Eax;
|
|
|
|
vm86->regs.ebx = context->Ebx;
|
|
|
|
vm86->regs.ecx = context->Ecx;
|
|
|
|
vm86->regs.edx = context->Edx;
|
|
|
|
vm86->regs.esi = context->Esi;
|
|
|
|
vm86->regs.edi = context->Edi;
|
|
|
|
vm86->regs.esp = context->Esp;
|
|
|
|
vm86->regs.ebp = context->Ebp;
|
|
|
|
vm86->regs.eip = context->Eip;
|
|
|
|
vm86->regs.cs = context->SegCs;
|
|
|
|
vm86->regs.ds = context->SegDs;
|
|
|
|
vm86->regs.es = context->SegEs;
|
|
|
|
vm86->regs.fs = context->SegFs;
|
|
|
|
vm86->regs.gs = context->SegGs;
|
|
|
|
vm86->regs.ss = context->SegSs;
|
|
|
|
vm86->regs.eflags = context->EFlags;
|
|
|
|
}
|
2003-11-11 01:44:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* merge_vm86_pending_flags
|
|
|
|
*
|
|
|
|
* Merges TEB.vm86_ptr and TEB.vm86_pending VIP flags and
|
|
|
|
* raises exception if there are pending events and VIF flag
|
|
|
|
* has been turned on.
|
|
|
|
*
|
|
|
|
* Called from __wine_enter_vm86 because vm86_enter
|
|
|
|
* doesn't check for pending events.
|
|
|
|
*
|
|
|
|
* Called from raise_vm86_sti_exception to check for
|
|
|
|
* pending events in a signal safe way.
|
|
|
|
*/
|
|
|
|
static void merge_vm86_pending_flags( EXCEPTION_RECORD *rec )
|
|
|
|
{
|
|
|
|
BOOL check_pending = TRUE;
|
|
|
|
struct vm86plus_struct *vm86 =
|
2005-06-06 22:04:33 +02:00
|
|
|
(struct vm86plus_struct*)(ntdll_get_thread_data()->vm86_ptr);
|
2003-11-11 01:44:10 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In order to prevent a race when SIGUSR2 occurs while
|
|
|
|
* we are returning from exception handler, pending events
|
|
|
|
* will be rechecked after each raised exception.
|
|
|
|
*/
|
2008-03-01 11:57:00 +01:00
|
|
|
while (check_pending && get_vm86_teb_info()->vm86_pending)
|
2003-11-11 01:44:10 +01:00
|
|
|
{
|
|
|
|
check_pending = FALSE;
|
2005-06-06 22:04:33 +02:00
|
|
|
ntdll_get_thread_data()->vm86_ptr = NULL;
|
2003-11-11 01:44:10 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If VIF is set, throw exception.
|
|
|
|
* Note that SIGUSR2 may turn VIF flag off so
|
|
|
|
* VIF check must occur only when TEB.vm86_ptr is NULL.
|
|
|
|
*/
|
2008-06-02 12:13:33 +02:00
|
|
|
if (vm86->regs.eflags & VIF_FLAG)
|
2003-11-11 01:44:10 +01:00
|
|
|
{
|
|
|
|
CONTEXT vcontext;
|
|
|
|
save_vm86_context( &vcontext, vm86 );
|
|
|
|
|
|
|
|
rec->ExceptionCode = EXCEPTION_VM86_STI;
|
|
|
|
rec->ExceptionFlags = EXCEPTION_CONTINUABLE;
|
|
|
|
rec->ExceptionRecord = NULL;
|
|
|
|
rec->NumberParameters = 0;
|
|
|
|
rec->ExceptionAddress = (LPVOID)vcontext.Eip;
|
|
|
|
|
2008-06-02 12:13:33 +02:00
|
|
|
vcontext.EFlags &= ~VIP_FLAG;
|
2008-03-01 11:57:00 +01:00
|
|
|
get_vm86_teb_info()->vm86_pending = 0;
|
2005-05-07 20:10:30 +02:00
|
|
|
__regs_RtlRaiseException( rec, &vcontext );
|
2003-11-11 01:44:10 +01:00
|
|
|
|
|
|
|
restore_vm86_context( &vcontext, vm86 );
|
|
|
|
check_pending = TRUE;
|
|
|
|
}
|
|
|
|
|
2005-06-06 22:04:33 +02:00
|
|
|
ntdll_get_thread_data()->vm86_ptr = vm86;
|
2003-11-11 01:44:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Merge VIP flags in a signal safe way. This requires
|
|
|
|
* that the following operation compiles into atomic
|
|
|
|
* instruction.
|
|
|
|
*/
|
2008-03-01 11:57:00 +01:00
|
|
|
vm86->regs.eflags |= get_vm86_teb_info()->vm86_pending;
|
2003-11-11 01:44:10 +01:00
|
|
|
}
|
2001-07-02 03:22:10 +02:00
|
|
|
#endif /* __HAVE_VM86 */
|
2000-12-29 04:29:31 +01: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 )
|
|
|
|
{
|
|
|
|
struct ntdll_thread_data *thread_data;
|
|
|
|
|
|
|
|
__asm__ __volatile__("mov %ss,%ax; mov %ax,%ds; mov %ax,%es");
|
|
|
|
|
2008-10-23 23:53:02 +02:00
|
|
|
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
|
|
|
|
|
2003-10-28 01:30:55 +01:00
|
|
|
typedef void (WINAPI *raise_func)( EXCEPTION_RECORD *rec, CONTEXT *context );
|
|
|
|
|
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
|
|
|
*/
|
2007-03-17 11:28:32 +01:00
|
|
|
static inline void *init_handler( const SIGCONTEXT *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();
|
2007-07-19 16:56:10 +02:00
|
|
|
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
|
2003-10-31 00:15:56 +01:00
|
|
|
|
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 */
|
2007-07-19 16:56:10 +02:00
|
|
|
wine_set_fs( thread_data->fs );
|
2008-07-08 20:54:40 +02:00
|
|
|
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__
|
|
|
|
context->ContextFlags |= CONTEXT_FLOATING_POINT;
|
|
|
|
__asm__ __volatile__( "fnsave %0; fwait" : "=m" (context->FloatSave) );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-15 18:08:29 +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);
|
|
|
|
|
|
|
|
__asm__ __volatile__( "fxsave %0" : "=m" (*state) );
|
|
|
|
context->ContextFlags |= CONTEXT_EXTENDED_REGISTERS;
|
|
|
|
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.
|
|
|
|
*/
|
2007-03-17 11:28:32 +01:00
|
|
|
static inline void save_context( CONTEXT *context, const SIGCONTEXT *sigcontext, WORD fs, WORD gs )
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-01-13 13:58:14 +01:00
|
|
|
struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
|
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));
|
2006-01-13 13:58:14 +01:00
|
|
|
context->Dr0 = regs->dr0;
|
|
|
|
context->Dr1 = regs->dr1;
|
|
|
|
context->Dr2 = regs->dr2;
|
|
|
|
context->Dr3 = regs->dr3;
|
|
|
|
context->Dr6 = regs->dr6;
|
|
|
|
context->Dr7 = regs->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) );
|
|
|
|
fpux_support = 1;
|
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.
|
|
|
|
*/
|
2007-03-17 11:28:32 +01:00
|
|
|
static inline void restore_context( const CONTEXT *context, SIGCONTEXT *sigcontext )
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
2006-01-13 13:58:14 +01:00
|
|
|
struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
|
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
|
|
|
|
|
|
|
regs->dr0 = context->Dr0;
|
|
|
|
regs->dr1 = context->Dr1;
|
|
|
|
regs->dr2 = context->Dr2;
|
|
|
|
regs->dr3 = context->Dr3;
|
|
|
|
regs->dr6 = context->Dr6;
|
|
|
|
regs->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
|
|
|
/***********************************************************************
|
|
|
|
* get_cpu_context
|
|
|
|
*
|
|
|
|
* Register function to get the context of the current thread.
|
|
|
|
*/
|
|
|
|
void WINAPI __regs_get_cpu_context( CONTEXT *context, CONTEXT *regs )
|
|
|
|
{
|
|
|
|
*context = *regs;
|
2008-01-15 18:08:29 +01:00
|
|
|
if (fpux_support) save_fpux( context );
|
|
|
|
else save_fpu( context );
|
2006-04-20 15:40:28 +02:00
|
|
|
}
|
2007-04-11 22:42:56 +02:00
|
|
|
DEFINE_REGS_ENTRYPOINT( get_cpu_context, 4, 4 )
|
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
|
|
|
*/
|
2006-01-11 20:20:32 +01:00
|
|
|
void set_cpu_context( const CONTEXT *context )
|
2005-12-19 09:59:50 +01:00
|
|
|
{
|
|
|
|
DWORD flags = context->ContextFlags & ~CONTEXT_i386;
|
|
|
|
|
2008-01-18 12:02:31 +01:00
|
|
|
if ((flags & CONTEXT_EXTENDED_REGISTERS) && fpux_support) 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)
|
|
|
|
{
|
|
|
|
struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
|
|
|
|
regs->dr0 = context->Dr0;
|
|
|
|
regs->dr1 = context->Dr1;
|
|
|
|
regs->dr2 = context->Dr2;
|
|
|
|
regs->dr3 = context->Dr3;
|
|
|
|
regs->dr6 = context->Dr6;
|
|
|
|
regs->dr7 = context->Dr7;
|
|
|
|
}
|
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)
|
2006-01-11 20:20:32 +01:00
|
|
|
__wine_call_from_32_restore_regs( 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();
|
|
|
|
__wine_call_from_32_restore_regs( &newcontext );
|
|
|
|
}
|
2006-01-11 20:20:32 +01:00
|
|
|
}
|
2005-12-19 09:59:50 +01: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.
|
|
|
|
*/
|
2007-03-14 12:02:43 +01:00
|
|
|
static inline DWORD is_privileged_instr( CONTEXT86 *context )
|
2005-12-16 16:27:39 +01:00
|
|
|
{
|
|
|
|
const BYTE *instr;
|
|
|
|
unsigned int prefix_count = 0;
|
|
|
|
|
|
|
|
if (!wine_ldt_is_system( context->SegCs )) return 0;
|
|
|
|
instr = (BYTE *)context->Eip;
|
|
|
|
|
|
|
|
for (;;) switch(*instr)
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
instr++;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case 0x0f: /* extended instruction */
|
|
|
|
switch(instr[1])
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-10 15:13:59 +01:00
|
|
|
#include "pshpack1.h"
|
|
|
|
struct atl_thunk
|
|
|
|
{
|
|
|
|
DWORD movl; /* movl this,4(%esp) */
|
|
|
|
DWORD this;
|
|
|
|
BYTE jmp; /* jmp func */
|
|
|
|
int func;
|
|
|
|
};
|
|
|
|
#include "poppack.h"
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* check_atl_thunk
|
|
|
|
*
|
|
|
|
* Check if code destination is an ATL thunk, and emulate it if so.
|
|
|
|
*/
|
|
|
|
static BOOL check_atl_thunk( EXCEPTION_RECORD *rec, CONTEXT *context )
|
|
|
|
{
|
2006-09-27 16:51:07 +02:00
|
|
|
const struct atl_thunk *thunk = (const struct atl_thunk *)rec->ExceptionInformation[1];
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
if (thunk->movl == 0x042444c7 && thunk->jmp == 0xe9)
|
|
|
|
{
|
|
|
|
*((DWORD *)context->Esp + 1) = thunk->this;
|
|
|
|
context->Eip = (DWORD_PTR)(&thunk->func + 1) + thunk->func;
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE( "emulating ATL thunk at %p, func=%08x arg=%08x\n",
|
2006-09-27 16:51:07 +02:00
|
|
|
thunk, context->Eip, *((DWORD *)context->Esp + 1) );
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__EXCEPT_PAGE_FAULT
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
return ret;
|
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
|
|
|
*/
|
2008-04-01 17:37:17 +02:00
|
|
|
static EXCEPTION_RECORD *setup_exception_record( SIGCONTEXT *sigcontext, void *stack_ptr,
|
|
|
|
WORD fs, WORD gs, raise_func func )
|
2003-10-28 01:30:55 +01:00
|
|
|
{
|
|
|
|
struct stack_layout
|
|
|
|
{
|
|
|
|
void *ret_addr; /* return address from raise_func */
|
|
|
|
EXCEPTION_RECORD *rec_ptr; /* first arg for raise_func */
|
|
|
|
CONTEXT *context_ptr; /* second arg for raise_func */
|
|
|
|
CONTEXT context;
|
|
|
|
EXCEPTION_RECORD rec;
|
|
|
|
DWORD ebp;
|
|
|
|
DWORD eip;
|
2008-04-01 17:37:17 +02:00
|
|
|
} *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 );
|
2003-11-06 01:08:05 +01:00
|
|
|
server_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 );
|
|
|
|
server_abort_thread(1);
|
|
|
|
}
|
|
|
|
else if ((char *)(stack - 1) < (char *)NtCurrentTeb()->Tib.StackLimit)
|
|
|
|
{
|
|
|
|
/* stack access below stack limit, may be recoverable */
|
|
|
|
if (virtual_handle_stack_fault( stack - 1 )) exception_code = EXCEPTION_STACK_OVERFLOW;
|
|
|
|
else
|
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 );
|
2003-11-06 01:08:05 +01:00
|
|
|
server_abort_thread(1);
|
2003-11-04 05:50:18 +01:00
|
|
|
}
|
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
|
2005-12-19 09:59:50 +01:00
|
|
|
stack->ret_addr = (void *)0xdeadbabe; /* raise_func must not return */
|
2003-10-28 01:30:55 +01:00
|
|
|
stack->rec_ptr = &stack->rec;
|
|
|
|
stack->context_ptr = &stack->context;
|
|
|
|
|
|
|
|
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 );
|
2003-10-28 01:30:55 +01:00
|
|
|
|
|
|
|
/* now modify the sigcontext to return to the raise function */
|
|
|
|
ESP_sig(sigcontext) = (DWORD)stack;
|
|
|
|
EIP_sig(sigcontext) = (DWORD)func;
|
2008-03-20 11:50:07 +01:00
|
|
|
/* clear single-step, direction, and align check flag */
|
|
|
|
EFL_sig(sigcontext) &= ~(0x100|0x400|0x40000);
|
2003-10-28 01:30:55 +01:00
|
|
|
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();
|
|
|
|
|
|
|
|
return stack->rec_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static EXCEPTION_RECORD *setup_exception( SIGCONTEXT *sigcontext, raise_func func )
|
|
|
|
{
|
|
|
|
WORD fs, gs;
|
|
|
|
void *stack = init_handler( sigcontext, &fs, &gs );
|
|
|
|
|
|
|
|
return setup_exception_record( sigcontext, stack, fs, gs, func );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-28 01:30:55 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* get_exception_context
|
|
|
|
*
|
|
|
|
* Get a pointer to the context built by setup_exception.
|
|
|
|
*/
|
|
|
|
static inline CONTEXT *get_exception_context( EXCEPTION_RECORD *rec )
|
|
|
|
{
|
|
|
|
return (CONTEXT *)rec - 1; /* cf. stack_layout structure */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
DWORD status = context->FloatSave.StatusWord;
|
|
|
|
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2003-10-28 01:30:55 +01:00
|
|
|
* raise_segv_exception
|
1999-09-27 12:58:45 +02:00
|
|
|
*/
|
2006-01-11 20:20:32 +01:00
|
|
|
static void WINAPI raise_segv_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
|
1999-09-27 12:58:45 +02:00
|
|
|
{
|
2003-10-28 01:30:55 +01:00
|
|
|
switch(rec->ExceptionCode)
|
1999-09-27 12:58:45 +02:00
|
|
|
{
|
2003-10-28 01:30:55 +01:00
|
|
|
case EXCEPTION_ACCESS_VIOLATION:
|
|
|
|
if (rec->NumberParameters == 2)
|
2006-02-10 15:13:59 +01:00
|
|
|
{
|
2006-09-20 11:27:53 +02:00
|
|
|
if (rec->ExceptionInformation[0] == EXCEPTION_EXECUTE_FAULT && check_atl_thunk( rec, context ))
|
|
|
|
goto done;
|
2008-11-25 12:02:16 +01:00
|
|
|
if (!(rec->ExceptionCode = virtual_handle_fault( (void *)rec->ExceptionInformation[1],
|
|
|
|
rec->ExceptionInformation[0] )))
|
|
|
|
goto done;
|
2006-02-10 15:13:59 +01:00
|
|
|
}
|
1999-09-27 12:58:45 +02:00
|
|
|
break;
|
2003-10-28 01:30:55 +01:00
|
|
|
case EXCEPTION_DATATYPE_MISALIGNMENT:
|
1999-09-27 12:58:45 +02:00
|
|
|
/* FIXME: pass through exception handler first? */
|
2000-09-18 04:15:07 +02:00
|
|
|
if (context->EFlags & 0x00040000)
|
1999-09-27 12:58:45 +02:00
|
|
|
{
|
|
|
|
/* Disable AC flag, return */
|
2000-09-18 04:15:07 +02:00
|
|
|
context->EFlags &= ~0x00040000;
|
2005-12-19 09:59:50 +01:00
|
|
|
goto done;
|
2000-09-18 04:15:07 +02:00
|
|
|
}
|
1999-09-27 12:58:45 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-05-07 20:10:30 +02:00
|
|
|
__regs_RtlRaiseException( rec, context );
|
2005-12-19 09:59:50 +01:00
|
|
|
done:
|
2006-01-11 20:20:32 +01:00
|
|
|
NtSetContextThread( GetCurrentThread(), context );
|
1999-09-27 12:58:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2003-10-28 01:30:55 +01:00
|
|
|
* raise_trap_exception
|
1999-09-27 12:58:45 +02:00
|
|
|
*/
|
2006-01-11 20:20:32 +01:00
|
|
|
static void WINAPI raise_trap_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
|
1999-09-27 12:58:45 +02:00
|
|
|
{
|
2003-10-28 01:30:55 +01:00
|
|
|
if (rec->ExceptionCode == EXCEPTION_SINGLE_STEP)
|
1999-09-28 15:15:27 +02:00
|
|
|
{
|
2007-11-09 17:49:06 +01:00
|
|
|
struct ntdll_thread_regs * const regs = ntdll_get_thread_regs();
|
|
|
|
|
|
|
|
/* 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( !(context->EFlags & 0x100) || (regs->dr7 & 0xff) )
|
2002-06-02 23:36:39 +02:00
|
|
|
{
|
2007-11-09 17:49:06 +01:00
|
|
|
/* (possible) hardware breakpoint, fetch the debug registers */
|
2003-03-24 20:31:10 +01:00
|
|
|
context->ContextFlags = CONTEXT_DEBUG_REGISTERS;
|
2003-04-05 00:26:34 +02:00
|
|
|
NtGetContextThread(GetCurrentThread(), context);
|
2006-01-11 20:20:32 +01:00
|
|
|
context->ContextFlags |= CONTEXT_FULL; /* restore flags */
|
2002-06-02 23:36:39 +02:00
|
|
|
}
|
2007-11-09 17:49:06 +01:00
|
|
|
|
|
|
|
context->EFlags &= ~0x100; /* clear single-step flag */
|
1999-09-28 15:15:27 +02:00
|
|
|
}
|
2003-10-28 01:30:55 +01:00
|
|
|
|
2005-05-07 20:10:30 +02:00
|
|
|
__regs_RtlRaiseException( rec, context );
|
2006-01-11 20:20:32 +01:00
|
|
|
NtSetContextThread( GetCurrentThread(), context );
|
1999-09-27 12:58:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2005-12-19 09:59:50 +01:00
|
|
|
* raise_exception
|
|
|
|
*
|
|
|
|
* Generic raise function for exceptions that don't need special treatment.
|
1999-09-27 12:58:45 +02:00
|
|
|
*/
|
2006-01-11 20:20:32 +01:00
|
|
|
static void WINAPI raise_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
|
1999-09-27 12:58:45 +02:00
|
|
|
{
|
2005-05-07 20:10:30 +02:00
|
|
|
__regs_RtlRaiseException( rec, context );
|
2006-01-11 20:20:32 +01:00
|
|
|
NtSetContextThread( GetCurrentThread(), context );
|
2000-09-18 04:15:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-02 03:22:10 +02:00
|
|
|
#ifdef __HAVE_VM86
|
2001-06-21 02:39:34 +02:00
|
|
|
/**********************************************************************
|
2003-11-05 01:52:29 +01:00
|
|
|
* raise_vm86_sti_exception
|
2001-06-21 02:39:34 +02:00
|
|
|
*/
|
2006-01-11 20:20:32 +01:00
|
|
|
static void WINAPI raise_vm86_sti_exception( EXCEPTION_RECORD *rec, CONTEXT *context )
|
2001-06-21 02:39:34 +02:00
|
|
|
{
|
2003-11-11 01:44:10 +01:00
|
|
|
/* merge_vm86_pending_flags merges the vm86_pending flag in safely */
|
2008-06-02 12:13:33 +02:00
|
|
|
get_vm86_teb_info()->vm86_pending |= VIP_FLAG;
|
2003-11-05 01:52:29 +01:00
|
|
|
|
2005-06-06 22:04:33 +02:00
|
|
|
if (ntdll_get_thread_data()->vm86_ptr)
|
2001-06-21 02:39:34 +02:00
|
|
|
{
|
2002-01-04 22:57:04 +01:00
|
|
|
if (((char*)context->Eip >= (char*)vm86_return) &&
|
|
|
|
((char*)context->Eip <= (char*)vm86_return_end) &&
|
|
|
|
(VM86_TYPE(context->Eax) != VM86_SIGNAL)) {
|
|
|
|
/* exiting from VM86, can't throw */
|
2005-12-19 09:59:50 +01:00
|
|
|
goto done;
|
2002-01-04 22:57:04 +01:00
|
|
|
}
|
2003-11-11 01:44:10 +01:00
|
|
|
merge_vm86_pending_flags( rec );
|
2001-06-21 02:39:34 +02:00
|
|
|
}
|
2008-03-01 11:57:00 +01:00
|
|
|
else if (get_vm86_teb_info()->dpmi_vif &&
|
2003-11-17 21:12:56 +01:00
|
|
|
!wine_ldt_is_system(context->SegCs) &&
|
|
|
|
!wine_ldt_is_system(context->SegSs))
|
2003-11-05 01:52:29 +01:00
|
|
|
{
|
|
|
|
/* Executing DPMI code and virtual interrupts are enabled. */
|
2008-03-01 11:57:00 +01:00
|
|
|
get_vm86_teb_info()->vm86_pending = 0;
|
2005-05-07 20:10:30 +02:00
|
|
|
__regs_RtlRaiseException( rec, context );
|
2003-11-05 01:52:29 +01:00
|
|
|
}
|
2005-12-19 09:59:50 +01:00
|
|
|
done:
|
2006-01-11 20:20:32 +01:00
|
|
|
NtSetContextThread( GetCurrentThread(), context );
|
2001-06-21 02:39:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 23:08:47 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* usr2_handler
|
|
|
|
*
|
|
|
|
* Handler for SIGUSR2.
|
|
|
|
* We use it to signal that the running __wine_enter_vm86() should
|
2008-06-02 12:13:33 +02:00
|
|
|
* immediately set VIP_FLAG, causing pending events to be handled
|
2001-06-25 23:08:47 +02:00
|
|
|
* as early as possible.
|
|
|
|
*/
|
2006-08-11 14:45:11 +02:00
|
|
|
static void usr2_handler( int signal, siginfo_t *siginfo, void *sigcontext )
|
2001-06-25 23:08:47 +02:00
|
|
|
{
|
2006-08-11 14:45:11 +02:00
|
|
|
EXCEPTION_RECORD *rec = setup_exception( sigcontext, raise_vm86_sti_exception );
|
2003-11-05 01:52:29 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_VM86_STI;
|
2001-06-25 23:08:47 +02:00
|
|
|
}
|
2001-07-02 03:22:10 +02:00
|
|
|
#endif /* __HAVE_VM86 */
|
2001-06-25 23:08:47 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
EXCEPTION_RECORD *rec;
|
2006-08-11 14:45:11 +02:00
|
|
|
SIGCONTEXT *context = sigcontext;
|
2008-04-01 17:37:17 +02:00
|
|
|
void *stack = init_handler( sigcontext, &fs, &gs );
|
|
|
|
|
|
|
|
/* check for page fault inside the thread stack */
|
|
|
|
if (get_trap_code(context) == TRAP_x86_PAGEFLT &&
|
|
|
|
(char *)siginfo->si_addr >= (char *)NtCurrentTeb()->DeallocationStack &&
|
|
|
|
(char *)siginfo->si_addr < (char *)NtCurrentTeb()->Tib.StackBase &&
|
|
|
|
virtual_handle_stack_fault( siginfo->si_addr ))
|
2008-04-01 17:40:37 +02:00
|
|
|
{
|
|
|
|
/* check if this was the last guard page */
|
|
|
|
if ((char *)siginfo->si_addr < (char *)NtCurrentTeb()->DeallocationStack + 2*4096)
|
|
|
|
{
|
|
|
|
rec = setup_exception_record( context, stack, fs, gs, raise_segv_exception );
|
|
|
|
rec->ExceptionCode = EXCEPTION_STACK_OVERFLOW;
|
|
|
|
}
|
2008-04-01 17:37:17 +02:00
|
|
|
return;
|
2008-04-01 17:40:37 +02:00
|
|
|
}
|
2008-04-01 17:37:17 +02:00
|
|
|
|
|
|
|
rec = setup_exception_record( context, stack, fs, gs, raise_segv_exception );
|
2008-04-01 17:40:37 +02:00
|
|
|
if (rec->ExceptionCode == EXCEPTION_STACK_OVERFLOW) return;
|
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 */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_INT_OVERFLOW;
|
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_BOUND: /* Bound range exception */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
|
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_PRIVINFLT: /* Invalid opcode exception */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
|
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_STKFLT: /* Stack fault */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_STACK_OVERFLOW;
|
|
|
|
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);
|
2007-03-14 12:02:43 +01:00
|
|
|
if (!err && (rec->ExceptionCode = is_privileged_instr( get_exception_context(rec) ))) break;
|
2005-12-16 16:27:39 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
|
|
|
|
rec->NumberParameters = 2;
|
|
|
|
rec->ExceptionInformation[0] = 0;
|
|
|
|
/* 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 ))
|
|
|
|
rec->ExceptionInformation[1] = err & ~7;
|
|
|
|
else
|
|
|
|
rec->ExceptionInformation[1] = 0xffffffff;
|
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 */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
|
|
|
|
rec->NumberParameters = 2;
|
2006-08-11 14:45:11 +02:00
|
|
|
rec->ExceptionInformation[0] = (get_error_code(context) >> 1) & 0x09;
|
|
|
|
rec->ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
|
2003-10-28 01:30:55 +01:00
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_ALIGNFLT: /* Alignment check exception */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
|
|
|
|
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 */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
{
|
2006-08-11 14:45:11 +02:00
|
|
|
SIGCONTEXT *context = sigcontext;
|
|
|
|
EXCEPTION_RECORD *rec = setup_exception( context, raise_trap_exception );
|
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 */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_SINGLE_STEP;
|
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_BPTFLT: /* Breakpoint exception */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionAddress = (char *)rec->ExceptionAddress - 1; /* back up over the int3 instruction */
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
rec->ExceptionCode = EXCEPTION_BREAKPOINT;
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
{
|
2006-08-11 14:45:11 +02:00
|
|
|
CONTEXT *win_context;
|
|
|
|
SIGCONTEXT *context = sigcontext;
|
|
|
|
EXCEPTION_RECORD *rec = setup_exception( context, raise_exception );
|
2003-10-28 01:30:55 +01:00
|
|
|
|
2006-08-11 14:45:11 +02:00
|
|
|
win_context = get_exception_context( rec );
|
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 */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
|
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_FPOPFLT: /* Coprocessor segment overrun */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
|
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_ARITHTRAP: /* Floating point exception */
|
|
|
|
case TRAP_x86_UNKNOWN: /* Unknown fault code */
|
2006-08-11 14:45:11 +02:00
|
|
|
rec->ExceptionCode = get_fpu_code( win_context );
|
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 */
|
|
|
|
if(siginfo->si_code != FPE_FLTDIV)
|
|
|
|
FIXME("untested SIMD exception: %#x. Might not work correctly\n",
|
|
|
|
siginfo->si_code);
|
|
|
|
|
|
|
|
rec->ExceptionCode = STATUS_FLOAT_MULTIPLE_TRAPS;
|
|
|
|
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 */
|
2007-03-08 22:48:14 +01:00
|
|
|
rec->ExceptionInformation[0] = 0;
|
|
|
|
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) );
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
|
|
|
|
break;
|
|
|
|
}
|
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;
|
2006-08-11 14:45:11 +02:00
|
|
|
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
|
|
|
{
|
2006-08-11 14:45:11 +02:00
|
|
|
EXCEPTION_RECORD *rec = setup_exception( sigcontext, raise_exception );
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = CONTROL_C_EXIT;
|
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
|
|
|
{
|
2006-08-11 14:45:11 +02:00
|
|
|
EXCEPTION_RECORD *rec = setup_exception( sigcontext, raise_exception );
|
2003-10-28 01:30:55 +01:00
|
|
|
rec->ExceptionCode = EXCEPTION_WINE_ASSERTION;
|
|
|
|
rec->ExceptionFlags = EH_NONCONTINUABLE;
|
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 );
|
2003-11-06 01:08:05 +01:00
|
|
|
server_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-14 12:36:58 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* get_signal_stack_total_size
|
|
|
|
*
|
|
|
|
* Retrieve the size to allocate for the signal stack, including the TEB at the bottom.
|
|
|
|
* Must be a power of two.
|
|
|
|
*/
|
|
|
|
size_t get_signal_stack_total_size(void)
|
|
|
|
{
|
|
|
|
static const size_t teb_size = 4096; /* we reserve one page for the TEB */
|
|
|
|
|
|
|
|
if (!signal_stack_size)
|
|
|
|
{
|
2007-11-08 13:53:47 +01:00
|
|
|
size_t size = 8192, 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 */
|
|
|
|
while (size < min_size) size *= 2;
|
|
|
|
signal_stack_mask = size - 1;
|
|
|
|
signal_stack_size = size - teb_size;
|
|
|
|
}
|
|
|
|
return signal_stack_size + teb_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-31 20:46:09 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* __wine_set_signal_handler (NTDLL.@)
|
|
|
|
*/
|
2008-12-16 16:37:46 +01:00
|
|
|
int CDECL __wine_set_signal_handler(unsigned int sig, wine_signal_handler wsh)
|
2002-07-31 20:46:09 +02:00
|
|
|
{
|
2006-04-07 08:16:48 +02:00
|
|
|
if (sig >= sizeof(handlers) / sizeof(handlers[0])) return -1;
|
2002-07-31 20:46:09 +02:00
|
|
|
if (handlers[sig] != NULL) return -2;
|
|
|
|
handlers[sig] = wsh;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
2008-07-03 20:18:23 +02:00
|
|
|
void signal_init_thread(void)
|
1999-09-27 12:58:45 +02:00
|
|
|
{
|
2000-04-13 21:25:52 +02:00
|
|
|
#ifdef HAVE_SIGALTSTACK
|
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
|
|
|
|
|
2003-10-31 00:15:56 +01:00
|
|
|
ss.ss_sp = get_signal_stack();
|
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" );
|
1999-09-27 12:58:45 +02:00
|
|
|
#endif /* HAVE_SIGALTSTACK */
|
2008-07-08 20:54:40 +02:00
|
|
|
|
|
|
|
ntdll_get_thread_data()->gs = wine_get_gs();
|
2008-07-03 20:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* signal_init_process
|
|
|
|
*/
|
|
|
|
void signal_init_process(void)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
2001-07-02 03:22:10 +02:00
|
|
|
#ifdef __HAVE_VM86
|
2006-08-11 14:45:11 +02:00
|
|
|
sig_act.sa_sigaction = usr2_handler;
|
2006-08-07 16:45:45 +02:00
|
|
|
if (sigaction( SIGUSR2, &sig_act, NULL ) == -1) goto error;
|
2001-06-25 23:08:47 +02:00
|
|
|
#endif
|
|
|
|
|
2008-07-03 20:18:23 +02:00
|
|
|
signal_init_thread();
|
|
|
|
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
|
|
|
|
2001-07-02 03:22:10 +02:00
|
|
|
#ifdef __HAVE_VM86
|
2000-09-18 04:15:07 +02:00
|
|
|
/**********************************************************************
|
2002-09-09 21:26:55 +02:00
|
|
|
* __wine_enter_vm86 (NTDLL.@)
|
2000-09-18 04:15:07 +02:00
|
|
|
*
|
|
|
|
* Enter vm86 mode with the specified register context.
|
|
|
|
*/
|
|
|
|
void __wine_enter_vm86( CONTEXT *context )
|
|
|
|
{
|
|
|
|
EXCEPTION_RECORD rec;
|
|
|
|
int res;
|
|
|
|
struct vm86plus_struct vm86;
|
|
|
|
|
2000-09-24 05:11:54 +02:00
|
|
|
memset( &vm86, 0, sizeof(vm86) );
|
2000-09-18 04:15:07 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
2000-12-29 04:29:31 +01:00
|
|
|
restore_vm86_context( context, &vm86 );
|
2003-10-28 01:30:55 +01:00
|
|
|
|
2005-06-06 22:04:33 +02:00
|
|
|
ntdll_get_thread_data()->vm86_ptr = &vm86;
|
2003-11-11 01:44:10 +01:00
|
|
|
merge_vm86_pending_flags( &rec );
|
2000-09-18 04:15:07 +02:00
|
|
|
|
2005-06-06 22:04:33 +02:00
|
|
|
res = vm86_enter( &ntdll_get_thread_data()->vm86_ptr ); /* uses and clears teb->vm86_ptr */
|
2003-11-11 01:44:10 +01:00
|
|
|
if (res < 0)
|
2000-09-24 05:11:54 +02:00
|
|
|
{
|
2003-11-11 01:44:10 +01:00
|
|
|
errno = -res;
|
|
|
|
return;
|
|
|
|
}
|
2000-09-18 04:15:07 +02:00
|
|
|
|
2000-12-29 04:29:31 +01:00
|
|
|
save_vm86_context( context, &vm86 );
|
2000-09-18 04:15:07 +02:00
|
|
|
|
2003-10-28 01:30:55 +01:00
|
|
|
rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
|
|
|
|
rec.ExceptionRecord = NULL;
|
|
|
|
rec.ExceptionAddress = (LPVOID)context->Eip;
|
|
|
|
rec.NumberParameters = 0;
|
|
|
|
|
2000-09-18 04:15:07 +02:00
|
|
|
switch(VM86_TYPE(res))
|
|
|
|
{
|
|
|
|
case VM86_UNKNOWN: /* unhandled GP fault - IO-instruction or similar */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec.ExceptionCode = EXCEPTION_PRIV_INSTRUCTION;
|
2007-06-25 19:47:58 +02:00
|
|
|
break;
|
2000-09-18 04:15:07 +02:00
|
|
|
case VM86_TRAP: /* return due to DOS-debugger request */
|
2003-10-28 01:30:55 +01:00
|
|
|
switch(VM86_ARG(res))
|
|
|
|
{
|
2006-03-27 10:12:02 +02:00
|
|
|
case TRAP_x86_TRCTRAP: /* Single-step exception */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec.ExceptionCode = EXCEPTION_SINGLE_STEP;
|
|
|
|
break;
|
2006-02-03 12:30:55 +01:00
|
|
|
case TRAP_x86_BPTFLT: /* Breakpoint exception */
|
2003-10-28 01:30:55 +01:00
|
|
|
rec.ExceptionAddress = (char *)rec.ExceptionAddress - 1; /* back up over the int3 instruction */
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
rec.ExceptionCode = EXCEPTION_BREAKPOINT;
|
|
|
|
break;
|
|
|
|
}
|
2006-03-27 10:12:02 +02:00
|
|
|
break;
|
2000-09-18 04:15:07 +02:00
|
|
|
case VM86_INTx: /* int3/int x instruction (ARG = x) */
|
|
|
|
rec.ExceptionCode = EXCEPTION_VM86_INTx;
|
2003-10-28 01:30:55 +01:00
|
|
|
rec.NumberParameters = 1;
|
|
|
|
rec.ExceptionInformation[0] = VM86_ARG(res);
|
2000-09-18 04:15:07 +02:00
|
|
|
break;
|
|
|
|
case VM86_STI: /* sti/popf/iret instruction enabled virtual interrupts */
|
2008-06-02 12:13:33 +02:00
|
|
|
context->EFlags |= VIF_FLAG;
|
|
|
|
context->EFlags &= ~VIP_FLAG;
|
2008-03-01 11:57:00 +01:00
|
|
|
get_vm86_teb_info()->vm86_pending = 0;
|
2000-09-18 04:15:07 +02:00
|
|
|
rec.ExceptionCode = EXCEPTION_VM86_STI;
|
|
|
|
break;
|
|
|
|
case VM86_PICRETURN: /* return due to pending PIC request */
|
|
|
|
rec.ExceptionCode = EXCEPTION_VM86_PICRETURN;
|
|
|
|
break;
|
2003-11-11 01:44:10 +01:00
|
|
|
case VM86_SIGNAL: /* cannot happen because vm86_enter handles this case */
|
2000-09-18 04:15:07 +02:00
|
|
|
default:
|
2007-03-14 09:53:59 +01:00
|
|
|
WINE_ERR( "unhandled result from vm86 mode %x\n", res );
|
2000-09-18 04:15:07 +02:00
|
|
|
continue;
|
|
|
|
}
|
2005-05-07 20:10:30 +02:00
|
|
|
__regs_RtlRaiseException( &rec, context );
|
2000-09-18 04:15:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-02 03:22:10 +02:00
|
|
|
#else /* __HAVE_VM86 */
|
2002-09-09 21:26:55 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* __wine_enter_vm86 (NTDLL.@)
|
|
|
|
*/
|
2000-09-18 04:15:07 +02:00
|
|
|
void __wine_enter_vm86( CONTEXT *context )
|
|
|
|
{
|
|
|
|
MESSAGE("vm86 mode not supported on this platform\n");
|
|
|
|
}
|
2001-07-02 03:22:10 +02:00
|
|
|
#endif /* __HAVE_VM86 */
|
2000-09-18 04:15:07 +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
|
|
|
*/
|
2007-01-13 00:38:07 +01:00
|
|
|
__ASM_GLOBAL_FUNC( DbgBreakPoint, "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
|
|
|
*/
|
2007-01-13 00:38:07 +01:00
|
|
|
__ASM_GLOBAL_FUNC( DbgUserBreakPoint, "int $3; ret")
|
2000-03-07 14:10:21 +01:00
|
|
|
|
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,
|
|
|
|
" pushl %ebp\n"
|
|
|
|
" movl %esp, %ebp\n"
|
2006-09-25 06:43:41 +02:00
|
|
|
" pushl %ebx\n"
|
2005-11-01 10:21:03 +01:00
|
|
|
" movl 28(%ebp), %edx\n" /* ugly hack to pass the 6th param needed because of Shrinker */
|
|
|
|
" pushl 24(%ebp)\n"
|
|
|
|
" pushl 20(%ebp)\n"
|
|
|
|
" pushl 16(%ebp)\n"
|
|
|
|
" pushl 12(%ebp)\n"
|
|
|
|
" pushl 8(%ebp)\n"
|
2005-11-15 13:05:45 +01:00
|
|
|
" call " __ASM_NAME("call_exception_handler") "\n"
|
2006-09-25 06:43:41 +02:00
|
|
|
" popl %ebx\n"
|
2005-10-31 15:08:05 +01:00
|
|
|
" leave\n"
|
|
|
|
" ret\n"
|
2007-01-13 00:38:07 +01:00
|
|
|
)
|
2005-11-01 10:21:03 +01:00
|
|
|
__ASM_GLOBAL_FUNC(call_exception_handler,
|
|
|
|
" pushl %ebp\n"
|
|
|
|
" movl %esp, %ebp\n"
|
2005-11-23 19:55:06 +01:00
|
|
|
" subl $12,%esp\n"
|
2005-11-01 10:21:03 +01:00
|
|
|
" pushl 12(%ebp)\n" /* make any exceptions in this... */
|
|
|
|
" pushl %edx\n" /* handler be handled by... */
|
|
|
|
" .byte 0x64\n"
|
|
|
|
" pushl (0)\n" /* nested_handler (passed in edx). */
|
|
|
|
" .byte 0x64\n"
|
|
|
|
" movl %esp,(0)\n" /* push the new exception frame onto the exception stack. */
|
|
|
|
" pushl 20(%ebp)\n"
|
|
|
|
" pushl 16(%ebp)\n"
|
|
|
|
" pushl 12(%ebp)\n"
|
|
|
|
" pushl 8(%ebp)\n"
|
|
|
|
" movl 24(%ebp), %ecx\n" /* (*1) */
|
|
|
|
" call *%ecx\n" /* call handler. (*2) */
|
|
|
|
" .byte 0x64\n"
|
|
|
|
" movl (0), %esp\n" /* restore previous... (*3) */
|
|
|
|
" .byte 0x64\n"
|
|
|
|
" popl (0)\n" /* exception frame. */
|
|
|
|
" movl %ebp, %esp\n" /* restore saved stack, in case it was corrupted */
|
|
|
|
" popl %ebp\n"
|
|
|
|
" ret $20\n" /* (*4) */
|
2007-01-13 00:38:07 +01:00
|
|
|
)
|
1999-09-27 12:58:45 +02:00
|
|
|
#endif /* __i386__ */
|