1/* except-gcc.h -*-C++-*- 2 * 3 ************************************************************************* 4 * 5 * @copyright 6 * Copyright (C) 2009-2013, Intel Corporation 7 * All rights reserved. 8 * 9 * @copyright 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 14 * * Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * * Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * * Neither the name of Intel Corporation nor the names of its 21 * contributors may be used to endorse or promote products derived 22 * from this software without specific prior written permission. 23 * 24 * @copyright 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 32 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 33 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 35 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 **************************************************************************/ 38 39/** 40 * @file except-gcc.h 41 * 42 * @brief ABI for gcc exception handling. 43 * 44 * @par Origin 45 * The code below is generally copied from the Intel Itanium ABI (Intel 46 * download 245370). 47 */ 48 49#ifndef INCLUDED_EXCEPT_GCC_DOT_H 50#define INCLUDED_EXCEPT_GCC_DOT_H 51 52#ifndef __cplusplus 53# error except-gcc.h should be used in C++ code only. 54#endif 55 56#include <cilk/common.h> 57#include <exception> 58#include <typeinfo> 59 60struct __cxa_exception; 61 62__CILKRTS_BEGIN_EXTERN_C 63 64/** Unwind reason code (Itanium ABI 6.1.2.1) */ 65typedef enum _Unwind_Reason_Code { 66 _URC_NO_REASON = 0, 67 _URC_FOREIGN_EXCEPTION_CAUGHT = 1, 68 _URC_FATAL_PHASE2_ERROR = 2, 69 _URC_FATAL_PHASE1_ERROR = 3, 70 _URC_NORMAL_STOP = 4, 71 _URC_END_OF_STACK = 5, 72 _URC_HANDLER_FOUND = 6, 73 _URC_INSTALL_CONTEXT = 7, 74 _URC_CONTINUE_UNWIND = 8 75} _Unwind_Reason_Code; 76 77typedef struct _Unwind_Exception _Unwind_Exception; 78 79/** Exception cleanup function pointer (Itanium ABI 6.1.2.2) */ 80typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code reason, 81 _Unwind_Exception *exc); 82 83/** 84 * @brief Exception undwinding information 85 * 86 * This is copied from the Intel Itanium ABI except that the 87 * private fields are declared unsigned long for binary 88 * compatibility with gcc/g++ on 32 bit machines. 89 */ 90struct _Unwind_Exception 91{ 92 uint64_t exception_class; 93 _Unwind_Exception_Cleanup_Fn exception_cleanup; 94 unsigned long private_1; 95 unsigned long private_2; 96}; 97 98/** Throw or rethrow an exception */ 99_Unwind_Reason_Code 100_Unwind_RaiseException(_Unwind_Exception *exception_object); 101 102/** Resume an exception other than by rethrowing it. */ 103void _Unwind_Resume(_Unwind_Exception *exception_object); 104 105/** Delete an exception object */ 106void _Unwind_DeleteException(_Unwind_Exception *exception_object); 107 108/** 109 * C++ exception ABI. 110 * The following declarations are from 111 * 112 * http://www.codesourcery.com/public/cxx-abi/abi-eh.html#cxx-abi 113 */ 114 115struct __cxa_exception { 116 std::type_info * exceptionType; 117 void (*exceptionDestructor)(void *); 118 std::unexpected_handler unexpectedHandler; 119 std::terminate_handler terminateHandler; 120 __cxa_exception * nextException; 121 122 int handlerCount; 123 int handlerSwitchValue; 124 const char * actionRecord; 125 const char * languageSpecificData; 126 void * catchTemp; 127 void * adjustedPtr; 128 129 _Unwind_Exception unwindHeader; 130}; 131 132static inline __cxa_exception *to_cxx(_Unwind_Exception *e) 133{ 134 return ((__cxa_exception *)(e+1)) - 1; 135} 136 137typedef struct __cxa_eh_globals { 138 __cxa_exception *caughtExceptions; 139 unsigned int uncaughtExceptions; 140} __cxa_eh_globals; 141 142__cxa_eh_globals*__cxa_get_globals(void) throw(); 143 144__CILKRTS_END_EXTERN_C 145 146#endif // ! defined(INCLUDED_EXCEPT_GCC_DOT_H) 147