1 /* libunwind - a platform-independent unwind library 2 Copyright 2011 Linaro Limited 3 4 This file is part of libunwind. 5 6 Permission is hereby granted, free of charge, to any person obtaining 7 a copy of this software and associated documentation files (the 8 "Software"), to deal in the Software without restriction, including 9 without limitation the rights to use, copy, modify, merge, publish, 10 distribute, sublicense, and/or sell copies of the Software, and to 11 permit persons to whom the Software is furnished to do so, subject to 12 the following conditions: 13 14 The above copyright notice and this permission notice shall be 15 included in all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 24 25 // Copyright (c) 2010 Google Inc. 26 // All rights reserved. 27 // 28 // Redistribution and use in source and binary forms, with or without 29 // modification, are permitted provided that the following conditions are 30 // met: 31 // 32 // * Redistributions of source code must retain the above copyright 33 // notice, this list of conditions and the following disclaimer. 34 // * Redistributions in binary form must reproduce the above 35 // copyright notice, this list of conditions and the following disclaimer 36 // in the documentation and/or other materials provided with the 37 // distribution. 38 // * Neither the name of Google Inc. nor the names of its 39 // contributors may be used to endorse or promote products derived from 40 // this software without specific prior written permission. 41 // 42 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 43 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 44 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 45 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 46 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 47 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 48 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 49 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 50 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 51 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 52 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 53 54 55 // Derived from libunwind, with extensive modifications. 56 57 #ifndef COMMON_ARM_EX_READER_H__ 58 #define COMMON_ARM_EX_READER_H__ 59 60 #include "common/arm_ex_to_module.h" 61 #include "common/memory_range.h" 62 63 namespace arm_ex_reader { 64 65 // This class is a reader for ARM unwind information 66 // from .ARM.exidx and .ARM.extab sections. 67 class ExceptionTableInfo { 68 public: ExceptionTableInfo(const char * exidx,size_t exidx_size,const char * extab,size_t extab_size,uint32_t text_last_svma,arm_ex_to_module::ARMExToModule * handler,const char * mapping_addr,uint32_t loading_addr)69 ExceptionTableInfo(const char* exidx, size_t exidx_size, 70 const char* extab, size_t extab_size, 71 uint32_t text_last_svma, 72 arm_ex_to_module::ARMExToModule* handler, 73 const char* mapping_addr, 74 uint32_t loading_addr) 75 : mr_exidx_(google_breakpad::MemoryRange(exidx, exidx_size)), 76 mr_extab_(google_breakpad::MemoryRange(extab, extab_size)), 77 text_last_svma_(text_last_svma), 78 handler_(handler), mapping_addr_(mapping_addr), 79 loading_addr_(loading_addr) { } 80 ~ExceptionTableInfo()81 ~ExceptionTableInfo() { } 82 83 // Parses the entries in .ARM.exidx and possibly 84 // in .ARM.extab tables, reports what we find to 85 // arm_ex_to_module::ARMExToModule. 86 void Start(); 87 88 private: 89 google_breakpad::MemoryRange mr_exidx_; 90 google_breakpad::MemoryRange mr_extab_; 91 uint32_t text_last_svma_; 92 arm_ex_to_module::ARMExToModule* handler_; 93 const char* mapping_addr_; 94 uint32_t loading_addr_; 95 96 enum ExExtractResult { 97 ExSuccess, // success 98 ExInBufOverflow, // out-of-range while reading .exidx 99 ExOutBufOverflow, // output buffer is too small 100 ExCantUnwind, // this function is marked CANT_UNWIND 101 ExCantRepresent, // entry valid, but we can't represent it 102 ExInvalid // entry is invalid 103 }; 104 ExExtractResult 105 ExtabEntryExtract(const struct arm_ex_to_module::exidx_entry* entry, 106 uint8_t* buf, size_t buf_size, 107 size_t* buf_used); 108 109 int ExtabEntryDecode(const uint8_t* buf, size_t buf_size); 110 }; 111 112 } // namespace arm_ex_reader 113 114 #endif // COMMON_ARM_EX_READER_H__ 115