unwind-cxx.h revision 132720
197403Sobrien// -*- C++ -*- Exception handling and frame unwind runtime interface routines.
297403Sobrien// Copyright (C) 2001 Free Software Foundation, Inc.
397403Sobrien//
4132720Skan// This file is part of GCC.
597403Sobrien//
6132720Skan// GCC is free software; you can redistribute it and/or modify
797403Sobrien// it under the terms of the GNU General Public License as published by
897403Sobrien// the Free Software Foundation; either version 2, or (at your option)
997403Sobrien// any later version.
1097403Sobrien//
11132720Skan// GCC is distributed in the hope that it will be useful,
1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1497403Sobrien// GNU General Public License for more details.
1597403Sobrien//
1697403Sobrien// You should have received a copy of the GNU General Public License
17132720Skan// along with GCC; see the file COPYING.  If not, write to
1897403Sobrien// the Free Software Foundation, 59 Temple Place - Suite 330,
1997403Sobrien// Boston, MA 02111-1307, USA.
2097403Sobrien
2197403Sobrien// As a special exception, you may use this file as part of a free software
2297403Sobrien// library without restriction.  Specifically, if other files instantiate
2397403Sobrien// templates or use macros or inline functions from this file, or you compile
2497403Sobrien// this file and link it with other files to produce an executable, this
2597403Sobrien// file does not by itself cause the resulting executable to be covered by
2697403Sobrien// the GNU General Public License.  This exception does not however
2797403Sobrien// invalidate any other reasons why the executable file might be covered by
2897403Sobrien// the GNU General Public License.
2997403Sobrien
3097403Sobrien// This is derived from the C++ ABI for IA-64.  Where we diverge
3197403Sobrien// for cross-architecture compatibility are noted with "@@@".
3297403Sobrien
33132720Skan#ifndef _UNWIND_CXX_H
34132720Skan#define _UNWIND_CXX_H 1
3597403Sobrien
3697403Sobrien// Level 2: C++ ABI
3797403Sobrien
3897403Sobrien#include <typeinfo>
3997403Sobrien#include <exception>
4097403Sobrien#include <cstddef>
4197403Sobrien#include "unwind.h"
4297403Sobrien
4397403Sobriennamespace __cxxabiv1
4497403Sobrien{
4597403Sobrien
4697403Sobrien// A C++ exception object consists of a header, which is a wrapper around
4797403Sobrien// an unwind object header with additional C++ specific information,
4897403Sobrien// followed by the exception object itself.
4997403Sobrien
5097403Sobrienstruct __cxa_exception
5197403Sobrien{
5297403Sobrien  // Manage the exception object itself.
5397403Sobrien  std::type_info *exceptionType;
5497403Sobrien  void (*exceptionDestructor)(void *);
5597403Sobrien
5697403Sobrien  // The C++ standard has entertaining rules wrt calling set_terminate
5797403Sobrien  // and set_unexpected in the middle of the exception cleanup process.
5897403Sobrien  std::unexpected_handler unexpectedHandler;
5997403Sobrien  std::terminate_handler terminateHandler;
6097403Sobrien
6197403Sobrien  // The caught exception stack threads through here.
6297403Sobrien  __cxa_exception *nextException;
6397403Sobrien
6497403Sobrien  // How many nested handlers have caught this exception.  A negated
6597403Sobrien  // value is a signal that this object has been rethrown.
6697403Sobrien  int handlerCount;
6797403Sobrien
6897403Sobrien  // Cache parsed handler data from the personality routine Phase 1
6997403Sobrien  // for Phase 2 and __cxa_call_unexpected.
7097403Sobrien  int handlerSwitchValue;
7197403Sobrien  const unsigned char *actionRecord;
7297403Sobrien  const unsigned char *languageSpecificData;
73117397Skan  _Unwind_Ptr catchTemp;
7497403Sobrien  void *adjustedPtr;
7597403Sobrien
7697403Sobrien  // The generic exception header.  Must be last.
7797403Sobrien  _Unwind_Exception unwindHeader;
7897403Sobrien};
7997403Sobrien
8097403Sobrien// Each thread in a C++ program has access to a __cxa_eh_globals object.
8197403Sobrienstruct __cxa_eh_globals
8297403Sobrien{
8397403Sobrien  __cxa_exception *caughtExceptions;
8497403Sobrien  unsigned int uncaughtExceptions;
8597403Sobrien};
8697403Sobrien
8797403Sobrien
8897403Sobrien// The __cxa_eh_globals for the current thread can be obtained by using
8997403Sobrien// either of the following functions.  The "fast" version assumes at least
9097403Sobrien// one prior call of __cxa_get_globals has been made from the current
9197403Sobrien// thread, so no initialization is necessary.
9297403Sobrienextern "C" __cxa_eh_globals *__cxa_get_globals () throw();
9397403Sobrienextern "C" __cxa_eh_globals *__cxa_get_globals_fast () throw();
9497403Sobrien
9597403Sobrien// Allocate memory for the exception plus the thown object.
9697403Sobrienextern "C" void *__cxa_allocate_exception(std::size_t thrown_size) throw();
9797403Sobrien
9897403Sobrien// Free the space allocated for the exception.
9997403Sobrienextern "C" void __cxa_free_exception(void *thrown_exception) throw();
10097403Sobrien
10197403Sobrien// Throw the exception.
10297403Sobrienextern "C" void __cxa_throw (void *thrown_exception,
10397403Sobrien			     std::type_info *tinfo,
10497403Sobrien			     void (*dest) (void *))
10597403Sobrien     __attribute__((noreturn));
10697403Sobrien
10797403Sobrien// Used to implement exception handlers.
10897403Sobrienextern "C" void *__cxa_begin_catch (void *) throw();
10997403Sobrienextern "C" void __cxa_end_catch ();
11097403Sobrienextern "C" void __cxa_rethrow () __attribute__((noreturn));
11197403Sobrien
11297403Sobrien// These facilitate code generation for recurring situations.
11397403Sobrienextern "C" void __cxa_bad_cast ();
11497403Sobrienextern "C" void __cxa_bad_typeid ();
11597403Sobrien
11697403Sobrien// @@@ These are not directly specified by the IA-64 C++ ABI.
11797403Sobrien
11897403Sobrien// Handles re-checking the exception specification if unexpectedHandler
11997403Sobrien// throws, and if bad_exception needs to be thrown.  Called from the
12097403Sobrien// compiler.
12197403Sobrienextern "C" void __cxa_call_unexpected (void *) __attribute__((noreturn));
12297403Sobrien
12397403Sobrien// Invokes given handler, dying appropriately if the user handler was
12497403Sobrien// so inconsiderate as to return.
12597403Sobrienextern void __terminate(std::terminate_handler) __attribute__((noreturn));
12697403Sobrienextern void __unexpected(std::unexpected_handler) __attribute__((noreturn));
12797403Sobrien
12897403Sobrien// The current installed user handlers.
12997403Sobrienextern std::terminate_handler __terminate_handler;
13097403Sobrienextern std::unexpected_handler __unexpected_handler;
13197403Sobrien
13297403Sobrien// These are explicitly GNU C++ specific.
13397403Sobrien
13497403Sobrien// This is the exception class we report -- "GNUCC++\0".
13597403Sobrienconst _Unwind_Exception_Class __gxx_exception_class
13697403Sobrien= ((((((((_Unwind_Exception_Class) 'G'
13797403Sobrien	 << 8 | (_Unwind_Exception_Class) 'N')
13897403Sobrien	<< 8 | (_Unwind_Exception_Class) 'U')
13997403Sobrien       << 8 | (_Unwind_Exception_Class) 'C')
14097403Sobrien      << 8 | (_Unwind_Exception_Class) 'C')
14197403Sobrien     << 8 | (_Unwind_Exception_Class) '+')
14297403Sobrien    << 8 | (_Unwind_Exception_Class) '+')
14397403Sobrien   << 8 | (_Unwind_Exception_Class) '\0');
14497403Sobrien
14597403Sobrien// GNU C++ personality routine, Version 0.
14697403Sobrienextern "C" _Unwind_Reason_Code __gxx_personality_v0
14797403Sobrien     (int, _Unwind_Action, _Unwind_Exception_Class,
14897403Sobrien      struct _Unwind_Exception *, struct _Unwind_Context *);
14997403Sobrien
15097403Sobrien// GNU C++ sjlj personality routine, Version 0.
15197403Sobrienextern "C" _Unwind_Reason_Code __gxx_personality_sj0
15297403Sobrien     (int, _Unwind_Action, _Unwind_Exception_Class,
15397403Sobrien      struct _Unwind_Exception *, struct _Unwind_Context *);
15497403Sobrien
15597403Sobrien// Acquire the C++ exception header from the C++ object.
15697403Sobrienstatic inline __cxa_exception *
15797403Sobrien__get_exception_header_from_obj (void *ptr)
15897403Sobrien{
15997403Sobrien  return reinterpret_cast<__cxa_exception *>(ptr) - 1;
16097403Sobrien}
16197403Sobrien
16297403Sobrien// Acquire the C++ exception header from the generic exception header.
16397403Sobrienstatic inline __cxa_exception *
16497403Sobrien__get_exception_header_from_ue (_Unwind_Exception *exc)
16597403Sobrien{
16697403Sobrien  return reinterpret_cast<__cxa_exception *>(exc + 1) - 1;
16797403Sobrien}
16897403Sobrien
16997403Sobrien} /* namespace __cxxabiv1 */
17097403Sobrien
171132720Skan#endif // _UNWIND_CXX_H
172