1 // Copyright (C) 2012 The Android Open Source Project 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions 6 // are met: 7 // 1. Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // 2. Redistributions in binary form must reproduce the above copyright 10 // notice, this list of conditions and the following disclaimer in the 11 // documentation and/or other materials provided with the distribution. 12 // 3. Neither the name of the project nor the names of its contributors 13 // may be used to endorse or promote products derived from this software 14 // without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 // ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 // SUCH DAMAGE. 27 28 #ifndef __GXXABI_HELPER_FUNC_INTERNAL_H 29 #define __GXXABI_HELPER_FUNC_INTERNAL_H 30 31 #include <cxxabi.h> 32 #include <exception> 33 #include <unwind.h> 34 #include "dwarf_helper.h" 35 36 // Target-independent helper functions 37 namespace __cxxabiv1 { 38 39 void call_terminate(_Unwind_Exception* unwind_exception); 40 41 #if __arm__ 42 uint32_t decodeRelocTarget2 (uint32_t ptr); 43 #endif 44 45 // An exception spec acts like a catch handler, but in reverse. 46 // If any catchType in the list can catch an excpType, 47 // then this exception spec does not catch the excpType. 48 bool canExceptionSpecCatch(int64_t specIndex, 49 const uint8_t* classInfo, 50 uint8_t ttypeEncoding, 51 const std::type_info* excpType, 52 void* adjustedPtr, 53 _Unwind_Exception* unwind_exception); 54 55 void setRegisters(_Unwind_Exception* unwind_exception, 56 _Unwind_Context* context, 57 const ScanResultInternal& results); 58 59 _Unwind_Reason_Code continueUnwinding(_Unwind_Exception *ex, 60 _Unwind_Context *context); 61 62 void saveDataToBarrierCache(_Unwind_Exception* exc, 63 _Unwind_Context* ctx, 64 const ScanResultInternal& results); 65 66 void loadDataFromBarrierCache(_Unwind_Exception* exc, 67 ScanResultInternal& results); 68 69 void prepareBeginCleanup(_Unwind_Exception* exc); 70 71 void saveUnexpectedDataToBarrierCache(_Unwind_Exception* exc, 72 _Unwind_Context* ctx, 73 const ScanResultInternal& results); 74 75 void scanEHTable(ScanResultInternal& results, 76 _Unwind_Action actions, 77 bool native_exception, 78 _Unwind_Exception* unwind_exception, 79 _Unwind_Context* context); 80 81 // Make it easier to adapt to Itanium PR 82 #ifdef __arm__ 83 # define BEGIN_DEFINE_PERSONALITY_FUNC \ 84 __gxx_personality_v0(_Unwind_State state, \ 85 _Unwind_Exception* unwind_exception, \ 86 _Unwind_Context* context) { \ 87 int version = 1; \ 88 uint64_t exceptionClass = unwind_exception->exception_class; \ 89 _Unwind_Action actions = 0; \ 90 switch (state) { \ 91 default: { \ 92 return _URC_FAILURE; \ 93 } \ 94 case _US_VIRTUAL_UNWIND_FRAME: { \ 95 actions = _UA_SEARCH_PHASE; \ 96 break; \ 97 } \ 98 case _US_UNWIND_FRAME_STARTING: { \ 99 actions = _UA_CLEANUP_PHASE; \ 100 if (unwind_exception->barrier_cache.sp == _Unwind_GetGR(context, UNWIND_STACK_REG)) { \ 101 actions |= _UA_HANDLER_FRAME; \ 102 } \ 103 break; \ 104 } \ 105 case _US_UNWIND_FRAME_RESUME: { \ 106 return continueUnwinding(unwind_exception, context); \ 107 break; \ 108 } \ 109 } \ 110 _Unwind_SetGR (context, UNWIND_POINTER_REG, reinterpret_cast<uint32_t>(unwind_exception)); 111 #else // ! __arm__ 112 # define BEGIN_DEFINE_PERSONALITY_FUNC \ 113 __gxx_personality_v0(int version, _Unwind_Action actions, uint64_t exceptionClass, \ 114 _Unwind_Exception* unwind_exception, _Unwind_Context* context) { 115 #endif 116 117 // Print an error message to either stderr or the log. Then calls 118 // std::terminate(). Note: This always appends a newline to the message. 119 void fatalError(const char* message); 120 121 } // namespace __cxxabiv1 122 123 #endif // __GXXABI_HELPER_FUNC_INTERNAL_H 124