aboutsummaryrefslogtreecommitdiff
path: root/libgcc/unwind-sjlj.c
diff options
context:
space:
mode:
authorRainer Orth <ro@gcc.gnu.org>2011-08-05 14:37:48 +0000
committerRainer Orth <ro@gcc.gnu.org>2011-08-05 14:37:48 +0000
commit201cdb743879cbffd38c53d8ebf85fa9fff1e0e4 (patch)
tree80376027cf518687afe9d3c715d908e42d42c267 /libgcc/unwind-sjlj.c
parentd50f4827c7062e3247baf493e646c365114c28cd (diff)
downloadgcc-201cdb743879cbffd38c53d8ebf85fa9fff1e0e4.zip
gcc-201cdb743879cbffd38c53d8ebf85fa9fff1e0e4.tar.gz
gcc-201cdb743879cbffd38c53d8ebf85fa9fff1e0e4.tar.bz2
Makefile.in (UNWIND_H): Remove.
gcc: * Makefile.in (UNWIND_H): Remove. (LIB2ADDEH, LIB2ADDEHSTATIC, LIB2ADDEHSHARED): Move to ../libgcc/Makefile.in. (LIBUNWIND, SHLIBUNWIND_LINK, SHLIBUNWIND_INSTALL): Likewise. (LIBUNWINDDEP): Remove. (libgcc-support): Remove LIB2ADDEH, $(srcdir)/emutls.c dependencies. (libgcc.mvars): Remove LIB2ADDEH, LIB2ADDEHSTATIC, LIB2ADDEHSHARED, LIBUNWIND, SHLIBUNWIND_LINK, SHLIBUNWIND_INSTALL. (stmp-int-hdrs): Remove $(UNWIND_H) dependency. Don't copy $(UNWIND_H). * config.gcc (ia64*-*-linux*): Remove with_system_libunwind handling. * configure.ac (GCC_CHECK_UNWIND_GETIPINFO): Remove. * aclocal.m4: Regenerate. * configure: Regenerate. * emutls.c, unwind-c.c, unwind-compat.c, unwind-compat.h, unwind-dw2-fde-compat.c, unwind-dw2-fde-glibc.c, unwind-dw2-fde.c, unwind-dw2-fde.h, unwind-dw2.c, unwind-dw2.h, unwind-generic.h, unwind-pe.h, unwind-sjlj.c, unwind.inc: Move to ../libgcc. * unwind-dw2-fde-darwin.c: Move to ../libgcc/config. * config/arm/libunwind.S, config/arm/pr-support.c, config/arm/unwind-arm.c, config/arm/unwind-arm.h: Move to ../libgcc/config/arm. * config/arm/t-bpabi (UNWIND_H, LIB2ADDEH): Remove. * config/arm/t-symbian (UNWIND_H, LIB2ADDEH): Remove. * config/frv/t-frv ($(T)frvbegin$(objext)): Use $(srcdir)/../libgcc to refer to unwind-dw2-fde.h. ($(T)frvend$(objext)): Likewise. * config/ia64/t-glibc (LIB2ADDEH): Remove. * config/ia64/t-glibc-libunwind: Move to ../libgcc/config/ia64. * config/ia64/fde-glibc.c, config/ia64/fde-vms.c, config/ia64/unwind-ia64.c, config/ia64/unwind-ia64.h: Move to ../libgcc/config/ia64. * config/ia64/t-hpux (LIB2ADDEH): Remove. * config/ia64/t-ia64 (LIB2ADDEH): Remove. * config/ia64/t-vms (LIB2ADDEH): Remove. * config/ia64/vms.h (UNW_IVMS_MODE, MD_UNW_COMPATIBLE_PERSONALITY_P): Remove. * config/picochip/t-picochip (LIB2ADDEH): Remove. * config/rs6000/aix.h (R_LR, MD_FROB_UPDATE_CONTEXT): Remove. * config/rs6000/t-darwin (LIB2ADDEH): Remove. * config/rs6000/darwin-fallback.c: Move to ../libgcc/config/rs6000. * config/sh/t-sh ($(T)unwind-dw2-Os-4-200.o): Use $(srcdir)/../libgcc to refer to unwinder sources. * config/spu/t-spu-elf (LIB2ADDEH): Remove. * config/t-darwin (LIB2ADDEH): Remove. * config/t-freebsd (LIB2ADDEH): Remove. * config/t-libunwind (LIB2ADDEH, LIB2ADDEHSTATIC): Remove. * config/t-libunwind-elf: Move to ../libgcc/config. * config/t-linux (LIB2ADDEH): Remove. * config/t-sol2 (LIB2ADDEH): Remove. * config/xtensa/t-xtensa (LIB2ADDEH): Remove. * system.h (MD_FROB_UPDATE_CONTEXT): Poison. gcc/po: * EXCLUDES (unwind-c.c, unwind-dw2-fde-darwin.c) (unwind-dw2-fde-glibc.c, unwind-dw2-fde.c, unwind-dw2-fde.h) (unwind-dw2.c, unwind-pe.h, unwind-sjlj.c, unwind.h): Remove. libgcc: * Makefile.in (LIB2ADDEH, LIB2ADDEHSTATIC, LIB2ADDEHSHARED): New variables. (LIBUNWIND, SHLIBUNWIND_LINK, SHLIBUNWIND_INSTALL): New variables. (LIB2ADDEH, LIB2ADDEHSTATIC, LIB2ADDEHSHARED): Add $(srcdir)/emutls.c. (install-unwind_h): New target. (all): Depend on it. * config.host (unwind_header): New variable. (*-*-freebsd*): Set tmake_file to t-eh-dw2-dip. (*-*-linux*, frv-*-*linux*, *-*-kfreebsd*-gnu, *-*-knetbsd*-gnu, *-*-gnu*): Likewise, also for *-*-kopensolaris*-gnu. (*-*-solaris2*): Add t-eh-dw2-dip to tmake_file. (arm*-*-linux*): Add arm/t-bpabi for arm*-*-linux-*eabi. Set unwind_header. (arm*-*-uclinux*): Add arm/t-bpabi for arm*-*-uclinux*eabi. Set unwind_header. (arm*-*-eabi*, arm*-*-symbianelf*): Add arm/t-bpabi for arm*-*-eabi*. Add arm/t-symbian to tmake_file for arm*-*-symbianelf*. Set unwind_header. (ia64*-*-elf*): Add ia64/t-eh-ia64 to tmake_file. (ia64*-*-freebsd*): Likewise. (ia64*-*-linux*): Add ia64/t-glibc, ia64/t-eh-ia64, t-libunwind to tmake_file. Add t-libunwind-elf, ia64/t-glibc-libunwind unless $with_system_libunwind. (ia64*-*-hpux*): Set tmake_file. (ia64-hp-*vms*): Add ia64/t-eh-ia64 to tmake_file. (picochip-*-*): Set tmake_file. (rs6000-ibm-aix4.[3456789]*, powerpc-ibm-aix4.[3456789]*): Set md_unwind_header. (rs6000-ibm-aix5.1.*, powerpc-ibm-aix5.1.*): Likewise. (rs6000-ibm-aix[56789].*, powerpc-ibm-aix[56789].*): Likewise. (s390x-ibm-tpf*): Add t-eh-dw2-dip to tmake_file. (xtensa*-*-elf*): Set tmake_file. (xtensa*-*-linux*): Likewise. * configure.ac: Include ../config/unwind_ipinfo.m4. Call GCC_CHECK_UNWIND_GETIPINFO. Link unwind.h to $unwind_header. * configure: Regenerate. * emutls.c, unwind-c.c, unwind-compat.c, unwind-compat.h, unwind-dw2-fde-compat.c, unwind-dw2-fde-dip.c, unwind-dw2-fde.c, unwind-dw2-fde.h, unwind-dw2.c, unwind-dw2.h, unwind-generic.h, unwind-pe.h, unwind-sjlj.c, unwind.inc: New files. * config/unwind-dw2-fde-darwin.c: New file. * config/arm/libunwind.S, config/arm/pr-support.c, config/arm/t-bpabi, config/arm/t-symbian, config/arm/unwind-arm.c, config/arm/unwind-arm.h,: New files. * config/ia64/fde-glibc.c, config/ia64/fde-vms.c, config/ia64/t-eh-ia64, config/ia64/t-glibc, config/ia64/t-glibc-libunwind, config/ia64/t-hpux, config/ia64/t-vms, config/ia64/unwind-ia64.c, config/ia64/unwind-ia64.h: New files. * config/picochip/t-picochip: New file. * config/rs6000/aix-unwind.h, config/rs6000/darwin-fallback.c: New files. * config/rs6000/t-darwin (LIB2ADDEH): Set. * config/s390/t-tpf (LIB2ADDEH): Remove. * config/t-darwin (LIB2ADDEH): Set. * config/t-eh-dw2-dip: New file. * config/t-libunwind, config/t-libunwind-elf: New files. * config/t-sol2 (LIB2ADDEH): Remove. * config/xtensa/t-xtensa: New file. gcc/ada: * gcc-interface/Makefile.in (raise-gcc.o): Search $(srcdir)/../libgcc. libgo: * Makefile.am (AM_CFLAGS): Search $(srcdir)/../libgcc. * Makefile.in: Regenerate. libjava: * configure.ac (GCC_UNWIND_INCLUDE): Rename to LIBGCC_UNWIND_INCLUDE. Point to $(multi_basedir)/./libjava/../libgcc. * configure: Regenerate. * Makefile.am (GCC_UNWIND_INCLUDE): Reflect this. * Makefile.in: Regenerate. libobjc: * Makefile.in (INCLUDES): Search $(srcdir)/$(MULTISRCTOP)../libgcc. libstdc++-v3: * acinclude.m4 (GLIBCXX_EXPORT_INCLUDES): Point TOPLEVEL_INCLUDES to $(toplevel_srcdir)/libgcc. * configure: Regenerate. From-SVN: r177447
Diffstat (limited to 'libgcc/unwind-sjlj.c')
-rw-r--r--libgcc/unwind-sjlj.c326
1 files changed, 326 insertions, 0 deletions
diff --git a/libgcc/unwind-sjlj.c b/libgcc/unwind-sjlj.c
new file mode 100644
index 0000000..c71e798
--- /dev/null
+++ b/libgcc/unwind-sjlj.c
@@ -0,0 +1,326 @@
+/* SJLJ exception handling and frame unwind runtime interface routines.
+ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006,
+ 2009 Free Software Foundation, Inc.
+
+ 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/>. */
+
+#include "tconfig.h"
+#include "tsystem.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "unwind.h"
+#include "gthr.h"
+
+#ifdef __USING_SJLJ_EXCEPTIONS__
+
+#ifdef DONT_USE_BUILTIN_SETJMP
+#ifndef inhibit_libc
+#include <setjmp.h>
+#else
+typedef void *jmp_buf[JMP_BUF_SIZE];
+extern void longjmp(jmp_buf, int) __attribute__((noreturn));
+#endif
+#else
+#define longjmp __builtin_longjmp
+#endif
+
+/* The setjmp side is dealt with in the except.c file. */
+#undef setjmp
+#define setjmp setjmp_should_not_be_used_in_this_file
+
+
+/* This structure is allocated on the stack of the target function.
+ This must match the definition created in except.c:init_eh. */
+struct SjLj_Function_Context
+{
+ /* This is the chain through all registered contexts. It is
+ filled in by _Unwind_SjLj_Register. */
+ struct SjLj_Function_Context *prev;
+
+ /* This is assigned in by the target function before every call
+ to the index of the call site in the lsda. It is assigned by
+ the personality routine to the landing pad index. */
+ int call_site;
+
+ /* This is how data is returned from the personality routine to
+ the target function's handler. */
+ _Unwind_Word data[4];
+
+ /* These are filled in once by the target function before any
+ exceptions are expected to be handled. */
+ _Unwind_Personality_Fn personality;
+ void *lsda;
+
+#ifdef DONT_USE_BUILTIN_SETJMP
+ /* We don't know what sort of alignment requirements the system
+ jmp_buf has. We over estimated in except.c, and now we have
+ to match that here just in case the system *didn't* have more
+ restrictive requirements. */
+ jmp_buf jbuf __attribute__((aligned));
+#else
+ void *jbuf[];
+#endif
+};
+
+struct _Unwind_Context
+{
+ struct SjLj_Function_Context *fc;
+};
+
+typedef struct
+{
+ _Unwind_Personality_Fn personality;
+} _Unwind_FrameState;
+
+
+/* Manage the chain of registered function contexts. */
+
+/* Single threaded fallback chain. */
+static struct SjLj_Function_Context *fc_static;
+
+#if __GTHREADS
+static __gthread_key_t fc_key;
+static int use_fc_key = -1;
+
+static void
+fc_key_init (void)
+{
+ use_fc_key = __gthread_key_create (&fc_key, 0) == 0;
+}
+
+static void
+fc_key_init_once (void)
+{
+ static __gthread_once_t once = __GTHREAD_ONCE_INIT;
+ if (__gthread_once (&once, fc_key_init) != 0 || use_fc_key < 0)
+ use_fc_key = 0;
+}
+#endif
+
+void
+_Unwind_SjLj_Register (struct SjLj_Function_Context *fc)
+{
+#if __GTHREADS
+ if (use_fc_key < 0)
+ fc_key_init_once ();
+
+ if (use_fc_key)
+ {
+ fc->prev = __gthread_getspecific (fc_key);
+ __gthread_setspecific (fc_key, fc);
+ }
+ else
+#endif
+ {
+ fc->prev = fc_static;
+ fc_static = fc;
+ }
+}
+
+static inline struct SjLj_Function_Context *
+_Unwind_SjLj_GetContext (void)
+{
+#if __GTHREADS
+ if (use_fc_key < 0)
+ fc_key_init_once ();
+
+ if (use_fc_key)
+ return __gthread_getspecific (fc_key);
+#endif
+ return fc_static;
+}
+
+static inline void
+_Unwind_SjLj_SetContext (struct SjLj_Function_Context *fc)
+{
+#if __GTHREADS
+ if (use_fc_key < 0)
+ fc_key_init_once ();
+
+ if (use_fc_key)
+ __gthread_setspecific (fc_key, fc);
+ else
+#endif
+ fc_static = fc;
+}
+
+void
+_Unwind_SjLj_Unregister (struct SjLj_Function_Context *fc)
+{
+ _Unwind_SjLj_SetContext (fc->prev);
+}
+
+
+/* Get/set the return data value at INDEX in CONTEXT. */
+
+_Unwind_Word
+_Unwind_GetGR (struct _Unwind_Context *context, int index)
+{
+ return context->fc->data[index];
+}
+
+/* Get the value of the CFA as saved in CONTEXT. */
+
+_Unwind_Word
+_Unwind_GetCFA (struct _Unwind_Context *context __attribute__((unused)))
+{
+ /* ??? Ideally __builtin_setjmp places the CFA in the jmpbuf. */
+
+#ifndef DONT_USE_BUILTIN_SETJMP
+ /* This is a crude imitation of the CFA: the saved stack pointer.
+ This is roughly the CFA of the frame before CONTEXT. When using the
+ DWARF-2 unwinder _Unwind_GetCFA returns the CFA of the frame described
+ by CONTEXT instead; but for DWARF-2 the cleanups associated with
+ CONTEXT have already been run, and for SJLJ they have not yet been. */
+ if (context->fc != NULL)
+ return (_Unwind_Word) context->fc->jbuf[2];
+#endif
+
+ /* Otherwise we're out of luck for now. */
+ return (_Unwind_Word) 0;
+}
+
+void
+_Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
+{
+ context->fc->data[index] = val;
+}
+
+/* Get the call-site index as saved in CONTEXT. */
+
+_Unwind_Ptr
+_Unwind_GetIP (struct _Unwind_Context *context)
+{
+ return context->fc->call_site + 1;
+}
+
+_Unwind_Ptr
+_Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
+{
+ *ip_before_insn = 0;
+ if (context->fc != NULL)
+ return context->fc->call_site + 1;
+ else
+ return 0;
+}
+
+/* Set the return landing pad index in CONTEXT. */
+
+void
+_Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
+{
+ context->fc->call_site = val - 1;
+}
+
+void *
+_Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
+{
+ return context->fc->lsda;
+}
+
+_Unwind_Ptr
+_Unwind_GetRegionStart (struct _Unwind_Context *context __attribute__((unused)) )
+{
+ return 0;
+}
+
+void *
+_Unwind_FindEnclosingFunction (void *pc __attribute__((unused)))
+{
+ return NULL;
+}
+
+#ifndef __ia64__
+_Unwind_Ptr
+_Unwind_GetDataRelBase (struct _Unwind_Context *context __attribute__((unused)) )
+{
+ return 0;
+}
+
+_Unwind_Ptr
+_Unwind_GetTextRelBase (struct _Unwind_Context *context __attribute__((unused)) )
+{
+ return 0;
+}
+#endif
+
+static inline _Unwind_Reason_Code
+uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
+{
+ if (context->fc == NULL)
+ {
+ fs->personality = NULL;
+ return _URC_END_OF_STACK;
+ }
+ else
+ {
+ fs->personality = context->fc->personality;
+ return _URC_NO_REASON;
+ }
+}
+
+static inline void
+uw_update_context (struct _Unwind_Context *context,
+ _Unwind_FrameState *fs __attribute__((unused)) )
+{
+ context->fc = context->fc->prev;
+}
+
+static void
+uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
+{
+ _Unwind_SjLj_Unregister (context->fc);
+ uw_update_context (context, fs);
+}
+
+static inline void
+uw_init_context (struct _Unwind_Context *context)
+{
+ context->fc = _Unwind_SjLj_GetContext ();
+}
+
+static void __attribute__((noreturn))
+uw_install_context (struct _Unwind_Context *current __attribute__((unused)),
+ struct _Unwind_Context *target)
+{
+ _Unwind_SjLj_SetContext (target->fc);
+ longjmp (target->fc->jbuf, 1);
+}
+
+static inline _Unwind_Ptr
+uw_identify_context (struct _Unwind_Context *context)
+{
+ return (_Unwind_Ptr) context->fc;
+}
+
+
+/* Play games with unwind symbols so that we can have call frame
+ and sjlj symbols in the same shared library. Not that you can
+ use them simultaneously... */
+#define _Unwind_RaiseException _Unwind_SjLj_RaiseException
+#define _Unwind_ForcedUnwind _Unwind_SjLj_ForcedUnwind
+#define _Unwind_Resume _Unwind_SjLj_Resume
+#define _Unwind_Resume_or_Rethrow _Unwind_SjLj_Resume_or_Rethrow
+
+#include "unwind.inc"
+
+#endif /* USING_SJLJ_EXCEPTIONS */