eh_throw.cc revision 117397
1270161Simp// -*- C++ -*- Exception handling routines for throwing. 2270161Simp// Copyright (C) 2001, 2003 Free Software Foundation, Inc. 3270161Simp// 4270161Simp// This file is part of GNU CC. 5270161Simp// 6270161Simp// GNU CC is free software; you can redistribute it and/or modify 7270161Simp// it under the terms of the GNU General Public License as published by 8270161Simp// the Free Software Foundation; either version 2, or (at your option) 9270161Simp// any later version. 10270161Simp// 11270161Simp// GNU CC is distributed in the hope that it will be useful, 12270161Simp// but WITHOUT ANY WARRANTY; without even the implied warranty of 13270161Simp// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14270161Simp// GNU General Public License for more details. 15270161Simp// 16270161Simp// You should have received a copy of the GNU General Public License 17270161Simp// along with GNU CC; see the file COPYING. If not, write to 18270161Simp// the Free Software Foundation, 59 Temple Place - Suite 330, 19270161Simp// Boston, MA 02111-1307, USA. 20270161Simp 21270161Simp// As a special exception, you may use this file as part of a free software 22270161Simp// library without restriction. Specifically, if other files instantiate 23270161Simp// templates or use macros or inline functions from this file, or you compile 24270161Simp// this file and link it with other files to produce an executable, this 25270161Simp// file does not by itself cause the resulting executable to be covered by 26270161Simp// the GNU General Public License. This exception does not however 27270161Simp// invalidate any other reasons why the executable file might be covered by 28270161Simp// the GNU General Public License. 29270161Simp 30270161Simp 31270161Simp#include <bits/c++config.h> 32270161Simp#include "unwind-cxx.h" 33270161Simp 34270161Simp 35270161Simpusing namespace __cxxabiv1; 36270161Simp 37270161Simp 38static void 39__gxx_exception_cleanup (_Unwind_Reason_Code code, _Unwind_Exception *exc) 40{ 41 __cxa_exception *header = __get_exception_header_from_ue (exc); 42 43 // If we haven't been caught by a foreign handler, then this is 44 // some sort of unwind error. In that case just die immediately. 45 // _Unwind_DeleteException in the HP-UX IA64 libunwind library 46 // returns _URC_NO_REASON and not _URC_FOREIGN_EXCEPTION_CAUGHT 47 // like the GCC _Unwind_DeleteException function does. 48 if (code != _URC_FOREIGN_EXCEPTION_CAUGHT && code != _URC_NO_REASON) 49 __terminate (header->terminateHandler); 50 51 if (header->exceptionDestructor) 52 header->exceptionDestructor (header + 1); 53 54 __cxa_free_exception (header + 1); 55} 56 57 58extern "C" void 59__cxa_throw (void *obj, std::type_info *tinfo, void (*dest) (void *)) 60{ 61 __cxa_exception *header = __get_exception_header_from_obj (obj); 62 header->exceptionType = tinfo; 63 header->exceptionDestructor = dest; 64 header->unexpectedHandler = __unexpected_handler; 65 header->terminateHandler = __terminate_handler; 66 header->unwindHeader.exception_class = __gxx_exception_class; 67 header->unwindHeader.exception_cleanup = __gxx_exception_cleanup; 68 69 __cxa_eh_globals *globals = __cxa_get_globals (); 70 globals->uncaughtExceptions += 1; 71 72#ifdef _GLIBCPP_SJLJ_EXCEPTIONS 73 _Unwind_SjLj_RaiseException (&header->unwindHeader); 74#else 75 _Unwind_RaiseException (&header->unwindHeader); 76#endif 77 78 // Some sort of unwinding error. Note that terminate is a handler. 79 __cxa_begin_catch (&header->unwindHeader); 80 std::terminate (); 81} 82 83extern "C" void 84__cxa_rethrow () 85{ 86 __cxa_eh_globals *globals = __cxa_get_globals (); 87 __cxa_exception *header = globals->caughtExceptions; 88 89 // Watch for luser rethrowing with no active exception. 90 if (header) 91 { 92 // Tell __cxa_end_catch this is a rethrow. 93 if (header->unwindHeader.exception_class != __gxx_exception_class) 94 globals->caughtExceptions = 0; 95 else 96 header->handlerCount = -header->handlerCount; 97 98#ifdef _GLIBCPP_SJLJ_EXCEPTIONS 99 _Unwind_SjLj_Resume_or_Rethrow (&header->unwindHeader); 100#else 101#ifdef _LIBUNWIND_STD_ABI 102 _Unwind_RaiseException (&header->unwindHeader); 103#else 104 _Unwind_Resume_or_Rethrow (&header->unwindHeader); 105#endif 106#endif 107 108 // Some sort of unwinding error. Note that terminate is a handler. 109 __cxa_begin_catch (&header->unwindHeader); 110 } 111 std::terminate (); 112} 113