58cd1d70dd
gcc: * config/alpha/linux.h (MD_UNWIND_SUPPORT): Remove. * config/alpha/osf5.h (MD_UNWIND_SUPPORT): Remove. * config/alpha/vms.h (MD_UNWIND_SUPPORT): Remove. * config/bfin/linux.h (MD_UNWIND_SUPPORT): Remove. * config/bfin/uclinux.h (MD_UNWIND_SUPPORT): Remove. * config/i386/linux.h (MD_UNWIND_SUPPORT): Remove. * config/i386/linux64.h (MD_UNWIND_SUPPORT): Remove. * config/i386/sol2.h (MD_UNWIND_SUPPORT): Remove. * config/i386/mingw32.h (MD_UNWIND_SUPPORT): Remove. * config/ia64/linux.h (MD_UNWIND_SUPPORT): Remove. * config/ia64/vms.h (MD_UNWIND_SUPPORT): Remove. * config/m68k/linux.h (MD_UNWIND_SUPPORT): Remove. * config/mips/linux.h (MD_UNWIND_SUPPORT): Remove. * config/pa/pa-hpux.h (MD_UNWIND_SUPPORT): Remove. * config/pa/pa32-linux.h (MD_UNWIND_SUPPORT): Remove. * config/rs6000/darwin.h (MD_UNWIND_SUPPORT): Remove. * config/rs6000/linux.h (MD_UNWIND_SUPPORT): Remove. * config/rs6000/linux64.h (MD_UNWIND_SUPPORT): Remove. * config/s390/linux.h (MD_UNWIND_SUPPORT): Remove. * config/s390/tpf.h (MD_UNWIND_SUPPORT): Remove. * config/sh/linux.h (MD_UNWIND_SUPPORT): Remove. * config/sparc/linux.h (MD_UNWIND_SUPPORT): Remove. * config/sparc/linux64.h (MD_UNWIND_SUPPORT): Remove. * config/sparc/sol2.h (MD_UNWIND_SUPPORT): Remove. * config/xtensa/linux.h (MD_UNWIND_SUPPORT): Remove. * config/alpha/linux-unwind.h: Move to ../libgcc/config/alpha. * config/alpha/osf5-unwind.h: Move to ../libgcc/config/alpha. * config/alpha/vms-unwind.h: Move to ../libgcc/config/alpha. * config/bfin/linux-unwind.h: Move to ../libgcc/config/bfin. * config/i386/linux-unwind.h: Move to ../libgcc/config/i386. * config/i386/sol2-unwind.h: Move to ../libgcc/config/i386. * config/i386/w32-unwind.h: Move to ../libgcc/config/i386. * config/ia64/linux-unwind.h: Move to ../libgcc/config/ia64. * config/ia64/vms-unwind.h: Move to ../libgcc/config/ia64. * config/m68k/linux-unwind.h: Move to ../libgcc/config/m68k. * config/mips/linux-unwind.h: Move to ../libgcc/config/mips. * config/pa/hpux-unwind.h: Move to ../libgcc/config/pa. * config/pa/linux-unwind.h: Move to ../libgcc/config/pa. * config/rs6000/darwin-unwind.h: Move to ../libgcc/config/rs6000. * config/rs6000/linux-unwind.h: Move to ../libgcc/config/rs6000. * config/s390/linux-unwind.h: Move to ../libgcc/config/s390. * config/s390/tpf-unwind.h: Move to ../libgcc/config/s390. * config/sh/linux-unwind.h: Move to ../libgcc/config/sh. * config/sparc/linux-unwind.h: Move to ../libgcc/config/sparc. * config/sparc/sol2-unwind.h: Move to ../libgcc/config/sparc. * config/xtensa/linux-unwind.h: Move to ../libgcc/config/xtensa. * config/darwin9.h (DARWIN_LIBSYSTEM_HAS_UNWIND): Remove. * system.h (MD_UNWIND_SUPPORT): Poison. * doc/tm.texi.in (Exception Handling, MD_UNWIND_SUPPORT): Remove. * doc/tm.texi: Regenerate. * unwind-dw2.c: Include md-unwind-support.h instead of MD_UNWIND_SUPPORT. * config/ia64/unwind-ia64.c: Likewise. * config/xtensa/unwind-dw2-xtensa.c: Likewise. libgcc: * config/alpha/linux-unwind.h: Move from ../gcc/config/alpha. * config/alpha/osf5-unwind.h: Move from ../gcc/config/alpha. * config/alpha/vms-unwind.h: Move from ../gcc/config/alpha. * config/bfin/linux-unwind.h: Move from ../gcc/config/bfin. * config/i386/linux-unwind.h: Move from ../gcc/config/i386. * config/i386/sol2-unwind.h: Move from ../gcc/config/i386. * config/i386/w32-unwind.h: Move from ../gcc/config/i386. Wrap in !__MINGW64__. * config/ia64/linux-unwind.h: Move from ../gcc/config/ia64. * config/ia64/vms-unwind.h: Move from ../gcc/config/ia64. * config/m68k/linux-unwind.h: Move from ../gcc/config/m68k. * config/mips/linux-unwind.h: Move from ../gcc/config/mips. * config/pa/hpux-unwind.h: Move from ../gcc/config/pa. * config/pa/linux-unwind.h: Move from ../gcc/config/pa. * config/rs6000/darwin-unwind.h: Move from ../gcc/config/rs6000. Wrap in !__LP64__. * config/rs6000/linux-unwind.h: Move from ../gcc/config/rs6000. * config/s390/linux-unwind.h: Move from ../gcc/config/s390. * config/s390/tpf-unwind.h: Move from ../gcc/config/s390. * config/sh/linux-unwind.h: Move from ../gcc/config/sh. * config/sparc/linux-unwind.h: Move from ../gcc/config/sparc. * config/sparc/sol2-unwind.h: Move from ../gcc/config/sparc. * config/xtensa/linux-unwind.h: Move from ../gcc/config/xtensa. * config/no-unwind.h: New file. * config.host (md_unwind_header): Document. Define. (alpha*-*-linux*, alpha*-dec-osf5.1*, alpha64-dec-*vms*, alpha*-dec-*vms*, bfin*-uclinux*, bfin*-linux-uclibc*, hppa*-*-linux*, hppa[12]*-*-hpux10*, hppa*64*-*-hpux11*, hppa[12]*-*-hpux11*): Set md_unwind_header. (i[34567]86-*-linux*): Handle i[34567]86-*-kopensolaris*-gnu. Set md_unwind_header. (x86_64-*-linux*, i[34567]86-*-solaris2*): Set md_unwind_header. (i[34567]86-*-cygwin*): Split from i[34567]86-*-mingw*. (i[34567]86-*-mingw*, ia64*-*-linux*, ia64-hp-*vms*, m68k-*-uclinux*, m68k-*-linux*, mips64*-*-linux*, mips*-*-linux*, powerpc-*-darwin*, powerpc-*-linux*, s390-*-linux*, s390x-*-linux*, s390x-ibm-tpf*, sh*-*-linux*, sparc-*-linux*, sparc*-*-solaris2*, sparc64-*-linux*, xtensa*-*-linux*): Set md_unwind_header. * configure.ac: Link md-unwind-support.h to $md_unwind_header. * configure: Regenerate. From-SVN: r174613
209 lines
7.7 KiB
C
209 lines
7.7 KiB
C
/* Definitions for Dwarf2 EH unwind support for Windows32 targets
|
|
Copyright (C) 2007, 2009, 2010, 2011
|
|
Free Software Foundation, Inc.
|
|
Contributed by Pascal Obry <obry@adacore.com>
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
GCC 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 General Public License
|
|
for more details.
|
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
/* This file implements the md_fallback_frame_state_for routine for
|
|
Windows, triggered when the GCC table based unwinding process hits a
|
|
frame for which no unwind info has been registered. This typically
|
|
occurs when raising an exception from a signal handler, because the
|
|
handler is actually called from the OS kernel.
|
|
|
|
The basic idea is to detect that we are indeed trying to unwind past a
|
|
signal handler and to fill out the GCC internal unwinding structures for
|
|
the OS kernel frame as if it had been directly called from the
|
|
interrupted context.
|
|
|
|
This is all assuming that the code to set the handler asked the kernel
|
|
to pass a pointer to such context information.
|
|
|
|
There is three main parts.
|
|
|
|
1) The first thing to do is to check if we are in a signal context. If
|
|
not we can just return as there is nothing to do. We are probably on
|
|
some foreign code for which no unwind frame can be found. If this is
|
|
a call from the Windows signal handler, then:
|
|
|
|
2) We must get the signal context information.
|
|
|
|
* With the standard exception filter:
|
|
|
|
This is on Windows pointed to by an EXCEPTION_POINTERS. We know that
|
|
the signal handle will call an UnhandledExceptionFilter with this
|
|
parameter. The spec for this routine is:
|
|
|
|
LONG WINAPI UnhandledExceptionFilter(struct _EXCEPTION_POINTERS*);
|
|
|
|
So the pointer to struct _EXCEPTION_POINTERS must be somewhere on the
|
|
stack.
|
|
|
|
This was found experimentally to always be at offset 0 of the context
|
|
frame in all cases handled by this implementation.
|
|
|
|
* With the SEH exception handler:
|
|
|
|
In this case the signal context is directly on the stack as the SEH
|
|
exception handler has the following prototype:
|
|
|
|
DWORD
|
|
SEH_error_handler (PEXCEPTION_RECORD ExceptionRecord,
|
|
PVOID EstablisherFrame,
|
|
PCONTEXT ContextRecord,
|
|
PVOID DispatcherContext)
|
|
|
|
This was found experimentally to always be at offset 56 of the
|
|
context frame in all cases handled by this implementation.
|
|
|
|
3) When we have the signal context we just have to save some registers
|
|
and set the return address based on the program counter (Eip).
|
|
|
|
Note that this implementation follows closely the same principles as the
|
|
GNU/Linux and OSF ones. */
|
|
|
|
#ifndef __MINGW64__
|
|
|
|
#define WIN32_MEAN_AND_LEAN
|
|
#include <windows.h>
|
|
/* Patterns found experimentally to be on a Windows signal handler */
|
|
|
|
/* In a standard exception filter */
|
|
|
|
#define SIG_PAT1 \
|
|
(pc_[-2] == 0xff && pc_[-1] == 0xd0 /* call %eax */ \
|
|
&& pc_[0] == 0x83 && pc_[1] == 0xf8) /* cmp 0xdepl,%eax */
|
|
|
|
#define SIG_PAT2 \
|
|
(pc_[-5] == 0xe8 && pc_[-4] == 0x68 /* call (depl16) */ \
|
|
&& pc_[0] == 0xc3) /* ret */
|
|
|
|
/* In a Win32 SEH handler */
|
|
|
|
#define SIG_SEH1 \
|
|
(pc_[-5] == 0xe8 /* call addr */ \
|
|
&& pc_[0] == 0x83 && pc_[1] == 0xc4 /* add 0xval,%esp */ \
|
|
&& pc_[3] == 0xb8) /* mov 0xval,%eax */
|
|
|
|
#define SIG_SEH2 \
|
|
(pc_[-5] == 0x8b && pc_[-4] == 0x4d /* mov depl(%ebp),%ecx */ \
|
|
&& pc_[0] == 0x64 && pc_[1] == 0x8b) /* mov %fs:(0),<reg> */ \
|
|
|
|
/* In the GCC alloca (stack probing) */
|
|
|
|
#define SIG_ALLOCA \
|
|
(pc_[-1] == 0x83 /* orl $0x0,(%ecx) */ \
|
|
&& pc_[0] == 0x9 && pc_[1] == 0 \
|
|
&& pc_[2] == 0x2d && pc_[3] == 0 /* subl $0x1000,%eax */ \
|
|
&& pc_[4] == 0x10 && pc_[5] == 0)
|
|
|
|
|
|
#define MD_FALLBACK_FRAME_STATE_FOR i386_w32_fallback_frame_state
|
|
|
|
static _Unwind_Reason_Code
|
|
i386_w32_fallback_frame_state (struct _Unwind_Context *context,
|
|
_Unwind_FrameState *fs)
|
|
|
|
{
|
|
void * ctx_ra_ = (void *)(context->ra); /* return address */
|
|
void * ctx_cfa_ = (void *)(context->cfa); /* context frame address */
|
|
unsigned char * pc_ = (unsigned char *) ctx_ra_;
|
|
|
|
/* In the test below we look for two specific patterns found
|
|
experimentally to be in the Windows signal handler. */
|
|
if (SIG_PAT1 || SIG_PAT2 || SIG_SEH1 || SIG_SEH2)
|
|
{
|
|
PEXCEPTION_POINTERS weinfo_;
|
|
PCONTEXT proc_ctx_;
|
|
long new_cfa_;
|
|
|
|
if (SIG_SEH1)
|
|
proc_ctx_ = (PCONTEXT) (*(int*)(ctx_cfa_ + 56));
|
|
else if (SIG_SEH2)
|
|
proc_ctx_ = (PCONTEXT) (*(int*)(ctx_cfa_ + 8));
|
|
else
|
|
{
|
|
weinfo_ = (PEXCEPTION_POINTERS) (*(int*)ctx_cfa_);
|
|
proc_ctx_ = weinfo_->ContextRecord;
|
|
}
|
|
|
|
/* The new context frame address is the stack pointer. */
|
|
new_cfa_ = proc_ctx_->Esp;
|
|
fs->regs.cfa_how = CFA_REG_OFFSET;
|
|
fs->regs.cfa_reg = __builtin_dwarf_sp_column();
|
|
fs->regs.cfa_offset = new_cfa_ - (long) ctx_cfa_;
|
|
|
|
/* Restore registers. */
|
|
fs->regs.reg[0].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[0].loc.offset = (long)&proc_ctx_->Eax - new_cfa_;
|
|
fs->regs.reg[3].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[3].loc.offset = (long)&proc_ctx_->Ebx - new_cfa_;
|
|
fs->regs.reg[1].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[1].loc.offset = (long)&proc_ctx_->Ecx - new_cfa_;
|
|
fs->regs.reg[2].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[2].loc.offset = (long)&proc_ctx_->Edx - new_cfa_;
|
|
fs->regs.reg[6].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[6].loc.offset = (long)&proc_ctx_->Esi - new_cfa_;
|
|
fs->regs.reg[7].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[7].loc.offset = (long)&proc_ctx_->Edi - new_cfa_;
|
|
fs->regs.reg[5].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[5].loc.offset = (long)&proc_ctx_->Ebp - new_cfa_;
|
|
fs->regs.reg[8].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[8].loc.offset = (long)&proc_ctx_->Eip - new_cfa_;
|
|
fs->retaddr_column = 8;
|
|
fs->signal_frame = 1;
|
|
|
|
return _URC_NO_REASON;
|
|
}
|
|
|
|
/* Unwinding through _alloca, propagating from a trap triggered by
|
|
one of it's probes prior to the real SP adjustment. The only
|
|
operations of interest performed is "pushl %ecx", followed by
|
|
ecx clobbering. */
|
|
else if (SIG_ALLOCA)
|
|
{
|
|
/* Only one push between entry in _alloca and the probe trap. */
|
|
long new_cfa_ = (long) ctx_cfa_ + 4;
|
|
|
|
fs->regs.cfa_how = CFA_REG_OFFSET;
|
|
fs->regs.cfa_reg = __builtin_dwarf_sp_column();
|
|
fs->regs.cfa_offset = new_cfa_ - (long) ctx_cfa_;
|
|
|
|
/* The saved value of %ecx is at CFA - 4 */
|
|
fs->regs.reg[1].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[1].loc.offset = -4;
|
|
|
|
/* and what is stored at the CFA is the return address. */
|
|
fs->retaddr_column = 8;
|
|
fs->regs.reg[8].how = REG_SAVED_OFFSET;
|
|
fs->regs.reg[8].loc.offset = 0;
|
|
fs->signal_frame = 1;
|
|
|
|
return _URC_NO_REASON;
|
|
}
|
|
else
|
|
return _URC_END_OF_STACK;
|
|
}
|
|
|
|
#endif /* !__MINGW64__ */
|