1 // -*- mode: C++ -*- 2 3 // Copyright 2013 Google LLC 4 // 5 // Redistribution and use in source and binary forms, with or without 6 // modification, are permitted provided that the following conditions are 7 // met: 8 // 9 // * Redistributions of source code must retain the above copyright 10 // notice, this list of conditions and the following disclaimer. 11 // * Redistributions in binary form must reproduce the above 12 // copyright notice, this list of conditions and the following disclaimer 13 // in the documentation and/or other materials provided with the 14 // distribution. 15 // * Neither the name of Google LLC nor the names of its 16 // contributors may be used to endorse or promote products derived from 17 // this software without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 // stackwalker_arm64.h: arm64-specific stackwalker. 32 // 33 // Provides stack frames given arm64 register context and a memory region 34 // corresponding to an arm64 stack. 35 // 36 // Author: Mark Mentovai, Ted Mielczarek, Colin Blundell 37 38 39 #ifndef PROCESSOR_STACKWALKER_ARM64_H__ 40 #define PROCESSOR_STACKWALKER_ARM64_H__ 41 42 #include "google_breakpad/common/breakpad_types.h" 43 #include "google_breakpad/common/minidump_format.h" 44 #include "google_breakpad/processor/stackwalker.h" 45 46 namespace google_breakpad { 47 48 class CodeModules; 49 50 class StackwalkerARM64 : public Stackwalker { 51 public: 52 // context is an arm64 context object that gives access to arm64-specific 53 // register state corresponding to the innermost called frame to be 54 // included in the stack. The other arguments are passed directly through 55 // to the base Stackwalker constructor. 56 StackwalkerARM64(const SystemInfo* system_info, 57 const MDRawContextARM64* context, 58 MemoryRegion* memory, 59 const CodeModules* modules, 60 StackFrameSymbolizer* frame_symbolizer); 61 62 // Change the context validity mask of the frame returned by 63 // GetContextFrame to VALID. This is only for use by unit tests; the 64 // default behavior is correct for all application code. SetContextFrameValidity(uint64_t valid)65 void SetContextFrameValidity(uint64_t valid) { 66 context_frame_validity_ = valid; 67 } 68 69 private: 70 // Strip pointer authentication codes from an address. 71 uint64_t PtrauthStrip(uint64_t ptr); 72 73 // Implementation of Stackwalker, using arm64 context and stack conventions. 74 virtual StackFrame* GetContextFrame(); 75 virtual StackFrame* GetCallerFrame(const CallStack* stack, 76 bool stack_scan_allowed); 77 78 // Use cfi_frame_info (derived from STACK CFI records) to construct 79 // the frame that called frames.back(). The caller takes ownership 80 // of the returned frame. Return NULL on failure. 81 StackFrameARM64* GetCallerByCFIFrameInfo(const vector<StackFrame*>& frames, 82 CFIFrameInfo* cfi_frame_info); 83 84 // Use the frame pointer. The caller takes ownership of the returned frame. 85 // Return NULL on failure. 86 StackFrameARM64* GetCallerByFramePointer(const vector<StackFrame*>& frames); 87 88 // Scan the stack for plausible return addresses. The caller takes ownership 89 // of the returned frame. Return NULL on failure. 90 StackFrameARM64* GetCallerByStackScan(const vector<StackFrame*>& frames); 91 92 // GetCallerByFramePointer() depends on the previous frame having recovered 93 // x30($LR) which may not have been done when using CFI. 94 // This function recovers $LR in the previous frame by using the frame-pointer 95 // two frames back to read it from the stack. 96 void CorrectRegLRByFramePointer(const vector<StackFrame*>& frames, 97 StackFrameARM64* last_frame); 98 99 // Stores the CPU context corresponding to the youngest stack frame, to 100 // be returned by GetContextFrame. 101 const MDRawContextARM64* context_; 102 103 // Validity mask for youngest stack frame. This is always 104 // CONTEXT_VALID_ALL in real use; it is only changeable for the sake of 105 // unit tests. 106 uint64_t context_frame_validity_; 107 108 // A mask of the valid address bits, determined from the address range of 109 // modules_. 110 uint64_t address_range_mask_; 111 }; 112 113 114 } // namespace google_breakpad 115 116 117 #endif // PROCESSOR_STACKWALKER_ARM64_H__ 118