Path: blob/main/contrib/llvm-project/libunwind/src/UnwindCursor.hpp
35154 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//7// C++ interface to lower levels of libunwind8//===----------------------------------------------------------------------===//910#ifndef __UNWINDCURSOR_HPP__11#define __UNWINDCURSOR_HPP__1213#include "cet_unwind.h"14#include <stdint.h>15#include <stdio.h>16#include <stdlib.h>17#include <unwind.h>1819#ifdef _WIN3220#include <windows.h>21#include <ntverp.h>22#endif23#ifdef __APPLE__24#include <mach-o/dyld.h>25#endif26#ifdef _AIX27#include <dlfcn.h>28#include <sys/debug.h>29#include <sys/pseg.h>30#endif3132#if defined(_LIBUNWIND_TARGET_LINUX) && \33(defined(_LIBUNWIND_TARGET_AARCH64) || defined(_LIBUNWIND_TARGET_RISCV) || \34defined(_LIBUNWIND_TARGET_S390X))35#include <errno.h>36#include <signal.h>37#include <sys/syscall.h>38#include <unistd.h>39#define _LIBUNWIND_CHECK_LINUX_SIGRETURN 140#endif4142#include "AddressSpace.hpp"43#include "CompactUnwinder.hpp"44#include "config.h"45#include "DwarfInstructions.hpp"46#include "EHHeaderParser.hpp"47#include "libunwind.h"48#include "libunwind_ext.h"49#include "Registers.hpp"50#include "RWMutex.hpp"51#include "Unwind-EHABI.h"5253#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)54// Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and55// earlier) SDKs.56// MinGW-w64 has always provided this struct.57#if defined(_WIN32) && defined(_LIBUNWIND_TARGET_X86_64) && \58!defined(__MINGW32__) && VER_PRODUCTBUILD < 800059struct _DISPATCHER_CONTEXT {60ULONG64 ControlPc;61ULONG64 ImageBase;62PRUNTIME_FUNCTION FunctionEntry;63ULONG64 EstablisherFrame;64ULONG64 TargetIp;65PCONTEXT ContextRecord;66PEXCEPTION_ROUTINE LanguageHandler;67PVOID HandlerData;68PUNWIND_HISTORY_TABLE HistoryTable;69ULONG ScopeIndex;70ULONG Fill0;71};72#endif7374struct UNWIND_INFO {75uint8_t Version : 3;76uint8_t Flags : 5;77uint8_t SizeOfProlog;78uint8_t CountOfCodes;79uint8_t FrameRegister : 4;80uint8_t FrameOffset : 4;81uint16_t UnwindCodes[2];82};8384extern "C" _Unwind_Reason_Code __libunwind_seh_personality(85int, _Unwind_Action, uint64_t, _Unwind_Exception *,86struct _Unwind_Context *);8788#endif8990namespace libunwind {9192#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)93/// Cache of recently found FDEs.94template <typename A>95class _LIBUNWIND_HIDDEN DwarfFDECache {96typedef typename A::pint_t pint_t;97public:98static constexpr pint_t kSearchAll = static_cast<pint_t>(-1);99static pint_t findFDE(pint_t mh, pint_t pc);100static void add(pint_t mh, pint_t ip_start, pint_t ip_end, pint_t fde);101static void removeAllIn(pint_t mh);102static void iterateCacheEntries(void (*func)(unw_word_t ip_start,103unw_word_t ip_end,104unw_word_t fde, unw_word_t mh));105106private:107108struct entry {109pint_t mh;110pint_t ip_start;111pint_t ip_end;112pint_t fde;113};114115// These fields are all static to avoid needing an initializer.116// There is only one instance of this class per process.117static RWMutex _lock;118#ifdef __APPLE__119static void dyldUnloadHook(const struct mach_header *mh, intptr_t slide);120static bool _registeredForDyldUnloads;121#endif122static entry *_buffer;123static entry *_bufferUsed;124static entry *_bufferEnd;125static entry _initialBuffer[64];126};127128template <typename A>129typename DwarfFDECache<A>::entry *130DwarfFDECache<A>::_buffer = _initialBuffer;131132template <typename A>133typename DwarfFDECache<A>::entry *134DwarfFDECache<A>::_bufferUsed = _initialBuffer;135136template <typename A>137typename DwarfFDECache<A>::entry *138DwarfFDECache<A>::_bufferEnd = &_initialBuffer[64];139140template <typename A>141typename DwarfFDECache<A>::entry DwarfFDECache<A>::_initialBuffer[64];142143template <typename A>144RWMutex DwarfFDECache<A>::_lock;145146#ifdef __APPLE__147template <typename A>148bool DwarfFDECache<A>::_registeredForDyldUnloads = false;149#endif150151template <typename A>152typename A::pint_t DwarfFDECache<A>::findFDE(pint_t mh, pint_t pc) {153pint_t result = 0;154_LIBUNWIND_LOG_IF_FALSE(_lock.lock_shared());155for (entry *p = _buffer; p < _bufferUsed; ++p) {156if ((mh == p->mh) || (mh == kSearchAll)) {157if ((p->ip_start <= pc) && (pc < p->ip_end)) {158result = p->fde;159break;160}161}162}163_LIBUNWIND_LOG_IF_FALSE(_lock.unlock_shared());164return result;165}166167template <typename A>168void DwarfFDECache<A>::add(pint_t mh, pint_t ip_start, pint_t ip_end,169pint_t fde) {170#if !defined(_LIBUNWIND_NO_HEAP)171_LIBUNWIND_LOG_IF_FALSE(_lock.lock());172if (_bufferUsed >= _bufferEnd) {173size_t oldSize = (size_t)(_bufferEnd - _buffer);174size_t newSize = oldSize * 4;175// Can't use operator new (we are below it).176entry *newBuffer = (entry *)malloc(newSize * sizeof(entry));177memcpy(newBuffer, _buffer, oldSize * sizeof(entry));178if (_buffer != _initialBuffer)179free(_buffer);180_buffer = newBuffer;181_bufferUsed = &newBuffer[oldSize];182_bufferEnd = &newBuffer[newSize];183}184_bufferUsed->mh = mh;185_bufferUsed->ip_start = ip_start;186_bufferUsed->ip_end = ip_end;187_bufferUsed->fde = fde;188++_bufferUsed;189#ifdef __APPLE__190if (!_registeredForDyldUnloads) {191_dyld_register_func_for_remove_image(&dyldUnloadHook);192_registeredForDyldUnloads = true;193}194#endif195_LIBUNWIND_LOG_IF_FALSE(_lock.unlock());196#endif197}198199template <typename A>200void DwarfFDECache<A>::removeAllIn(pint_t mh) {201_LIBUNWIND_LOG_IF_FALSE(_lock.lock());202entry *d = _buffer;203for (const entry *s = _buffer; s < _bufferUsed; ++s) {204if (s->mh != mh) {205if (d != s)206*d = *s;207++d;208}209}210_bufferUsed = d;211_LIBUNWIND_LOG_IF_FALSE(_lock.unlock());212}213214#ifdef __APPLE__215template <typename A>216void DwarfFDECache<A>::dyldUnloadHook(const struct mach_header *mh, intptr_t ) {217removeAllIn((pint_t) mh);218}219#endif220221template <typename A>222void DwarfFDECache<A>::iterateCacheEntries(void (*func)(223unw_word_t ip_start, unw_word_t ip_end, unw_word_t fde, unw_word_t mh)) {224_LIBUNWIND_LOG_IF_FALSE(_lock.lock());225for (entry *p = _buffer; p < _bufferUsed; ++p) {226(*func)(p->ip_start, p->ip_end, p->fde, p->mh);227}228_LIBUNWIND_LOG_IF_FALSE(_lock.unlock());229}230#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)231232233#define arrayoffsetof(type, index, field) ((size_t)(&((type *)0)[index].field))234235#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)236template <typename A> class UnwindSectionHeader {237public:238UnwindSectionHeader(A &addressSpace, typename A::pint_t addr)239: _addressSpace(addressSpace), _addr(addr) {}240241uint32_t version() const {242return _addressSpace.get32(_addr +243offsetof(unwind_info_section_header, version));244}245uint32_t commonEncodingsArraySectionOffset() const {246return _addressSpace.get32(_addr +247offsetof(unwind_info_section_header,248commonEncodingsArraySectionOffset));249}250uint32_t commonEncodingsArrayCount() const {251return _addressSpace.get32(_addr + offsetof(unwind_info_section_header,252commonEncodingsArrayCount));253}254uint32_t personalityArraySectionOffset() const {255return _addressSpace.get32(_addr + offsetof(unwind_info_section_header,256personalityArraySectionOffset));257}258uint32_t personalityArrayCount() const {259return _addressSpace.get32(260_addr + offsetof(unwind_info_section_header, personalityArrayCount));261}262uint32_t indexSectionOffset() const {263return _addressSpace.get32(264_addr + offsetof(unwind_info_section_header, indexSectionOffset));265}266uint32_t indexCount() const {267return _addressSpace.get32(268_addr + offsetof(unwind_info_section_header, indexCount));269}270271private:272A &_addressSpace;273typename A::pint_t _addr;274};275276template <typename A> class UnwindSectionIndexArray {277public:278UnwindSectionIndexArray(A &addressSpace, typename A::pint_t addr)279: _addressSpace(addressSpace), _addr(addr) {}280281uint32_t functionOffset(uint32_t index) const {282return _addressSpace.get32(283_addr + arrayoffsetof(unwind_info_section_header_index_entry, index,284functionOffset));285}286uint32_t secondLevelPagesSectionOffset(uint32_t index) const {287return _addressSpace.get32(288_addr + arrayoffsetof(unwind_info_section_header_index_entry, index,289secondLevelPagesSectionOffset));290}291uint32_t lsdaIndexArraySectionOffset(uint32_t index) const {292return _addressSpace.get32(293_addr + arrayoffsetof(unwind_info_section_header_index_entry, index,294lsdaIndexArraySectionOffset));295}296297private:298A &_addressSpace;299typename A::pint_t _addr;300};301302template <typename A> class UnwindSectionRegularPageHeader {303public:304UnwindSectionRegularPageHeader(A &addressSpace, typename A::pint_t addr)305: _addressSpace(addressSpace), _addr(addr) {}306307uint32_t kind() const {308return _addressSpace.get32(309_addr + offsetof(unwind_info_regular_second_level_page_header, kind));310}311uint16_t entryPageOffset() const {312return _addressSpace.get16(313_addr + offsetof(unwind_info_regular_second_level_page_header,314entryPageOffset));315}316uint16_t entryCount() const {317return _addressSpace.get16(318_addr +319offsetof(unwind_info_regular_second_level_page_header, entryCount));320}321322private:323A &_addressSpace;324typename A::pint_t _addr;325};326327template <typename A> class UnwindSectionRegularArray {328public:329UnwindSectionRegularArray(A &addressSpace, typename A::pint_t addr)330: _addressSpace(addressSpace), _addr(addr) {}331332uint32_t functionOffset(uint32_t index) const {333return _addressSpace.get32(334_addr + arrayoffsetof(unwind_info_regular_second_level_entry, index,335functionOffset));336}337uint32_t encoding(uint32_t index) const {338return _addressSpace.get32(339_addr +340arrayoffsetof(unwind_info_regular_second_level_entry, index, encoding));341}342343private:344A &_addressSpace;345typename A::pint_t _addr;346};347348template <typename A> class UnwindSectionCompressedPageHeader {349public:350UnwindSectionCompressedPageHeader(A &addressSpace, typename A::pint_t addr)351: _addressSpace(addressSpace), _addr(addr) {}352353uint32_t kind() const {354return _addressSpace.get32(355_addr +356offsetof(unwind_info_compressed_second_level_page_header, kind));357}358uint16_t entryPageOffset() const {359return _addressSpace.get16(360_addr + offsetof(unwind_info_compressed_second_level_page_header,361entryPageOffset));362}363uint16_t entryCount() const {364return _addressSpace.get16(365_addr +366offsetof(unwind_info_compressed_second_level_page_header, entryCount));367}368uint16_t encodingsPageOffset() const {369return _addressSpace.get16(370_addr + offsetof(unwind_info_compressed_second_level_page_header,371encodingsPageOffset));372}373uint16_t encodingsCount() const {374return _addressSpace.get16(375_addr + offsetof(unwind_info_compressed_second_level_page_header,376encodingsCount));377}378379private:380A &_addressSpace;381typename A::pint_t _addr;382};383384template <typename A> class UnwindSectionCompressedArray {385public:386UnwindSectionCompressedArray(A &addressSpace, typename A::pint_t addr)387: _addressSpace(addressSpace), _addr(addr) {}388389uint32_t functionOffset(uint32_t index) const {390return UNWIND_INFO_COMPRESSED_ENTRY_FUNC_OFFSET(391_addressSpace.get32(_addr + index * sizeof(uint32_t)));392}393uint16_t encodingIndex(uint32_t index) const {394return UNWIND_INFO_COMPRESSED_ENTRY_ENCODING_INDEX(395_addressSpace.get32(_addr + index * sizeof(uint32_t)));396}397398private:399A &_addressSpace;400typename A::pint_t _addr;401};402403template <typename A> class UnwindSectionLsdaArray {404public:405UnwindSectionLsdaArray(A &addressSpace, typename A::pint_t addr)406: _addressSpace(addressSpace), _addr(addr) {}407408uint32_t functionOffset(uint32_t index) const {409return _addressSpace.get32(410_addr + arrayoffsetof(unwind_info_section_header_lsda_index_entry,411index, functionOffset));412}413uint32_t lsdaOffset(uint32_t index) const {414return _addressSpace.get32(415_addr + arrayoffsetof(unwind_info_section_header_lsda_index_entry,416index, lsdaOffset));417}418419private:420A &_addressSpace;421typename A::pint_t _addr;422};423#endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)424425class _LIBUNWIND_HIDDEN AbstractUnwindCursor {426public:427// NOTE: provide a class specific placement deallocation function (S5.3.4 p20)428// This avoids an unnecessary dependency to libc++abi.429void operator delete(void *, size_t) {}430431virtual ~AbstractUnwindCursor() {}432virtual bool validReg(int) { _LIBUNWIND_ABORT("validReg not implemented"); }433virtual unw_word_t getReg(int) { _LIBUNWIND_ABORT("getReg not implemented"); }434virtual void setReg(int, unw_word_t) {435_LIBUNWIND_ABORT("setReg not implemented");436}437virtual bool validFloatReg(int) {438_LIBUNWIND_ABORT("validFloatReg not implemented");439}440virtual unw_fpreg_t getFloatReg(int) {441_LIBUNWIND_ABORT("getFloatReg not implemented");442}443virtual void setFloatReg(int, unw_fpreg_t) {444_LIBUNWIND_ABORT("setFloatReg not implemented");445}446virtual int step(bool = false) { _LIBUNWIND_ABORT("step not implemented"); }447virtual void getInfo(unw_proc_info_t *) {448_LIBUNWIND_ABORT("getInfo not implemented");449}450virtual void jumpto() { _LIBUNWIND_ABORT("jumpto not implemented"); }451virtual bool isSignalFrame() {452_LIBUNWIND_ABORT("isSignalFrame not implemented");453}454virtual bool getFunctionName(char *, size_t, unw_word_t *) {455_LIBUNWIND_ABORT("getFunctionName not implemented");456}457virtual void setInfoBasedOnIPRegister(bool = false) {458_LIBUNWIND_ABORT("setInfoBasedOnIPRegister not implemented");459}460virtual const char *getRegisterName(int) {461_LIBUNWIND_ABORT("getRegisterName not implemented");462}463#ifdef __arm__464virtual void saveVFPAsX() { _LIBUNWIND_ABORT("saveVFPAsX not implemented"); }465#endif466467#ifdef _AIX468virtual uintptr_t getDataRelBase() {469_LIBUNWIND_ABORT("getDataRelBase not implemented");470}471#endif472473#if defined(_LIBUNWIND_USE_CET) || defined(_LIBUNWIND_USE_GCS)474virtual void *get_registers() {475_LIBUNWIND_ABORT("get_registers not implemented");476}477#endif478};479480#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)481482/// \c UnwindCursor contains all state (including all register values) during483/// an unwind. This is normally stack-allocated inside a unw_cursor_t.484template <typename A, typename R>485class UnwindCursor : public AbstractUnwindCursor {486typedef typename A::pint_t pint_t;487public:488UnwindCursor(unw_context_t *context, A &as);489UnwindCursor(CONTEXT *context, A &as);490UnwindCursor(A &as, void *threadArg);491virtual ~UnwindCursor() {}492virtual bool validReg(int);493virtual unw_word_t getReg(int);494virtual void setReg(int, unw_word_t);495virtual bool validFloatReg(int);496virtual unw_fpreg_t getFloatReg(int);497virtual void setFloatReg(int, unw_fpreg_t);498virtual int step(bool = false);499virtual void getInfo(unw_proc_info_t *);500virtual void jumpto();501virtual bool isSignalFrame();502virtual bool getFunctionName(char *buf, size_t len, unw_word_t *off);503virtual void setInfoBasedOnIPRegister(bool isReturnAddress = false);504virtual const char *getRegisterName(int num);505#ifdef __arm__506virtual void saveVFPAsX();507#endif508509DISPATCHER_CONTEXT *getDispatcherContext() { return &_dispContext; }510void setDispatcherContext(DISPATCHER_CONTEXT *disp) {511_dispContext = *disp;512_info.lsda = reinterpret_cast<unw_word_t>(_dispContext.HandlerData);513if (_dispContext.LanguageHandler) {514_info.handler = reinterpret_cast<unw_word_t>(__libunwind_seh_personality);515} else516_info.handler = 0;517}518519// libunwind does not and should not depend on C++ library which means that we520// need our own definition of inline placement new.521static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }522523private:524525pint_t getLastPC() const { return _dispContext.ControlPc; }526void setLastPC(pint_t pc) { _dispContext.ControlPc = pc; }527RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) {528#ifdef __arm__529// Remove the thumb bit; FunctionEntry ranges don't include the thumb bit.530pc &= ~1U;531#endif532// If pc points exactly at the end of the range, we might resolve the533// next function instead. Decrement pc by 1 to fit inside the current534// function.535pc -= 1;536_dispContext.FunctionEntry = RtlLookupFunctionEntry(pc,537&_dispContext.ImageBase,538_dispContext.HistoryTable);539*base = _dispContext.ImageBase;540return _dispContext.FunctionEntry;541}542bool getInfoFromSEH(pint_t pc);543int stepWithSEHData() {544_dispContext.LanguageHandler = RtlVirtualUnwind(UNW_FLAG_UHANDLER,545_dispContext.ImageBase,546_dispContext.ControlPc,547_dispContext.FunctionEntry,548_dispContext.ContextRecord,549&_dispContext.HandlerData,550&_dispContext.EstablisherFrame,551NULL);552// Update some fields of the unwind info now, since we have them.553_info.lsda = reinterpret_cast<unw_word_t>(_dispContext.HandlerData);554if (_dispContext.LanguageHandler) {555_info.handler = reinterpret_cast<unw_word_t>(__libunwind_seh_personality);556} else557_info.handler = 0;558return UNW_STEP_SUCCESS;559}560561A &_addressSpace;562unw_proc_info_t _info;563DISPATCHER_CONTEXT _dispContext;564CONTEXT _msContext;565UNWIND_HISTORY_TABLE _histTable;566bool _unwindInfoMissing;567};568569570template <typename A, typename R>571UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)572: _addressSpace(as), _unwindInfoMissing(false) {573static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),574"UnwindCursor<> does not fit in unw_cursor_t");575static_assert((alignof(UnwindCursor<A, R>) <= alignof(unw_cursor_t)),576"UnwindCursor<> requires more alignment than unw_cursor_t");577memset(&_info, 0, sizeof(_info));578memset(&_histTable, 0, sizeof(_histTable));579memset(&_dispContext, 0, sizeof(_dispContext));580_dispContext.ContextRecord = &_msContext;581_dispContext.HistoryTable = &_histTable;582// Initialize MS context from ours.583R r(context);584RtlCaptureContext(&_msContext);585_msContext.ContextFlags = CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_FLOATING_POINT;586#if defined(_LIBUNWIND_TARGET_X86_64)587_msContext.Rax = r.getRegister(UNW_X86_64_RAX);588_msContext.Rcx = r.getRegister(UNW_X86_64_RCX);589_msContext.Rdx = r.getRegister(UNW_X86_64_RDX);590_msContext.Rbx = r.getRegister(UNW_X86_64_RBX);591_msContext.Rsp = r.getRegister(UNW_X86_64_RSP);592_msContext.Rbp = r.getRegister(UNW_X86_64_RBP);593_msContext.Rsi = r.getRegister(UNW_X86_64_RSI);594_msContext.Rdi = r.getRegister(UNW_X86_64_RDI);595_msContext.R8 = r.getRegister(UNW_X86_64_R8);596_msContext.R9 = r.getRegister(UNW_X86_64_R9);597_msContext.R10 = r.getRegister(UNW_X86_64_R10);598_msContext.R11 = r.getRegister(UNW_X86_64_R11);599_msContext.R12 = r.getRegister(UNW_X86_64_R12);600_msContext.R13 = r.getRegister(UNW_X86_64_R13);601_msContext.R14 = r.getRegister(UNW_X86_64_R14);602_msContext.R15 = r.getRegister(UNW_X86_64_R15);603_msContext.Rip = r.getRegister(UNW_REG_IP);604union {605v128 v;606M128A m;607} t;608t.v = r.getVectorRegister(UNW_X86_64_XMM0);609_msContext.Xmm0 = t.m;610t.v = r.getVectorRegister(UNW_X86_64_XMM1);611_msContext.Xmm1 = t.m;612t.v = r.getVectorRegister(UNW_X86_64_XMM2);613_msContext.Xmm2 = t.m;614t.v = r.getVectorRegister(UNW_X86_64_XMM3);615_msContext.Xmm3 = t.m;616t.v = r.getVectorRegister(UNW_X86_64_XMM4);617_msContext.Xmm4 = t.m;618t.v = r.getVectorRegister(UNW_X86_64_XMM5);619_msContext.Xmm5 = t.m;620t.v = r.getVectorRegister(UNW_X86_64_XMM6);621_msContext.Xmm6 = t.m;622t.v = r.getVectorRegister(UNW_X86_64_XMM7);623_msContext.Xmm7 = t.m;624t.v = r.getVectorRegister(UNW_X86_64_XMM8);625_msContext.Xmm8 = t.m;626t.v = r.getVectorRegister(UNW_X86_64_XMM9);627_msContext.Xmm9 = t.m;628t.v = r.getVectorRegister(UNW_X86_64_XMM10);629_msContext.Xmm10 = t.m;630t.v = r.getVectorRegister(UNW_X86_64_XMM11);631_msContext.Xmm11 = t.m;632t.v = r.getVectorRegister(UNW_X86_64_XMM12);633_msContext.Xmm12 = t.m;634t.v = r.getVectorRegister(UNW_X86_64_XMM13);635_msContext.Xmm13 = t.m;636t.v = r.getVectorRegister(UNW_X86_64_XMM14);637_msContext.Xmm14 = t.m;638t.v = r.getVectorRegister(UNW_X86_64_XMM15);639_msContext.Xmm15 = t.m;640#elif defined(_LIBUNWIND_TARGET_ARM)641_msContext.R0 = r.getRegister(UNW_ARM_R0);642_msContext.R1 = r.getRegister(UNW_ARM_R1);643_msContext.R2 = r.getRegister(UNW_ARM_R2);644_msContext.R3 = r.getRegister(UNW_ARM_R3);645_msContext.R4 = r.getRegister(UNW_ARM_R4);646_msContext.R5 = r.getRegister(UNW_ARM_R5);647_msContext.R6 = r.getRegister(UNW_ARM_R6);648_msContext.R7 = r.getRegister(UNW_ARM_R7);649_msContext.R8 = r.getRegister(UNW_ARM_R8);650_msContext.R9 = r.getRegister(UNW_ARM_R9);651_msContext.R10 = r.getRegister(UNW_ARM_R10);652_msContext.R11 = r.getRegister(UNW_ARM_R11);653_msContext.R12 = r.getRegister(UNW_ARM_R12);654_msContext.Sp = r.getRegister(UNW_ARM_SP);655_msContext.Lr = r.getRegister(UNW_ARM_LR);656_msContext.Pc = r.getRegister(UNW_ARM_IP);657for (int i = UNW_ARM_D0; i <= UNW_ARM_D31; ++i) {658union {659uint64_t w;660double d;661} d;662d.d = r.getFloatRegister(i);663_msContext.D[i - UNW_ARM_D0] = d.w;664}665#elif defined(_LIBUNWIND_TARGET_AARCH64)666for (int i = UNW_AARCH64_X0; i <= UNW_ARM64_X30; ++i)667_msContext.X[i - UNW_AARCH64_X0] = r.getRegister(i);668_msContext.Sp = r.getRegister(UNW_REG_SP);669_msContext.Pc = r.getRegister(UNW_REG_IP);670for (int i = UNW_AARCH64_V0; i <= UNW_ARM64_D31; ++i)671_msContext.V[i - UNW_AARCH64_V0].D[0] = r.getFloatRegister(i);672#endif673}674675template <typename A, typename R>676UnwindCursor<A, R>::UnwindCursor(CONTEXT *context, A &as)677: _addressSpace(as), _unwindInfoMissing(false) {678static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),679"UnwindCursor<> does not fit in unw_cursor_t");680memset(&_info, 0, sizeof(_info));681memset(&_histTable, 0, sizeof(_histTable));682memset(&_dispContext, 0, sizeof(_dispContext));683_dispContext.ContextRecord = &_msContext;684_dispContext.HistoryTable = &_histTable;685_msContext = *context;686}687688689template <typename A, typename R>690bool UnwindCursor<A, R>::validReg(int regNum) {691if (regNum == UNW_REG_IP || regNum == UNW_REG_SP) return true;692#if defined(_LIBUNWIND_TARGET_X86_64)693if (regNum >= UNW_X86_64_RAX && regNum <= UNW_X86_64_RIP) return true;694#elif defined(_LIBUNWIND_TARGET_ARM)695if ((regNum >= UNW_ARM_R0 && regNum <= UNW_ARM_R15) ||696regNum == UNW_ARM_RA_AUTH_CODE)697return true;698#elif defined(_LIBUNWIND_TARGET_AARCH64)699if (regNum >= UNW_AARCH64_X0 && regNum <= UNW_ARM64_X30) return true;700#endif701return false;702}703704template <typename A, typename R>705unw_word_t UnwindCursor<A, R>::getReg(int regNum) {706switch (regNum) {707#if defined(_LIBUNWIND_TARGET_X86_64)708case UNW_X86_64_RIP:709case UNW_REG_IP: return _msContext.Rip;710case UNW_X86_64_RAX: return _msContext.Rax;711case UNW_X86_64_RDX: return _msContext.Rdx;712case UNW_X86_64_RCX: return _msContext.Rcx;713case UNW_X86_64_RBX: return _msContext.Rbx;714case UNW_REG_SP:715case UNW_X86_64_RSP: return _msContext.Rsp;716case UNW_X86_64_RBP: return _msContext.Rbp;717case UNW_X86_64_RSI: return _msContext.Rsi;718case UNW_X86_64_RDI: return _msContext.Rdi;719case UNW_X86_64_R8: return _msContext.R8;720case UNW_X86_64_R9: return _msContext.R9;721case UNW_X86_64_R10: return _msContext.R10;722case UNW_X86_64_R11: return _msContext.R11;723case UNW_X86_64_R12: return _msContext.R12;724case UNW_X86_64_R13: return _msContext.R13;725case UNW_X86_64_R14: return _msContext.R14;726case UNW_X86_64_R15: return _msContext.R15;727#elif defined(_LIBUNWIND_TARGET_ARM)728case UNW_ARM_R0: return _msContext.R0;729case UNW_ARM_R1: return _msContext.R1;730case UNW_ARM_R2: return _msContext.R2;731case UNW_ARM_R3: return _msContext.R3;732case UNW_ARM_R4: return _msContext.R4;733case UNW_ARM_R5: return _msContext.R5;734case UNW_ARM_R6: return _msContext.R6;735case UNW_ARM_R7: return _msContext.R7;736case UNW_ARM_R8: return _msContext.R8;737case UNW_ARM_R9: return _msContext.R9;738case UNW_ARM_R10: return _msContext.R10;739case UNW_ARM_R11: return _msContext.R11;740case UNW_ARM_R12: return _msContext.R12;741case UNW_REG_SP:742case UNW_ARM_SP: return _msContext.Sp;743case UNW_ARM_LR: return _msContext.Lr;744case UNW_REG_IP:745case UNW_ARM_IP: return _msContext.Pc;746#elif defined(_LIBUNWIND_TARGET_AARCH64)747case UNW_REG_SP: return _msContext.Sp;748case UNW_REG_IP: return _msContext.Pc;749default: return _msContext.X[regNum - UNW_AARCH64_X0];750#endif751}752_LIBUNWIND_ABORT("unsupported register");753}754755template <typename A, typename R>756void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {757switch (regNum) {758#if defined(_LIBUNWIND_TARGET_X86_64)759case UNW_X86_64_RIP:760case UNW_REG_IP: _msContext.Rip = value; break;761case UNW_X86_64_RAX: _msContext.Rax = value; break;762case UNW_X86_64_RDX: _msContext.Rdx = value; break;763case UNW_X86_64_RCX: _msContext.Rcx = value; break;764case UNW_X86_64_RBX: _msContext.Rbx = value; break;765case UNW_REG_SP:766case UNW_X86_64_RSP: _msContext.Rsp = value; break;767case UNW_X86_64_RBP: _msContext.Rbp = value; break;768case UNW_X86_64_RSI: _msContext.Rsi = value; break;769case UNW_X86_64_RDI: _msContext.Rdi = value; break;770case UNW_X86_64_R8: _msContext.R8 = value; break;771case UNW_X86_64_R9: _msContext.R9 = value; break;772case UNW_X86_64_R10: _msContext.R10 = value; break;773case UNW_X86_64_R11: _msContext.R11 = value; break;774case UNW_X86_64_R12: _msContext.R12 = value; break;775case UNW_X86_64_R13: _msContext.R13 = value; break;776case UNW_X86_64_R14: _msContext.R14 = value; break;777case UNW_X86_64_R15: _msContext.R15 = value; break;778#elif defined(_LIBUNWIND_TARGET_ARM)779case UNW_ARM_R0: _msContext.R0 = value; break;780case UNW_ARM_R1: _msContext.R1 = value; break;781case UNW_ARM_R2: _msContext.R2 = value; break;782case UNW_ARM_R3: _msContext.R3 = value; break;783case UNW_ARM_R4: _msContext.R4 = value; break;784case UNW_ARM_R5: _msContext.R5 = value; break;785case UNW_ARM_R6: _msContext.R6 = value; break;786case UNW_ARM_R7: _msContext.R7 = value; break;787case UNW_ARM_R8: _msContext.R8 = value; break;788case UNW_ARM_R9: _msContext.R9 = value; break;789case UNW_ARM_R10: _msContext.R10 = value; break;790case UNW_ARM_R11: _msContext.R11 = value; break;791case UNW_ARM_R12: _msContext.R12 = value; break;792case UNW_REG_SP:793case UNW_ARM_SP: _msContext.Sp = value; break;794case UNW_ARM_LR: _msContext.Lr = value; break;795case UNW_REG_IP:796case UNW_ARM_IP: _msContext.Pc = value; break;797#elif defined(_LIBUNWIND_TARGET_AARCH64)798case UNW_REG_SP: _msContext.Sp = value; break;799case UNW_REG_IP: _msContext.Pc = value; break;800case UNW_AARCH64_X0:801case UNW_AARCH64_X1:802case UNW_AARCH64_X2:803case UNW_AARCH64_X3:804case UNW_AARCH64_X4:805case UNW_AARCH64_X5:806case UNW_AARCH64_X6:807case UNW_AARCH64_X7:808case UNW_AARCH64_X8:809case UNW_AARCH64_X9:810case UNW_AARCH64_X10:811case UNW_AARCH64_X11:812case UNW_AARCH64_X12:813case UNW_AARCH64_X13:814case UNW_AARCH64_X14:815case UNW_AARCH64_X15:816case UNW_AARCH64_X16:817case UNW_AARCH64_X17:818case UNW_AARCH64_X18:819case UNW_AARCH64_X19:820case UNW_AARCH64_X20:821case UNW_AARCH64_X21:822case UNW_AARCH64_X22:823case UNW_AARCH64_X23:824case UNW_AARCH64_X24:825case UNW_AARCH64_X25:826case UNW_AARCH64_X26:827case UNW_AARCH64_X27:828case UNW_AARCH64_X28:829case UNW_AARCH64_FP:830case UNW_AARCH64_LR: _msContext.X[regNum - UNW_ARM64_X0] = value; break;831#endif832default:833_LIBUNWIND_ABORT("unsupported register");834}835}836837template <typename A, typename R>838bool UnwindCursor<A, R>::validFloatReg(int regNum) {839#if defined(_LIBUNWIND_TARGET_ARM)840if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) return true;841if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) return true;842#elif defined(_LIBUNWIND_TARGET_AARCH64)843if (regNum >= UNW_AARCH64_V0 && regNum <= UNW_ARM64_D31) return true;844#else845(void)regNum;846#endif847return false;848}849850template <typename A, typename R>851unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {852#if defined(_LIBUNWIND_TARGET_ARM)853if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) {854union {855uint32_t w;856float f;857} d;858d.w = _msContext.S[regNum - UNW_ARM_S0];859return d.f;860}861if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) {862union {863uint64_t w;864double d;865} d;866d.w = _msContext.D[regNum - UNW_ARM_D0];867return d.d;868}869_LIBUNWIND_ABORT("unsupported float register");870#elif defined(_LIBUNWIND_TARGET_AARCH64)871return _msContext.V[regNum - UNW_AARCH64_V0].D[0];872#else873(void)regNum;874_LIBUNWIND_ABORT("float registers unimplemented");875#endif876}877878template <typename A, typename R>879void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {880#if defined(_LIBUNWIND_TARGET_ARM)881if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) {882union {883uint32_t w;884float f;885} d;886d.f = (float)value;887_msContext.S[regNum - UNW_ARM_S0] = d.w;888}889if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) {890union {891uint64_t w;892double d;893} d;894d.d = value;895_msContext.D[regNum - UNW_ARM_D0] = d.w;896}897_LIBUNWIND_ABORT("unsupported float register");898#elif defined(_LIBUNWIND_TARGET_AARCH64)899_msContext.V[regNum - UNW_AARCH64_V0].D[0] = value;900#else901(void)regNum;902(void)value;903_LIBUNWIND_ABORT("float registers unimplemented");904#endif905}906907template <typename A, typename R> void UnwindCursor<A, R>::jumpto() {908RtlRestoreContext(&_msContext, nullptr);909}910911#ifdef __arm__912template <typename A, typename R> void UnwindCursor<A, R>::saveVFPAsX() {}913#endif914915template <typename A, typename R>916const char *UnwindCursor<A, R>::getRegisterName(int regNum) {917return R::getRegisterName(regNum);918}919920template <typename A, typename R> bool UnwindCursor<A, R>::isSignalFrame() {921return false;922}923924#else // !defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) || !defined(_WIN32)925926/// UnwindCursor contains all state (including all register values) during927/// an unwind. This is normally stack allocated inside a unw_cursor_t.928template <typename A, typename R>929class UnwindCursor : public AbstractUnwindCursor{930typedef typename A::pint_t pint_t;931public:932UnwindCursor(unw_context_t *context, A &as);933UnwindCursor(A &as, void *threadArg);934virtual ~UnwindCursor() {}935virtual bool validReg(int);936virtual unw_word_t getReg(int);937virtual void setReg(int, unw_word_t);938virtual bool validFloatReg(int);939virtual unw_fpreg_t getFloatReg(int);940virtual void setFloatReg(int, unw_fpreg_t);941virtual int step(bool stage2 = false);942virtual void getInfo(unw_proc_info_t *);943virtual void jumpto();944virtual bool isSignalFrame();945virtual bool getFunctionName(char *buf, size_t len, unw_word_t *off);946virtual void setInfoBasedOnIPRegister(bool isReturnAddress = false);947virtual const char *getRegisterName(int num);948#ifdef __arm__949virtual void saveVFPAsX();950#endif951952#ifdef _AIX953virtual uintptr_t getDataRelBase();954#endif955956#if defined(_LIBUNWIND_USE_CET) || defined(_LIBUNWIND_USE_GCS)957virtual void *get_registers() { return &_registers; }958#endif959960// libunwind does not and should not depend on C++ library which means that we961// need our own definition of inline placement new.962static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }963964private:965966#if defined(_LIBUNWIND_ARM_EHABI)967bool getInfoFromEHABISection(pint_t pc, const UnwindInfoSections §s);968969int stepWithEHABI() {970size_t len = 0;971size_t off = 0;972// FIXME: Calling decode_eht_entry() here is violating the libunwind973// abstraction layer.974const uint32_t *ehtp =975decode_eht_entry(reinterpret_cast<const uint32_t *>(_info.unwind_info),976&off, &len);977if (_Unwind_VRS_Interpret((_Unwind_Context *)this, ehtp, off, len) !=978_URC_CONTINUE_UNWIND)979return UNW_STEP_END;980return UNW_STEP_SUCCESS;981}982#endif983984#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)985bool setInfoForSigReturn() {986R dummy;987return setInfoForSigReturn(dummy);988}989int stepThroughSigReturn() {990R dummy;991return stepThroughSigReturn(dummy);992}993bool isReadableAddr(const pint_t addr) const;994#if defined(_LIBUNWIND_TARGET_AARCH64)995bool setInfoForSigReturn(Registers_arm64 &);996int stepThroughSigReturn(Registers_arm64 &);997#endif998#if defined(_LIBUNWIND_TARGET_RISCV)999bool setInfoForSigReturn(Registers_riscv &);1000int stepThroughSigReturn(Registers_riscv &);1001#endif1002#if defined(_LIBUNWIND_TARGET_S390X)1003bool setInfoForSigReturn(Registers_s390x &);1004int stepThroughSigReturn(Registers_s390x &);1005#endif1006template <typename Registers> bool setInfoForSigReturn(Registers &) {1007return false;1008}1009template <typename Registers> int stepThroughSigReturn(Registers &) {1010return UNW_STEP_END;1011}1012#endif10131014#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)1015bool getInfoFromFdeCie(const typename CFI_Parser<A>::FDE_Info &fdeInfo,1016const typename CFI_Parser<A>::CIE_Info &cieInfo,1017pint_t pc, uintptr_t dso_base);1018bool getInfoFromDwarfSection(pint_t pc, const UnwindInfoSections §s,1019uint32_t fdeSectionOffsetHint=0);1020int stepWithDwarfFDE(bool stage2) {1021return DwarfInstructions<A, R>::stepWithDwarf(1022_addressSpace, (pint_t)this->getReg(UNW_REG_IP),1023(pint_t)_info.unwind_info, _registers, _isSignalFrame, stage2);1024}1025#endif10261027#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)1028bool getInfoFromCompactEncodingSection(pint_t pc,1029const UnwindInfoSections §s);1030int stepWithCompactEncoding(bool stage2 = false) {1031#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)1032if ( compactSaysUseDwarf() )1033return stepWithDwarfFDE(stage2);1034#endif1035R dummy;1036return stepWithCompactEncoding(dummy);1037}10381039#if defined(_LIBUNWIND_TARGET_X86_64)1040int stepWithCompactEncoding(Registers_x86_64 &) {1041return CompactUnwinder_x86_64<A>::stepWithCompactEncoding(1042_info.format, _info.start_ip, _addressSpace, _registers);1043}1044#endif10451046#if defined(_LIBUNWIND_TARGET_I386)1047int stepWithCompactEncoding(Registers_x86 &) {1048return CompactUnwinder_x86<A>::stepWithCompactEncoding(1049_info.format, (uint32_t)_info.start_ip, _addressSpace, _registers);1050}1051#endif10521053#if defined(_LIBUNWIND_TARGET_PPC)1054int stepWithCompactEncoding(Registers_ppc &) {1055return UNW_EINVAL;1056}1057#endif10581059#if defined(_LIBUNWIND_TARGET_PPC64)1060int stepWithCompactEncoding(Registers_ppc64 &) {1061return UNW_EINVAL;1062}1063#endif106410651066#if defined(_LIBUNWIND_TARGET_AARCH64)1067int stepWithCompactEncoding(Registers_arm64 &) {1068return CompactUnwinder_arm64<A>::stepWithCompactEncoding(1069_info.format, _info.start_ip, _addressSpace, _registers);1070}1071#endif10721073#if defined(_LIBUNWIND_TARGET_MIPS_O32)1074int stepWithCompactEncoding(Registers_mips_o32 &) {1075return UNW_EINVAL;1076}1077#endif10781079#if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)1080int stepWithCompactEncoding(Registers_mips_newabi &) {1081return UNW_EINVAL;1082}1083#endif10841085#if defined(_LIBUNWIND_TARGET_LOONGARCH)1086int stepWithCompactEncoding(Registers_loongarch &) { return UNW_EINVAL; }1087#endif10881089#if defined(_LIBUNWIND_TARGET_SPARC)1090int stepWithCompactEncoding(Registers_sparc &) { return UNW_EINVAL; }1091#endif10921093#if defined(_LIBUNWIND_TARGET_SPARC64)1094int stepWithCompactEncoding(Registers_sparc64 &) { return UNW_EINVAL; }1095#endif10961097#if defined (_LIBUNWIND_TARGET_RISCV)1098int stepWithCompactEncoding(Registers_riscv &) {1099return UNW_EINVAL;1100}1101#endif11021103bool compactSaysUseDwarf(uint32_t *offset=NULL) const {1104R dummy;1105return compactSaysUseDwarf(dummy, offset);1106}11071108#if defined(_LIBUNWIND_TARGET_X86_64)1109bool compactSaysUseDwarf(Registers_x86_64 &, uint32_t *offset) const {1110if ((_info.format & UNWIND_X86_64_MODE_MASK) == UNWIND_X86_64_MODE_DWARF) {1111if (offset)1112*offset = (_info.format & UNWIND_X86_64_DWARF_SECTION_OFFSET);1113return true;1114}1115return false;1116}1117#endif11181119#if defined(_LIBUNWIND_TARGET_I386)1120bool compactSaysUseDwarf(Registers_x86 &, uint32_t *offset) const {1121if ((_info.format & UNWIND_X86_MODE_MASK) == UNWIND_X86_MODE_DWARF) {1122if (offset)1123*offset = (_info.format & UNWIND_X86_DWARF_SECTION_OFFSET);1124return true;1125}1126return false;1127}1128#endif11291130#if defined(_LIBUNWIND_TARGET_PPC)1131bool compactSaysUseDwarf(Registers_ppc &, uint32_t *) const {1132return true;1133}1134#endif11351136#if defined(_LIBUNWIND_TARGET_PPC64)1137bool compactSaysUseDwarf(Registers_ppc64 &, uint32_t *) const {1138return true;1139}1140#endif11411142#if defined(_LIBUNWIND_TARGET_AARCH64)1143bool compactSaysUseDwarf(Registers_arm64 &, uint32_t *offset) const {1144if ((_info.format & UNWIND_ARM64_MODE_MASK) == UNWIND_ARM64_MODE_DWARF) {1145if (offset)1146*offset = (_info.format & UNWIND_ARM64_DWARF_SECTION_OFFSET);1147return true;1148}1149return false;1150}1151#endif11521153#if defined(_LIBUNWIND_TARGET_MIPS_O32)1154bool compactSaysUseDwarf(Registers_mips_o32 &, uint32_t *) const {1155return true;1156}1157#endif11581159#if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)1160bool compactSaysUseDwarf(Registers_mips_newabi &, uint32_t *) const {1161return true;1162}1163#endif11641165#if defined(_LIBUNWIND_TARGET_LOONGARCH)1166bool compactSaysUseDwarf(Registers_loongarch &, uint32_t *) const {1167return true;1168}1169#endif11701171#if defined(_LIBUNWIND_TARGET_SPARC)1172bool compactSaysUseDwarf(Registers_sparc &, uint32_t *) const { return true; }1173#endif11741175#if defined(_LIBUNWIND_TARGET_SPARC64)1176bool compactSaysUseDwarf(Registers_sparc64 &, uint32_t *) const {1177return true;1178}1179#endif11801181#if defined (_LIBUNWIND_TARGET_RISCV)1182bool compactSaysUseDwarf(Registers_riscv &, uint32_t *) const {1183return true;1184}1185#endif11861187#endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)11881189#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)1190compact_unwind_encoding_t dwarfEncoding() const {1191R dummy;1192return dwarfEncoding(dummy);1193}11941195#if defined(_LIBUNWIND_TARGET_X86_64)1196compact_unwind_encoding_t dwarfEncoding(Registers_x86_64 &) const {1197return UNWIND_X86_64_MODE_DWARF;1198}1199#endif12001201#if defined(_LIBUNWIND_TARGET_I386)1202compact_unwind_encoding_t dwarfEncoding(Registers_x86 &) const {1203return UNWIND_X86_MODE_DWARF;1204}1205#endif12061207#if defined(_LIBUNWIND_TARGET_PPC)1208compact_unwind_encoding_t dwarfEncoding(Registers_ppc &) const {1209return 0;1210}1211#endif12121213#if defined(_LIBUNWIND_TARGET_PPC64)1214compact_unwind_encoding_t dwarfEncoding(Registers_ppc64 &) const {1215return 0;1216}1217#endif12181219#if defined(_LIBUNWIND_TARGET_AARCH64)1220compact_unwind_encoding_t dwarfEncoding(Registers_arm64 &) const {1221return UNWIND_ARM64_MODE_DWARF;1222}1223#endif12241225#if defined(_LIBUNWIND_TARGET_ARM)1226compact_unwind_encoding_t dwarfEncoding(Registers_arm &) const {1227return 0;1228}1229#endif12301231#if defined (_LIBUNWIND_TARGET_OR1K)1232compact_unwind_encoding_t dwarfEncoding(Registers_or1k &) const {1233return 0;1234}1235#endif12361237#if defined (_LIBUNWIND_TARGET_HEXAGON)1238compact_unwind_encoding_t dwarfEncoding(Registers_hexagon &) const {1239return 0;1240}1241#endif12421243#if defined (_LIBUNWIND_TARGET_MIPS_O32)1244compact_unwind_encoding_t dwarfEncoding(Registers_mips_o32 &) const {1245return 0;1246}1247#endif12481249#if defined (_LIBUNWIND_TARGET_MIPS_NEWABI)1250compact_unwind_encoding_t dwarfEncoding(Registers_mips_newabi &) const {1251return 0;1252}1253#endif12541255#if defined(_LIBUNWIND_TARGET_LOONGARCH)1256compact_unwind_encoding_t dwarfEncoding(Registers_loongarch &) const {1257return 0;1258}1259#endif12601261#if defined(_LIBUNWIND_TARGET_SPARC)1262compact_unwind_encoding_t dwarfEncoding(Registers_sparc &) const { return 0; }1263#endif12641265#if defined(_LIBUNWIND_TARGET_SPARC64)1266compact_unwind_encoding_t dwarfEncoding(Registers_sparc64 &) const {1267return 0;1268}1269#endif12701271#if defined (_LIBUNWIND_TARGET_RISCV)1272compact_unwind_encoding_t dwarfEncoding(Registers_riscv &) const {1273return 0;1274}1275#endif12761277#if defined (_LIBUNWIND_TARGET_S390X)1278compact_unwind_encoding_t dwarfEncoding(Registers_s390x &) const {1279return 0;1280}1281#endif12821283#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)12841285#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)1286// For runtime environments using SEH unwind data without Windows runtime1287// support.1288pint_t getLastPC() const { /* FIXME: Implement */ return 0; }1289void setLastPC(pint_t pc) { /* FIXME: Implement */ }1290RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) {1291/* FIXME: Implement */1292*base = 0;1293return nullptr;1294}1295bool getInfoFromSEH(pint_t pc);1296int stepWithSEHData() { /* FIXME: Implement */ return 0; }1297#endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)12981299#if defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)1300bool getInfoFromTBTable(pint_t pc, R ®isters);1301int stepWithTBTable(pint_t pc, tbtable *TBTable, R ®isters,1302bool &isSignalFrame);1303int stepWithTBTableData() {1304return stepWithTBTable(reinterpret_cast<pint_t>(this->getReg(UNW_REG_IP)),1305reinterpret_cast<tbtable *>(_info.unwind_info),1306_registers, _isSignalFrame);1307}1308#endif // defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)13091310A &_addressSpace;1311R _registers;1312unw_proc_info_t _info;1313bool _unwindInfoMissing;1314bool _isSignalFrame;1315#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)1316bool _isSigReturn = false;1317#endif1318};131913201321template <typename A, typename R>1322UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)1323: _addressSpace(as), _registers(context), _unwindInfoMissing(false),1324_isSignalFrame(false) {1325static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),1326"UnwindCursor<> does not fit in unw_cursor_t");1327static_assert((alignof(UnwindCursor<A, R>) <= alignof(unw_cursor_t)),1328"UnwindCursor<> requires more alignment than unw_cursor_t");1329memset(&_info, 0, sizeof(_info));1330}13311332template <typename A, typename R>1333UnwindCursor<A, R>::UnwindCursor(A &as, void *)1334: _addressSpace(as), _unwindInfoMissing(false), _isSignalFrame(false) {1335memset(&_info, 0, sizeof(_info));1336// FIXME1337// fill in _registers from thread arg1338}133913401341template <typename A, typename R>1342bool UnwindCursor<A, R>::validReg(int regNum) {1343return _registers.validRegister(regNum);1344}13451346template <typename A, typename R>1347unw_word_t UnwindCursor<A, R>::getReg(int regNum) {1348return _registers.getRegister(regNum);1349}13501351template <typename A, typename R>1352void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {1353_registers.setRegister(regNum, (typename A::pint_t)value);1354}13551356template <typename A, typename R>1357bool UnwindCursor<A, R>::validFloatReg(int regNum) {1358return _registers.validFloatRegister(regNum);1359}13601361template <typename A, typename R>1362unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {1363return _registers.getFloatRegister(regNum);1364}13651366template <typename A, typename R>1367void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {1368_registers.setFloatRegister(regNum, value);1369}13701371template <typename A, typename R> void UnwindCursor<A, R>::jumpto() {1372_registers.jumpto();1373}13741375#ifdef __arm__1376template <typename A, typename R> void UnwindCursor<A, R>::saveVFPAsX() {1377_registers.saveVFPAsX();1378}1379#endif13801381#ifdef _AIX1382template <typename A, typename R>1383uintptr_t UnwindCursor<A, R>::getDataRelBase() {1384return reinterpret_cast<uintptr_t>(_info.extra);1385}1386#endif13871388template <typename A, typename R>1389const char *UnwindCursor<A, R>::getRegisterName(int regNum) {1390return _registers.getRegisterName(regNum);1391}13921393template <typename A, typename R> bool UnwindCursor<A, R>::isSignalFrame() {1394return _isSignalFrame;1395}13961397#endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)13981399#if defined(_LIBUNWIND_ARM_EHABI)1400template<typename A>1401struct EHABISectionIterator {1402typedef EHABISectionIterator _Self;14031404typedef typename A::pint_t value_type;1405typedef typename A::pint_t* pointer;1406typedef typename A::pint_t& reference;1407typedef size_t size_type;1408typedef size_t difference_type;14091410static _Self begin(A& addressSpace, const UnwindInfoSections& sects) {1411return _Self(addressSpace, sects, 0);1412}1413static _Self end(A& addressSpace, const UnwindInfoSections& sects) {1414return _Self(addressSpace, sects,1415sects.arm_section_length / sizeof(EHABIIndexEntry));1416}14171418EHABISectionIterator(A& addressSpace, const UnwindInfoSections& sects, size_t i)1419: _i(i), _addressSpace(&addressSpace), _sects(§s) {}14201421_Self& operator++() { ++_i; return *this; }1422_Self& operator+=(size_t a) { _i += a; return *this; }1423_Self& operator--() { assert(_i > 0); --_i; return *this; }1424_Self& operator-=(size_t a) { assert(_i >= a); _i -= a; return *this; }14251426_Self operator+(size_t a) { _Self out = *this; out._i += a; return out; }1427_Self operator-(size_t a) { assert(_i >= a); _Self out = *this; out._i -= a; return out; }14281429size_t operator-(const _Self& other) const { return _i - other._i; }14301431bool operator==(const _Self& other) const {1432assert(_addressSpace == other._addressSpace);1433assert(_sects == other._sects);1434return _i == other._i;1435}14361437bool operator!=(const _Self& other) const {1438assert(_addressSpace == other._addressSpace);1439assert(_sects == other._sects);1440return _i != other._i;1441}14421443typename A::pint_t operator*() const { return functionAddress(); }14441445typename A::pint_t functionAddress() const {1446typename A::pint_t indexAddr = _sects->arm_section + arrayoffsetof(1447EHABIIndexEntry, _i, functionOffset);1448return indexAddr + signExtendPrel31(_addressSpace->get32(indexAddr));1449}14501451typename A::pint_t dataAddress() {1452typename A::pint_t indexAddr = _sects->arm_section + arrayoffsetof(1453EHABIIndexEntry, _i, data);1454return indexAddr;1455}14561457private:1458size_t _i;1459A* _addressSpace;1460const UnwindInfoSections* _sects;1461};14621463namespace {14641465template <typename A>1466EHABISectionIterator<A> EHABISectionUpperBound(1467EHABISectionIterator<A> first,1468EHABISectionIterator<A> last,1469typename A::pint_t value) {1470size_t len = last - first;1471while (len > 0) {1472size_t l2 = len / 2;1473EHABISectionIterator<A> m = first + l2;1474if (value < *m) {1475len = l2;1476} else {1477first = ++m;1478len -= l2 + 1;1479}1480}1481return first;1482}14831484}14851486template <typename A, typename R>1487bool UnwindCursor<A, R>::getInfoFromEHABISection(1488pint_t pc,1489const UnwindInfoSections §s) {1490EHABISectionIterator<A> begin =1491EHABISectionIterator<A>::begin(_addressSpace, sects);1492EHABISectionIterator<A> end =1493EHABISectionIterator<A>::end(_addressSpace, sects);1494if (begin == end)1495return false;14961497EHABISectionIterator<A> itNextPC = EHABISectionUpperBound(begin, end, pc);1498if (itNextPC == begin)1499return false;1500EHABISectionIterator<A> itThisPC = itNextPC - 1;15011502pint_t thisPC = itThisPC.functionAddress();1503// If an exception is thrown from a function, corresponding to the last entry1504// in the table, we don't really know the function extent and have to choose a1505// value for nextPC. Choosing max() will allow the range check during trace to1506// succeed.1507pint_t nextPC = (itNextPC == end) ? UINTPTR_MAX : itNextPC.functionAddress();1508pint_t indexDataAddr = itThisPC.dataAddress();15091510if (indexDataAddr == 0)1511return false;15121513uint32_t indexData = _addressSpace.get32(indexDataAddr);1514if (indexData == UNW_EXIDX_CANTUNWIND)1515return false;15161517// If the high bit is set, the exception handling table entry is inline inside1518// the index table entry on the second word (aka |indexDataAddr|). Otherwise,1519// the table points at an offset in the exception handling table (section 51520// EHABI).1521pint_t exceptionTableAddr;1522uint32_t exceptionTableData;1523bool isSingleWordEHT;1524if (indexData & 0x80000000) {1525exceptionTableAddr = indexDataAddr;1526// TODO(ajwong): Should this data be 0?1527exceptionTableData = indexData;1528isSingleWordEHT = true;1529} else {1530exceptionTableAddr = indexDataAddr + signExtendPrel31(indexData);1531exceptionTableData = _addressSpace.get32(exceptionTableAddr);1532isSingleWordEHT = false;1533}15341535// Now we know the 3 things:1536// exceptionTableAddr -- exception handler table entry.1537// exceptionTableData -- the data inside the first word of the eht entry.1538// isSingleWordEHT -- whether the entry is in the index.1539unw_word_t personalityRoutine = 0xbadf00d;1540bool scope32 = false;1541uintptr_t lsda;15421543// If the high bit in the exception handling table entry is set, the entry is1544// in compact form (section 6.3 EHABI).1545if (exceptionTableData & 0x80000000) {1546// Grab the index of the personality routine from the compact form.1547uint32_t choice = (exceptionTableData & 0x0f000000) >> 24;1548uint32_t extraWords = 0;1549switch (choice) {1550case 0:1551personalityRoutine = (unw_word_t) &__aeabi_unwind_cpp_pr0;1552extraWords = 0;1553scope32 = false;1554lsda = isSingleWordEHT ? 0 : (exceptionTableAddr + 4);1555break;1556case 1:1557personalityRoutine = (unw_word_t) &__aeabi_unwind_cpp_pr1;1558extraWords = (exceptionTableData & 0x00ff0000) >> 16;1559scope32 = false;1560lsda = exceptionTableAddr + (extraWords + 1) * 4;1561break;1562case 2:1563personalityRoutine = (unw_word_t) &__aeabi_unwind_cpp_pr2;1564extraWords = (exceptionTableData & 0x00ff0000) >> 16;1565scope32 = true;1566lsda = exceptionTableAddr + (extraWords + 1) * 4;1567break;1568default:1569_LIBUNWIND_ABORT("unknown personality routine");1570return false;1571}15721573if (isSingleWordEHT) {1574if (extraWords != 0) {1575_LIBUNWIND_ABORT("index inlined table detected but pr function "1576"requires extra words");1577return false;1578}1579}1580} else {1581pint_t personalityAddr =1582exceptionTableAddr + signExtendPrel31(exceptionTableData);1583personalityRoutine = personalityAddr;15841585// ARM EHABI # 6.2, # 9.21586//1587// +---- ehtp1588// v1589// +--------------------------------------+1590// | +--------+--------+--------+-------+ |1591// | |0| prel31 to personalityRoutine | |1592// | +--------+--------+--------+-------+ |1593// | | N | unwind opcodes | | <-- UnwindData1594// | +--------+--------+--------+-------+ |1595// | | Word 2 unwind opcodes | |1596// | +--------+--------+--------+-------+ |1597// | ... |1598// | +--------+--------+--------+-------+ |1599// | | Word N unwind opcodes | |1600// | +--------+--------+--------+-------+ |1601// | | LSDA | | <-- lsda1602// | | ... | |1603// | +--------+--------+--------+-------+ |1604// +--------------------------------------+16051606uint32_t *UnwindData = reinterpret_cast<uint32_t*>(exceptionTableAddr) + 1;1607uint32_t FirstDataWord = *UnwindData;1608size_t N = ((FirstDataWord >> 24) & 0xff);1609size_t NDataWords = N + 1;1610lsda = reinterpret_cast<uintptr_t>(UnwindData + NDataWords);1611}16121613_info.start_ip = thisPC;1614_info.end_ip = nextPC;1615_info.handler = personalityRoutine;1616_info.unwind_info = exceptionTableAddr;1617_info.lsda = lsda;1618// flags is pr_cache.additional. See EHABI #7.2 for definition of bit 0.1619_info.flags = (isSingleWordEHT ? 1 : 0) | (scope32 ? 0x2 : 0); // Use enum?16201621return true;1622}1623#endif16241625#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)1626template <typename A, typename R>1627bool UnwindCursor<A, R>::getInfoFromFdeCie(1628const typename CFI_Parser<A>::FDE_Info &fdeInfo,1629const typename CFI_Parser<A>::CIE_Info &cieInfo, pint_t pc,1630uintptr_t dso_base) {1631typename CFI_Parser<A>::PrologInfo prolog;1632if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo, pc,1633R::getArch(), &prolog)) {1634// Save off parsed FDE info1635_info.start_ip = fdeInfo.pcStart;1636_info.end_ip = fdeInfo.pcEnd;1637_info.lsda = fdeInfo.lsda;1638_info.handler = cieInfo.personality;1639// Some frameless functions need SP altered when resuming in function, so1640// propagate spExtraArgSize.1641_info.gp = prolog.spExtraArgSize;1642_info.flags = 0;1643_info.format = dwarfEncoding();1644_info.unwind_info = fdeInfo.fdeStart;1645_info.unwind_info_size = static_cast<uint32_t>(fdeInfo.fdeLength);1646_info.extra = static_cast<unw_word_t>(dso_base);1647return true;1648}1649return false;1650}16511652template <typename A, typename R>1653bool UnwindCursor<A, R>::getInfoFromDwarfSection(pint_t pc,1654const UnwindInfoSections §s,1655uint32_t fdeSectionOffsetHint) {1656typename CFI_Parser<A>::FDE_Info fdeInfo;1657typename CFI_Parser<A>::CIE_Info cieInfo;1658bool foundFDE = false;1659bool foundInCache = false;1660// If compact encoding table gave offset into dwarf section, go directly there1661if (fdeSectionOffsetHint != 0) {1662foundFDE = CFI_Parser<A>::findFDE(_addressSpace, pc, sects.dwarf_section,1663sects.dwarf_section_length,1664sects.dwarf_section + fdeSectionOffsetHint,1665&fdeInfo, &cieInfo);1666}1667#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)1668if (!foundFDE && (sects.dwarf_index_section != 0)) {1669foundFDE = EHHeaderParser<A>::findFDE(1670_addressSpace, pc, sects.dwarf_index_section,1671(uint32_t)sects.dwarf_index_section_length, &fdeInfo, &cieInfo);1672}1673#endif1674if (!foundFDE) {1675// otherwise, search cache of previously found FDEs.1676pint_t cachedFDE = DwarfFDECache<A>::findFDE(sects.dso_base, pc);1677if (cachedFDE != 0) {1678foundFDE =1679CFI_Parser<A>::findFDE(_addressSpace, pc, sects.dwarf_section,1680sects.dwarf_section_length,1681cachedFDE, &fdeInfo, &cieInfo);1682foundInCache = foundFDE;1683}1684}1685if (!foundFDE) {1686// Still not found, do full scan of __eh_frame section.1687foundFDE = CFI_Parser<A>::findFDE(_addressSpace, pc, sects.dwarf_section,1688sects.dwarf_section_length, 0,1689&fdeInfo, &cieInfo);1690}1691if (foundFDE) {1692if (getInfoFromFdeCie(fdeInfo, cieInfo, pc, sects.dso_base)) {1693// Add to cache (to make next lookup faster) if we had no hint1694// and there was no index.1695if (!foundInCache && (fdeSectionOffsetHint == 0)) {1696#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)1697if (sects.dwarf_index_section == 0)1698#endif1699DwarfFDECache<A>::add(sects.dso_base, fdeInfo.pcStart, fdeInfo.pcEnd,1700fdeInfo.fdeStart);1701}1702return true;1703}1704}1705//_LIBUNWIND_DEBUG_LOG("can't find/use FDE for pc=0x%llX", (uint64_t)pc);1706return false;1707}1708#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)170917101711#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)1712template <typename A, typename R>1713bool UnwindCursor<A, R>::getInfoFromCompactEncodingSection(pint_t pc,1714const UnwindInfoSections §s) {1715const bool log = false;1716if (log)1717fprintf(stderr, "getInfoFromCompactEncodingSection(pc=0x%llX, mh=0x%llX)\n",1718(uint64_t)pc, (uint64_t)sects.dso_base);17191720const UnwindSectionHeader<A> sectionHeader(_addressSpace,1721sects.compact_unwind_section);1722if (sectionHeader.version() != UNWIND_SECTION_VERSION)1723return false;17241725// do a binary search of top level index to find page with unwind info1726pint_t targetFunctionOffset = pc - sects.dso_base;1727const UnwindSectionIndexArray<A> topIndex(_addressSpace,1728sects.compact_unwind_section1729+ sectionHeader.indexSectionOffset());1730uint32_t low = 0;1731uint32_t high = sectionHeader.indexCount();1732uint32_t last = high - 1;1733while (low < high) {1734uint32_t mid = (low + high) / 2;1735//if ( log ) fprintf(stderr, "\tmid=%d, low=%d, high=%d, *mid=0x%08X\n",1736//mid, low, high, topIndex.functionOffset(mid));1737if (topIndex.functionOffset(mid) <= targetFunctionOffset) {1738if ((mid == last) ||1739(topIndex.functionOffset(mid + 1) > targetFunctionOffset)) {1740low = mid;1741break;1742} else {1743low = mid + 1;1744}1745} else {1746high = mid;1747}1748}1749const uint32_t firstLevelFunctionOffset = topIndex.functionOffset(low);1750const uint32_t firstLevelNextPageFunctionOffset =1751topIndex.functionOffset(low + 1);1752const pint_t secondLevelAddr =1753sects.compact_unwind_section + topIndex.secondLevelPagesSectionOffset(low);1754const pint_t lsdaArrayStartAddr =1755sects.compact_unwind_section + topIndex.lsdaIndexArraySectionOffset(low);1756const pint_t lsdaArrayEndAddr =1757sects.compact_unwind_section + topIndex.lsdaIndexArraySectionOffset(low+1);1758if (log)1759fprintf(stderr, "\tfirst level search for result index=%d "1760"to secondLevelAddr=0x%llX\n",1761low, (uint64_t) secondLevelAddr);1762// do a binary search of second level page index1763uint32_t encoding = 0;1764pint_t funcStart = 0;1765pint_t funcEnd = 0;1766pint_t lsda = 0;1767pint_t personality = 0;1768uint32_t pageKind = _addressSpace.get32(secondLevelAddr);1769if (pageKind == UNWIND_SECOND_LEVEL_REGULAR) {1770// regular page1771UnwindSectionRegularPageHeader<A> pageHeader(_addressSpace,1772secondLevelAddr);1773UnwindSectionRegularArray<A> pageIndex(1774_addressSpace, secondLevelAddr + pageHeader.entryPageOffset());1775// binary search looks for entry with e where index[e].offset <= pc <1776// index[e+1].offset1777if (log)1778fprintf(stderr, "\tbinary search for targetFunctionOffset=0x%08llX in "1779"regular page starting at secondLevelAddr=0x%llX\n",1780(uint64_t) targetFunctionOffset, (uint64_t) secondLevelAddr);1781low = 0;1782high = pageHeader.entryCount();1783while (low < high) {1784uint32_t mid = (low + high) / 2;1785if (pageIndex.functionOffset(mid) <= targetFunctionOffset) {1786if (mid == (uint32_t)(pageHeader.entryCount() - 1)) {1787// at end of table1788low = mid;1789funcEnd = firstLevelNextPageFunctionOffset + sects.dso_base;1790break;1791} else if (pageIndex.functionOffset(mid + 1) > targetFunctionOffset) {1792// next is too big, so we found it1793low = mid;1794funcEnd = pageIndex.functionOffset(low + 1) + sects.dso_base;1795break;1796} else {1797low = mid + 1;1798}1799} else {1800high = mid;1801}1802}1803encoding = pageIndex.encoding(low);1804funcStart = pageIndex.functionOffset(low) + sects.dso_base;1805if (pc < funcStart) {1806if (log)1807fprintf(1808stderr,1809"\tpc not in table, pc=0x%llX, funcStart=0x%llX, funcEnd=0x%llX\n",1810(uint64_t) pc, (uint64_t) funcStart, (uint64_t) funcEnd);1811return false;1812}1813if (pc > funcEnd) {1814if (log)1815fprintf(1816stderr,1817"\tpc not in table, pc=0x%llX, funcStart=0x%llX, funcEnd=0x%llX\n",1818(uint64_t) pc, (uint64_t) funcStart, (uint64_t) funcEnd);1819return false;1820}1821} else if (pageKind == UNWIND_SECOND_LEVEL_COMPRESSED) {1822// compressed page1823UnwindSectionCompressedPageHeader<A> pageHeader(_addressSpace,1824secondLevelAddr);1825UnwindSectionCompressedArray<A> pageIndex(1826_addressSpace, secondLevelAddr + pageHeader.entryPageOffset());1827const uint32_t targetFunctionPageOffset =1828(uint32_t)(targetFunctionOffset - firstLevelFunctionOffset);1829// binary search looks for entry with e where index[e].offset <= pc <1830// index[e+1].offset1831if (log)1832fprintf(stderr, "\tbinary search of compressed page starting at "1833"secondLevelAddr=0x%llX\n",1834(uint64_t) secondLevelAddr);1835low = 0;1836last = pageHeader.entryCount() - 1;1837high = pageHeader.entryCount();1838while (low < high) {1839uint32_t mid = (low + high) / 2;1840if (pageIndex.functionOffset(mid) <= targetFunctionPageOffset) {1841if ((mid == last) ||1842(pageIndex.functionOffset(mid + 1) > targetFunctionPageOffset)) {1843low = mid;1844break;1845} else {1846low = mid + 1;1847}1848} else {1849high = mid;1850}1851}1852funcStart = pageIndex.functionOffset(low) + firstLevelFunctionOffset1853+ sects.dso_base;1854if (low < last)1855funcEnd =1856pageIndex.functionOffset(low + 1) + firstLevelFunctionOffset1857+ sects.dso_base;1858else1859funcEnd = firstLevelNextPageFunctionOffset + sects.dso_base;1860if (pc < funcStart) {1861_LIBUNWIND_DEBUG_LOG("malformed __unwind_info, pc=0x%llX "1862"not in second level compressed unwind table. "1863"funcStart=0x%llX",1864(uint64_t) pc, (uint64_t) funcStart);1865return false;1866}1867if (pc > funcEnd) {1868_LIBUNWIND_DEBUG_LOG("malformed __unwind_info, pc=0x%llX "1869"not in second level compressed unwind table. "1870"funcEnd=0x%llX",1871(uint64_t) pc, (uint64_t) funcEnd);1872return false;1873}1874uint16_t encodingIndex = pageIndex.encodingIndex(low);1875if (encodingIndex < sectionHeader.commonEncodingsArrayCount()) {1876// encoding is in common table in section header1877encoding = _addressSpace.get32(1878sects.compact_unwind_section +1879sectionHeader.commonEncodingsArraySectionOffset() +1880encodingIndex * sizeof(uint32_t));1881} else {1882// encoding is in page specific table1883uint16_t pageEncodingIndex =1884encodingIndex - (uint16_t)sectionHeader.commonEncodingsArrayCount();1885encoding = _addressSpace.get32(secondLevelAddr +1886pageHeader.encodingsPageOffset() +1887pageEncodingIndex * sizeof(uint32_t));1888}1889} else {1890_LIBUNWIND_DEBUG_LOG(1891"malformed __unwind_info at 0x%0llX bad second level page",1892(uint64_t)sects.compact_unwind_section);1893return false;1894}18951896// look up LSDA, if encoding says function has one1897if (encoding & UNWIND_HAS_LSDA) {1898UnwindSectionLsdaArray<A> lsdaIndex(_addressSpace, lsdaArrayStartAddr);1899uint32_t funcStartOffset = (uint32_t)(funcStart - sects.dso_base);1900low = 0;1901high = (uint32_t)(lsdaArrayEndAddr - lsdaArrayStartAddr) /1902sizeof(unwind_info_section_header_lsda_index_entry);1903// binary search looks for entry with exact match for functionOffset1904if (log)1905fprintf(stderr,1906"\tbinary search of lsda table for targetFunctionOffset=0x%08X\n",1907funcStartOffset);1908while (low < high) {1909uint32_t mid = (low + high) / 2;1910if (lsdaIndex.functionOffset(mid) == funcStartOffset) {1911lsda = lsdaIndex.lsdaOffset(mid) + sects.dso_base;1912break;1913} else if (lsdaIndex.functionOffset(mid) < funcStartOffset) {1914low = mid + 1;1915} else {1916high = mid;1917}1918}1919if (lsda == 0) {1920_LIBUNWIND_DEBUG_LOG("found encoding 0x%08X with HAS_LSDA bit set for "1921"pc=0x%0llX, but lsda table has no entry",1922encoding, (uint64_t) pc);1923return false;1924}1925}19261927// extract personality routine, if encoding says function has one1928uint32_t personalityIndex = (encoding & UNWIND_PERSONALITY_MASK) >>1929(__builtin_ctz(UNWIND_PERSONALITY_MASK));1930if (personalityIndex != 0) {1931--personalityIndex; // change 1-based to zero-based index1932if (personalityIndex >= sectionHeader.personalityArrayCount()) {1933_LIBUNWIND_DEBUG_LOG("found encoding 0x%08X with personality index %d, "1934"but personality table has only %d entries",1935encoding, personalityIndex,1936sectionHeader.personalityArrayCount());1937return false;1938}1939int32_t personalityDelta = (int32_t)_addressSpace.get32(1940sects.compact_unwind_section +1941sectionHeader.personalityArraySectionOffset() +1942personalityIndex * sizeof(uint32_t));1943pint_t personalityPointer = sects.dso_base + (pint_t)personalityDelta;1944personality = _addressSpace.getP(personalityPointer);1945if (log)1946fprintf(stderr, "getInfoFromCompactEncodingSection(pc=0x%llX), "1947"personalityDelta=0x%08X, personality=0x%08llX\n",1948(uint64_t) pc, personalityDelta, (uint64_t) personality);1949}19501951if (log)1952fprintf(stderr, "getInfoFromCompactEncodingSection(pc=0x%llX), "1953"encoding=0x%08X, lsda=0x%08llX for funcStart=0x%llX\n",1954(uint64_t) pc, encoding, (uint64_t) lsda, (uint64_t) funcStart);1955_info.start_ip = funcStart;1956_info.end_ip = funcEnd;1957_info.lsda = lsda;1958_info.handler = personality;1959_info.gp = 0;1960_info.flags = 0;1961_info.format = encoding;1962_info.unwind_info = 0;1963_info.unwind_info_size = 0;1964_info.extra = sects.dso_base;1965return true;1966}1967#endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)196819691970#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)1971template <typename A, typename R>1972bool UnwindCursor<A, R>::getInfoFromSEH(pint_t pc) {1973pint_t base;1974RUNTIME_FUNCTION *unwindEntry = lookUpSEHUnwindInfo(pc, &base);1975if (!unwindEntry) {1976_LIBUNWIND_DEBUG_LOG("\tpc not in table, pc=0x%llX", (uint64_t) pc);1977return false;1978}1979_info.gp = 0;1980_info.flags = 0;1981_info.format = 0;1982_info.unwind_info_size = sizeof(RUNTIME_FUNCTION);1983_info.unwind_info = reinterpret_cast<unw_word_t>(unwindEntry);1984_info.extra = base;1985_info.start_ip = base + unwindEntry->BeginAddress;1986#ifdef _LIBUNWIND_TARGET_X86_641987_info.end_ip = base + unwindEntry->EndAddress;1988// Only fill in the handler and LSDA if they're stale.1989if (pc != getLastPC()) {1990UNWIND_INFO *xdata = reinterpret_cast<UNWIND_INFO *>(base + unwindEntry->UnwindData);1991if (xdata->Flags & (UNW_FLAG_EHANDLER|UNW_FLAG_UHANDLER)) {1992// The personality is given in the UNWIND_INFO itself. The LSDA immediately1993// follows the UNWIND_INFO. (This follows how both Clang and MSVC emit1994// these structures.)1995// N.B. UNWIND_INFO structs are DWORD-aligned.1996uint32_t lastcode = (xdata->CountOfCodes + 1) & ~1;1997const uint32_t *handler = reinterpret_cast<uint32_t *>(&xdata->UnwindCodes[lastcode]);1998_info.lsda = reinterpret_cast<unw_word_t>(handler+1);1999_dispContext.HandlerData = reinterpret_cast<void *>(_info.lsda);2000_dispContext.LanguageHandler =2001reinterpret_cast<EXCEPTION_ROUTINE *>(base + *handler);2002if (*handler) {2003_info.handler = reinterpret_cast<unw_word_t>(__libunwind_seh_personality);2004} else2005_info.handler = 0;2006} else {2007_info.lsda = 0;2008_info.handler = 0;2009}2010}2011#endif2012setLastPC(pc);2013return true;2014}2015#endif20162017#if defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)2018// Masks for traceback table field xtbtable.2019enum xTBTableMask : uint8_t {2020reservedBit = 0x02, // The traceback table was incorrectly generated if set2021// (see comments in function getInfoFromTBTable().2022ehInfoBit = 0x08 // Exception handling info is present if set2023};20242025enum frameType : unw_word_t {2026frameWithXLEHStateTable = 0,2027frameWithEHInfo = 12028};20292030extern "C" {2031typedef _Unwind_Reason_Code __xlcxx_personality_v0_t(int, _Unwind_Action,2032uint64_t,2033_Unwind_Exception *,2034struct _Unwind_Context *);2035__attribute__((__weak__)) __xlcxx_personality_v0_t __xlcxx_personality_v0;2036}20372038static __xlcxx_personality_v0_t *xlcPersonalityV0;2039static RWMutex xlcPersonalityV0InitLock;20402041template <typename A, typename R>2042bool UnwindCursor<A, R>::getInfoFromTBTable(pint_t pc, R ®isters) {2043uint32_t *p = reinterpret_cast<uint32_t *>(pc);20442045// Keep looking forward until a word of 0 is found. The traceback2046// table starts at the following word.2047while (*p)2048++p;2049tbtable *TBTable = reinterpret_cast<tbtable *>(p + 1);20502051if (_LIBUNWIND_TRACING_UNWINDING) {2052char functionBuf[512];2053const char *functionName = functionBuf;2054unw_word_t offset;2055if (!getFunctionName(functionBuf, sizeof(functionBuf), &offset)) {2056functionName = ".anonymous.";2057}2058_LIBUNWIND_TRACE_UNWINDING("%s: Look up traceback table of func=%s at %p",2059__func__, functionName,2060reinterpret_cast<void *>(TBTable));2061}20622063// If the traceback table does not contain necessary info, bypass this frame.2064if (!TBTable->tb.has_tboff)2065return false;20662067// Structure tbtable_ext contains important data we are looking for.2068p = reinterpret_cast<uint32_t *>(&TBTable->tb_ext);20692070// Skip field parminfo if it exists.2071if (TBTable->tb.fixedparms || TBTable->tb.floatparms)2072++p;20732074// p now points to tb_offset, the offset from start of function to TB table.2075unw_word_t start_ip =2076reinterpret_cast<unw_word_t>(TBTable) - *p - sizeof(uint32_t);2077unw_word_t end_ip = reinterpret_cast<unw_word_t>(TBTable);2078++p;20792080_LIBUNWIND_TRACE_UNWINDING("start_ip=%p, end_ip=%p\n",2081reinterpret_cast<void *>(start_ip),2082reinterpret_cast<void *>(end_ip));20832084// Skip field hand_mask if it exists.2085if (TBTable->tb.int_hndl)2086++p;20872088unw_word_t lsda = 0;2089unw_word_t handler = 0;2090unw_word_t flags = frameType::frameWithXLEHStateTable;20912092if (TBTable->tb.lang == TB_CPLUSPLUS && TBTable->tb.has_ctl) {2093// State table info is available. The ctl_info field indicates the2094// number of CTL anchors. There should be only one entry for the C++2095// state table.2096assert(*p == 1 && "libunwind: there must be only one ctl_info entry");2097++p;2098// p points to the offset of the state table into the stack.2099pint_t stateTableOffset = *p++;21002101int framePointerReg;21022103// Skip fields name_len and name if exist.2104if (TBTable->tb.name_present) {2105const uint16_t name_len = *(reinterpret_cast<uint16_t *>(p));2106p = reinterpret_cast<uint32_t *>(reinterpret_cast<char *>(p) + name_len +2107sizeof(uint16_t));2108}21092110if (TBTable->tb.uses_alloca)2111framePointerReg = *(reinterpret_cast<char *>(p));2112else2113framePointerReg = 1; // default frame pointer == SP21142115_LIBUNWIND_TRACE_UNWINDING(2116"framePointerReg=%d, framePointer=%p, "2117"stateTableOffset=%#lx\n",2118framePointerReg,2119reinterpret_cast<void *>(_registers.getRegister(framePointerReg)),2120stateTableOffset);2121lsda = _registers.getRegister(framePointerReg) + stateTableOffset;21222123// Since the traceback table generated by the legacy XLC++ does not2124// provide the location of the personality for the state table,2125// function __xlcxx_personality_v0(), which is the personality for the state2126// table and is exported from libc++abi, is directly assigned as the2127// handler here. When a legacy XLC++ frame is encountered, the symbol2128// is resolved dynamically using dlopen() to avoid hard dependency from2129// libunwind on libc++abi.21302131// Resolve the function pointer to the state table personality if it has2132// not already.2133if (xlcPersonalityV0 == NULL) {2134xlcPersonalityV0InitLock.lock();2135if (xlcPersonalityV0 == NULL) {2136// If libc++abi is statically linked in, symbol __xlcxx_personality_v02137// has been resolved at the link time.2138xlcPersonalityV0 = &__xlcxx_personality_v0;2139if (xlcPersonalityV0 == NULL) {2140// libc++abi is dynamically linked. Resolve __xlcxx_personality_v02141// using dlopen().2142const char libcxxabi[] = "libc++abi.a(libc++abi.so.1)";2143void *libHandle;2144// The AIX dlopen() sets errno to 0 when it is successful, which2145// clobbers the value of errno from the user code. This is an AIX2146// bug because according to POSIX it should not set errno to 0. To2147// workaround before AIX fixes the bug, errno is saved and restored.2148int saveErrno = errno;2149libHandle = dlopen(libcxxabi, RTLD_MEMBER | RTLD_NOW);2150if (libHandle == NULL) {2151_LIBUNWIND_TRACE_UNWINDING("dlopen() failed with errno=%d\n",2152errno);2153assert(0 && "dlopen() failed");2154}2155xlcPersonalityV0 = reinterpret_cast<__xlcxx_personality_v0_t *>(2156dlsym(libHandle, "__xlcxx_personality_v0"));2157if (xlcPersonalityV0 == NULL) {2158_LIBUNWIND_TRACE_UNWINDING("dlsym() failed with errno=%d\n", errno);2159assert(0 && "dlsym() failed");2160}2161dlclose(libHandle);2162errno = saveErrno;2163}2164}2165xlcPersonalityV0InitLock.unlock();2166}2167handler = reinterpret_cast<unw_word_t>(xlcPersonalityV0);2168_LIBUNWIND_TRACE_UNWINDING("State table: LSDA=%p, Personality=%p\n",2169reinterpret_cast<void *>(lsda),2170reinterpret_cast<void *>(handler));2171} else if (TBTable->tb.longtbtable) {2172// This frame has the traceback table extension. Possible cases are2173// 1) a C++ frame that has the 'eh_info' structure; 2) a C++ frame that2174// is not EH aware; or, 3) a frame of other languages. We need to figure out2175// if the traceback table extension contains the 'eh_info' structure.2176//2177// We also need to deal with the complexity arising from some XL compiler2178// versions use the wrong ordering of 'longtbtable' and 'has_vec' bits2179// where the 'longtbtable' bit is meant to be the 'has_vec' bit and vice2180// versa. For frames of code generated by those compilers, the 'longtbtable'2181// bit may be set but there isn't really a traceback table extension.2182//2183// In </usr/include/sys/debug.h>, there is the following definition of2184// 'struct tbtable_ext'. It is not really a structure but a dummy to2185// collect the description of optional parts of the traceback table.2186//2187// struct tbtable_ext {2188// ...2189// char alloca_reg; /* Register for alloca automatic storage */2190// struct vec_ext vec_ext; /* Vector extension (if has_vec is set) */2191// unsigned char xtbtable; /* More tbtable fields, if longtbtable is set*/2192// };2193//2194// Depending on how the 'has_vec'/'longtbtable' bit is interpreted, the data2195// following 'alloca_reg' can be treated either as 'struct vec_ext' or2196// 'unsigned char xtbtable'. 'xtbtable' bits are defined in2197// </usr/include/sys/debug.h> as flags. The 7th bit '0x02' is currently2198// unused and should not be set. 'struct vec_ext' is defined in2199// </usr/include/sys/debug.h> as follows:2200//2201// struct vec_ext {2202// unsigned vr_saved:6; /* Number of non-volatile vector regs saved2203// */2204// /* first register saved is assumed to be */2205// /* 32 - vr_saved */2206// unsigned saves_vrsave:1; /* Set if vrsave is saved on the stack */2207// unsigned has_varargs:1;2208// ...2209// };2210//2211// Here, the 7th bit is used as 'saves_vrsave'. To determine whether it2212// is 'struct vec_ext' or 'xtbtable' that follows 'alloca_reg',2213// we checks if the 7th bit is set or not because 'xtbtable' should2214// never have the 7th bit set. The 7th bit of 'xtbtable' will be reserved2215// in the future to make sure the mitigation works. This mitigation2216// is not 100% bullet proof because 'struct vec_ext' may not always have2217// 'saves_vrsave' bit set.2218//2219// 'reservedBit' is defined in enum 'xTBTableMask' above as the mask for2220// checking the 7th bit.22212222// p points to field name len.2223uint8_t *charPtr = reinterpret_cast<uint8_t *>(p);22242225// Skip fields name_len and name if they exist.2226if (TBTable->tb.name_present) {2227const uint16_t name_len = *(reinterpret_cast<uint16_t *>(charPtr));2228charPtr = charPtr + name_len + sizeof(uint16_t);2229}22302231// Skip field alloc_reg if it exists.2232if (TBTable->tb.uses_alloca)2233++charPtr;22342235// Check traceback table bit has_vec. Skip struct vec_ext if it exists.2236if (TBTable->tb.has_vec)2237// Note struct vec_ext does exist at this point because whether the2238// ordering of longtbtable and has_vec bits is correct or not, both2239// are set.2240charPtr += sizeof(struct vec_ext);22412242// charPtr points to field 'xtbtable'. Check if the EH info is available.2243// Also check if the reserved bit of the extended traceback table field2244// 'xtbtable' is set. If it is, the traceback table was incorrectly2245// generated by an XL compiler that uses the wrong ordering of 'longtbtable'2246// and 'has_vec' bits and this is in fact 'struct vec_ext'. So skip the2247// frame.2248if ((*charPtr & xTBTableMask::ehInfoBit) &&2249!(*charPtr & xTBTableMask::reservedBit)) {2250// Mark this frame has the new EH info.2251flags = frameType::frameWithEHInfo;22522253// eh_info is available.2254charPtr++;2255// The pointer is 4-byte aligned.2256if (reinterpret_cast<uintptr_t>(charPtr) % 4)2257charPtr += 4 - reinterpret_cast<uintptr_t>(charPtr) % 4;2258uintptr_t *ehInfo =2259reinterpret_cast<uintptr_t *>(*(reinterpret_cast<uintptr_t *>(2260registers.getRegister(2) +2261*(reinterpret_cast<uintptr_t *>(charPtr)))));22622263// ehInfo points to structure en_info. The first member is version.2264// Only version 0 is currently supported.2265assert(*(reinterpret_cast<uint32_t *>(ehInfo)) == 0 &&2266"libunwind: ehInfo version other than 0 is not supported");22672268// Increment ehInfo to point to member lsda.2269++ehInfo;2270lsda = *ehInfo++;22712272// enInfo now points to member personality.2273handler = *ehInfo;22742275_LIBUNWIND_TRACE_UNWINDING("Range table: LSDA=%#lx, Personality=%#lx\n",2276lsda, handler);2277}2278}22792280_info.start_ip = start_ip;2281_info.end_ip = end_ip;2282_info.lsda = lsda;2283_info.handler = handler;2284_info.gp = 0;2285_info.flags = flags;2286_info.format = 0;2287_info.unwind_info = reinterpret_cast<unw_word_t>(TBTable);2288_info.unwind_info_size = 0;2289_info.extra = registers.getRegister(2);22902291return true;2292}22932294// Step back up the stack following the frame back link.2295template <typename A, typename R>2296int UnwindCursor<A, R>::stepWithTBTable(pint_t pc, tbtable *TBTable,2297R ®isters, bool &isSignalFrame) {2298if (_LIBUNWIND_TRACING_UNWINDING) {2299char functionBuf[512];2300const char *functionName = functionBuf;2301unw_word_t offset;2302if (!getFunctionName(functionBuf, sizeof(functionBuf), &offset)) {2303functionName = ".anonymous.";2304}2305_LIBUNWIND_TRACE_UNWINDING(2306"%s: Look up traceback table of func=%s at %p, pc=%p, "2307"SP=%p, saves_lr=%d, stores_bc=%d",2308__func__, functionName, reinterpret_cast<void *>(TBTable),2309reinterpret_cast<void *>(pc),2310reinterpret_cast<void *>(registers.getSP()), TBTable->tb.saves_lr,2311TBTable->tb.stores_bc);2312}23132314#if defined(__powerpc64__)2315// Instruction to reload TOC register "ld r2,40(r1)"2316const uint32_t loadTOCRegInst = 0xe8410028;2317const int32_t unwPPCF0Index = UNW_PPC64_F0;2318const int32_t unwPPCV0Index = UNW_PPC64_V0;2319#else2320// Instruction to reload TOC register "lwz r2,20(r1)"2321const uint32_t loadTOCRegInst = 0x80410014;2322const int32_t unwPPCF0Index = UNW_PPC_F0;2323const int32_t unwPPCV0Index = UNW_PPC_V0;2324#endif23252326// lastStack points to the stack frame of the next routine up.2327pint_t curStack = static_cast<pint_t>(registers.getSP());2328pint_t lastStack = *reinterpret_cast<pint_t *>(curStack);23292330if (lastStack == 0)2331return UNW_STEP_END;23322333R newRegisters = registers;23342335// If backchain is not stored, use the current stack frame.2336if (!TBTable->tb.stores_bc)2337lastStack = curStack;23382339// Return address is the address after call site instruction.2340pint_t returnAddress;23412342if (isSignalFrame) {2343_LIBUNWIND_TRACE_UNWINDING("Possible signal handler frame: lastStack=%p",2344reinterpret_cast<void *>(lastStack));23452346sigcontext *sigContext = reinterpret_cast<sigcontext *>(2347reinterpret_cast<char *>(lastStack) + STKMINALIGN);2348returnAddress = sigContext->sc_jmpbuf.jmp_context.iar;23492350bool useSTKMIN = false;2351if (returnAddress < 0x10000000) {2352// Try again using STKMIN.2353sigContext = reinterpret_cast<sigcontext *>(2354reinterpret_cast<char *>(lastStack) + STKMIN);2355returnAddress = sigContext->sc_jmpbuf.jmp_context.iar;2356if (returnAddress < 0x10000000) {2357_LIBUNWIND_TRACE_UNWINDING("Bad returnAddress=%p from sigcontext=%p",2358reinterpret_cast<void *>(returnAddress),2359reinterpret_cast<void *>(sigContext));2360return UNW_EBADFRAME;2361}2362useSTKMIN = true;2363}2364_LIBUNWIND_TRACE_UNWINDING("Returning from a signal handler %s: "2365"sigContext=%p, returnAddress=%p. "2366"Seems to be a valid address",2367useSTKMIN ? "STKMIN" : "STKMINALIGN",2368reinterpret_cast<void *>(sigContext),2369reinterpret_cast<void *>(returnAddress));23702371// Restore the condition register from sigcontext.2372newRegisters.setCR(sigContext->sc_jmpbuf.jmp_context.cr);23732374// Save the LR in sigcontext for stepping up when the function that2375// raised the signal is a leaf function. This LR has the return address2376// to the caller of the leaf function.2377newRegisters.setLR(sigContext->sc_jmpbuf.jmp_context.lr);2378_LIBUNWIND_TRACE_UNWINDING(2379"Save LR=%p from sigcontext",2380reinterpret_cast<void *>(sigContext->sc_jmpbuf.jmp_context.lr));23812382// Restore GPRs from sigcontext.2383for (int i = 0; i < 32; ++i)2384newRegisters.setRegister(i, sigContext->sc_jmpbuf.jmp_context.gpr[i]);23852386// Restore FPRs from sigcontext.2387for (int i = 0; i < 32; ++i)2388newRegisters.setFloatRegister(i + unwPPCF0Index,2389sigContext->sc_jmpbuf.jmp_context.fpr[i]);23902391// Restore vector registers if there is an associated extended context2392// structure.2393if (sigContext->sc_jmpbuf.jmp_context.msr & __EXTCTX) {2394ucontext_t *uContext = reinterpret_cast<ucontext_t *>(sigContext);2395if (uContext->__extctx->__extctx_magic == __EXTCTX_MAGIC) {2396for (int i = 0; i < 32; ++i)2397newRegisters.setVectorRegister(2398i + unwPPCV0Index, *(reinterpret_cast<v128 *>(2399&(uContext->__extctx->__vmx.__vr[i]))));2400}2401}2402} else {2403// Step up a normal frame.24042405if (!TBTable->tb.saves_lr && registers.getLR()) {2406// This case should only occur if we were called from a signal handler2407// and the signal occurred in a function that doesn't save the LR.2408returnAddress = static_cast<pint_t>(registers.getLR());2409_LIBUNWIND_TRACE_UNWINDING("Use saved LR=%p",2410reinterpret_cast<void *>(returnAddress));2411} else {2412// Otherwise, use the LR value in the stack link area.2413returnAddress = reinterpret_cast<pint_t *>(lastStack)[2];2414}24152416// Reset LR in the current context.2417newRegisters.setLR(static_cast<uintptr_t>(NULL));24182419_LIBUNWIND_TRACE_UNWINDING(2420"Extract info from lastStack=%p, returnAddress=%p",2421reinterpret_cast<void *>(lastStack),2422reinterpret_cast<void *>(returnAddress));2423_LIBUNWIND_TRACE_UNWINDING("fpr_regs=%d, gpr_regs=%d, saves_cr=%d",2424TBTable->tb.fpr_saved, TBTable->tb.gpr_saved,2425TBTable->tb.saves_cr);24262427// Restore FP registers.2428char *ptrToRegs = reinterpret_cast<char *>(lastStack);2429double *FPRegs = reinterpret_cast<double *>(2430ptrToRegs - (TBTable->tb.fpr_saved * sizeof(double)));2431for (int i = 0; i < TBTable->tb.fpr_saved; ++i)2432newRegisters.setFloatRegister(243332 - TBTable->tb.fpr_saved + i + unwPPCF0Index, FPRegs[i]);24342435// Restore GP registers.2436ptrToRegs = reinterpret_cast<char *>(FPRegs);2437uintptr_t *GPRegs = reinterpret_cast<uintptr_t *>(2438ptrToRegs - (TBTable->tb.gpr_saved * sizeof(uintptr_t)));2439for (int i = 0; i < TBTable->tb.gpr_saved; ++i)2440newRegisters.setRegister(32 - TBTable->tb.gpr_saved + i, GPRegs[i]);24412442// Restore Vector registers.2443ptrToRegs = reinterpret_cast<char *>(GPRegs);24442445// Restore vector registers only if this is a Clang frame. Also2446// check if traceback table bit has_vec is set. If it is, structure2447// vec_ext is available.2448if (_info.flags == frameType::frameWithEHInfo && TBTable->tb.has_vec) {24492450// Get to the vec_ext structure to check if vector registers are saved.2451uint32_t *p = reinterpret_cast<uint32_t *>(&TBTable->tb_ext);24522453// Skip field parminfo if exists.2454if (TBTable->tb.fixedparms || TBTable->tb.floatparms)2455++p;24562457// Skip field tb_offset if exists.2458if (TBTable->tb.has_tboff)2459++p;24602461// Skip field hand_mask if exists.2462if (TBTable->tb.int_hndl)2463++p;24642465// Skip fields ctl_info and ctl_info_disp if exist.2466if (TBTable->tb.has_ctl) {2467// Skip field ctl_info.2468++p;2469// Skip field ctl_info_disp.2470++p;2471}24722473// Skip fields name_len and name if exist.2474// p is supposed to point to field name_len now.2475uint8_t *charPtr = reinterpret_cast<uint8_t *>(p);2476if (TBTable->tb.name_present) {2477const uint16_t name_len = *(reinterpret_cast<uint16_t *>(charPtr));2478charPtr = charPtr + name_len + sizeof(uint16_t);2479}24802481// Skip field alloc_reg if it exists.2482if (TBTable->tb.uses_alloca)2483++charPtr;24842485struct vec_ext *vec_ext = reinterpret_cast<struct vec_ext *>(charPtr);24862487_LIBUNWIND_TRACE_UNWINDING("vr_saved=%d", vec_ext->vr_saved);24882489// Restore vector register(s) if saved on the stack.2490if (vec_ext->vr_saved) {2491// Saved vector registers are 16-byte aligned.2492if (reinterpret_cast<uintptr_t>(ptrToRegs) % 16)2493ptrToRegs -= reinterpret_cast<uintptr_t>(ptrToRegs) % 16;2494v128 *VecRegs = reinterpret_cast<v128 *>(ptrToRegs - vec_ext->vr_saved *2495sizeof(v128));2496for (int i = 0; i < vec_ext->vr_saved; ++i) {2497newRegisters.setVectorRegister(249832 - vec_ext->vr_saved + i + unwPPCV0Index, VecRegs[i]);2499}2500}2501}2502if (TBTable->tb.saves_cr) {2503// Get the saved condition register. The condition register is only2504// a single word.2505newRegisters.setCR(2506*(reinterpret_cast<uint32_t *>(lastStack + sizeof(uintptr_t))));2507}25082509// Restore the SP.2510newRegisters.setSP(lastStack);25112512// The first instruction after return.2513uint32_t firstInstruction = *(reinterpret_cast<uint32_t *>(returnAddress));25142515// Do we need to set the TOC register?2516_LIBUNWIND_TRACE_UNWINDING(2517"Current gpr2=%p",2518reinterpret_cast<void *>(newRegisters.getRegister(2)));2519if (firstInstruction == loadTOCRegInst) {2520_LIBUNWIND_TRACE_UNWINDING(2521"Set gpr2=%p from frame",2522reinterpret_cast<void *>(reinterpret_cast<pint_t *>(lastStack)[5]));2523newRegisters.setRegister(2, reinterpret_cast<pint_t *>(lastStack)[5]);2524}2525}2526_LIBUNWIND_TRACE_UNWINDING("lastStack=%p, returnAddress=%p, pc=%p\n",2527reinterpret_cast<void *>(lastStack),2528reinterpret_cast<void *>(returnAddress),2529reinterpret_cast<void *>(pc));25302531// The return address is the address after call site instruction, so2532// setting IP to that simulates a return.2533newRegisters.setIP(reinterpret_cast<uintptr_t>(returnAddress));25342535// Simulate the step by replacing the register set with the new ones.2536registers = newRegisters;25372538// Check if the next frame is a signal frame.2539pint_t nextStack = *(reinterpret_cast<pint_t *>(registers.getSP()));25402541// Return address is the address after call site instruction.2542pint_t nextReturnAddress = reinterpret_cast<pint_t *>(nextStack)[2];25432544if (nextReturnAddress > 0x01 && nextReturnAddress < 0x10000) {2545_LIBUNWIND_TRACE_UNWINDING("The next is a signal handler frame: "2546"nextStack=%p, next return address=%p\n",2547reinterpret_cast<void *>(nextStack),2548reinterpret_cast<void *>(nextReturnAddress));2549isSignalFrame = true;2550} else {2551isSignalFrame = false;2552}2553return UNW_STEP_SUCCESS;2554}2555#endif // defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)25562557template <typename A, typename R>2558void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {2559#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)2560_isSigReturn = false;2561#endif25622563pint_t pc = static_cast<pint_t>(this->getReg(UNW_REG_IP));2564#if defined(_LIBUNWIND_ARM_EHABI)2565// Remove the thumb bit so the IP represents the actual instruction address.2566// This matches the behaviour of _Unwind_GetIP on arm.2567pc &= (pint_t)~0x1;2568#endif25692570// Exit early if at the top of the stack.2571if (pc == 0) {2572_unwindInfoMissing = true;2573return;2574}25752576// If the last line of a function is a "throw" the compiler sometimes2577// emits no instructions after the call to __cxa_throw. This means2578// the return address is actually the start of the next function.2579// To disambiguate this, back up the pc when we know it is a return2580// address.2581if (isReturnAddress)2582#if defined(_AIX)2583// PC needs to be a 4-byte aligned address to be able to look for a2584// word of 0 that indicates the start of the traceback table at the end2585// of a function on AIX.2586pc -= 4;2587#else2588--pc;2589#endif25902591#if !(defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)) && \2592!defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)2593// In case of this is frame of signal handler, the IP saved in the signal2594// handler points to first non-executed instruction, while FDE/CIE expects IP2595// to be after the first non-executed instruction.2596if (_isSignalFrame)2597++pc;2598#endif25992600// Ask address space object to find unwind sections for this pc.2601UnwindInfoSections sects;2602if (_addressSpace.findUnwindSections(pc, sects)) {2603#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)2604// If there is a compact unwind encoding table, look there first.2605if (sects.compact_unwind_section != 0) {2606if (this->getInfoFromCompactEncodingSection(pc, sects)) {2607#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)2608// Found info in table, done unless encoding says to use dwarf.2609uint32_t dwarfOffset;2610if ((sects.dwarf_section != 0) && compactSaysUseDwarf(&dwarfOffset)) {2611if (this->getInfoFromDwarfSection(pc, sects, dwarfOffset)) {2612// found info in dwarf, done2613return;2614}2615}2616#endif2617// If unwind table has entry, but entry says there is no unwind info,2618// record that we have no unwind info.2619if (_info.format == 0)2620_unwindInfoMissing = true;2621return;2622}2623}2624#endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)26252626#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)2627// If there is SEH unwind info, look there next.2628if (this->getInfoFromSEH(pc))2629return;2630#endif26312632#if defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)2633// If there is unwind info in the traceback table, look there next.2634if (this->getInfoFromTBTable(pc, _registers))2635return;2636#endif26372638#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)2639// If there is dwarf unwind info, look there next.2640if (sects.dwarf_section != 0) {2641if (this->getInfoFromDwarfSection(pc, sects)) {2642// found info in dwarf, done2643return;2644}2645}2646#endif26472648#if defined(_LIBUNWIND_ARM_EHABI)2649// If there is ARM EHABI unwind info, look there next.2650if (sects.arm_section != 0 && this->getInfoFromEHABISection(pc, sects))2651return;2652#endif2653}26542655#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)2656// There is no static unwind info for this pc. Look to see if an FDE was2657// dynamically registered for it.2658pint_t cachedFDE = DwarfFDECache<A>::findFDE(DwarfFDECache<A>::kSearchAll,2659pc);2660if (cachedFDE != 0) {2661typename CFI_Parser<A>::FDE_Info fdeInfo;2662typename CFI_Parser<A>::CIE_Info cieInfo;2663if (!CFI_Parser<A>::decodeFDE(_addressSpace, cachedFDE, &fdeInfo, &cieInfo))2664if (getInfoFromFdeCie(fdeInfo, cieInfo, pc, 0))2665return;2666}26672668// Lastly, ask AddressSpace object about platform specific ways to locate2669// other FDEs.2670pint_t fde;2671if (_addressSpace.findOtherFDE(pc, fde)) {2672typename CFI_Parser<A>::FDE_Info fdeInfo;2673typename CFI_Parser<A>::CIE_Info cieInfo;2674if (!CFI_Parser<A>::decodeFDE(_addressSpace, fde, &fdeInfo, &cieInfo)) {2675// Double check this FDE is for a function that includes the pc.2676if ((fdeInfo.pcStart <= pc) && (pc < fdeInfo.pcEnd))2677if (getInfoFromFdeCie(fdeInfo, cieInfo, pc, 0))2678return;2679}2680}2681#endif // #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)26822683#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)2684if (setInfoForSigReturn())2685return;2686#endif26872688// no unwind info, flag that we can't reliably unwind2689_unwindInfoMissing = true;2690}26912692#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) && \2693defined(_LIBUNWIND_TARGET_AARCH64)2694template <typename A, typename R>2695bool UnwindCursor<A, R>::setInfoForSigReturn(Registers_arm64 &) {2696// Look for the sigreturn trampoline. The trampoline's body is two2697// specific instructions (see below). Typically the trampoline comes from the2698// vDSO[1] (i.e. the __kernel_rt_sigreturn function). A libc might provide its2699// own restorer function, though, or user-mode QEMU might write a trampoline2700// onto the stack.2701//2702// This special code path is a fallback that is only used if the trampoline2703// lacks proper (e.g. DWARF) unwind info. On AArch64, a new DWARF register2704// constant for the PC needs to be defined before DWARF can handle a signal2705// trampoline. This code may segfault if the target PC is unreadable, e.g.:2706// - The PC points at a function compiled without unwind info, and which is2707// part of an execute-only mapping (e.g. using -Wl,--execute-only).2708// - The PC is invalid and happens to point to unreadable or unmapped memory.2709//2710// [1] https://github.com/torvalds/linux/blob/master/arch/arm64/kernel/vdso/sigreturn.S2711const pint_t pc = static_cast<pint_t>(this->getReg(UNW_REG_IP));2712// The PC might contain an invalid address if the unwind info is bad, so2713// directly accessing it could cause a SIGSEGV.2714if (!isReadableAddr(pc))2715return false;2716auto *instructions = reinterpret_cast<const uint32_t *>(pc);2717// Look for instructions: mov x8, #0x8b; svc #0x02718if (instructions[0] != 0xd2801168 || instructions[1] != 0xd4000001)2719return false;27202721_info = {};2722_info.start_ip = pc;2723_info.end_ip = pc + 4;2724_isSigReturn = true;2725return true;2726}27272728template <typename A, typename R>2729int UnwindCursor<A, R>::stepThroughSigReturn(Registers_arm64 &) {2730// In the signal trampoline frame, sp points to an rt_sigframe[1], which is:2731// - 128-byte siginfo struct2732// - ucontext struct:2733// - 8-byte long (uc_flags)2734// - 8-byte pointer (uc_link)2735// - 24-byte stack_t2736// - 128-byte signal set2737// - 8 bytes of padding because sigcontext has 16-byte alignment2738// - sigcontext/mcontext_t2739// [1] https://github.com/torvalds/linux/blob/master/arch/arm64/kernel/signal.c2740const pint_t kOffsetSpToSigcontext = (128 + 8 + 8 + 24 + 128 + 8); // 30427412742// Offsets from sigcontext to each register.2743const pint_t kOffsetGprs = 8; // offset to "__u64 regs[31]" field2744const pint_t kOffsetSp = 256; // offset to "__u64 sp" field2745const pint_t kOffsetPc = 264; // offset to "__u64 pc" field27462747pint_t sigctx = _registers.getSP() + kOffsetSpToSigcontext;27482749for (int i = 0; i <= 30; ++i) {2750uint64_t value = _addressSpace.get64(sigctx + kOffsetGprs +2751static_cast<pint_t>(i * 8));2752_registers.setRegister(UNW_AARCH64_X0 + i, value);2753}2754_registers.setSP(_addressSpace.get64(sigctx + kOffsetSp));2755_registers.setIP(_addressSpace.get64(sigctx + kOffsetPc));2756_isSignalFrame = true;2757return UNW_STEP_SUCCESS;2758}2759#endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&2760// defined(_LIBUNWIND_TARGET_AARCH64)27612762#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) && \2763defined(_LIBUNWIND_TARGET_RISCV)2764template <typename A, typename R>2765bool UnwindCursor<A, R>::setInfoForSigReturn(Registers_riscv &) {2766const pint_t pc = static_cast<pint_t>(getReg(UNW_REG_IP));2767// The PC might contain an invalid address if the unwind info is bad, so2768// directly accessing it could cause a SIGSEGV.2769if (!isReadableAddr(pc))2770return false;2771const auto *instructions = reinterpret_cast<const uint32_t *>(pc);2772// Look for the two instructions used in the sigreturn trampoline2773// __vdso_rt_sigreturn:2774//2775// 0x08b00893 li a7,0x8b2776// 0x00000073 ecall2777if (instructions[0] != 0x08b00893 || instructions[1] != 0x00000073)2778return false;27792780_info = {};2781_info.start_ip = pc;2782_info.end_ip = pc + 4;2783_isSigReturn = true;2784return true;2785}27862787template <typename A, typename R>2788int UnwindCursor<A, R>::stepThroughSigReturn(Registers_riscv &) {2789// In the signal trampoline frame, sp points to an rt_sigframe[1], which is:2790// - 128-byte siginfo struct2791// - ucontext_t struct:2792// - 8-byte long (__uc_flags)2793// - 8-byte pointer (*uc_link)2794// - 24-byte uc_stack2795// - 8-byte uc_sigmask2796// - 120-byte of padding to allow sigset_t to be expanded in the future2797// - 8 bytes of padding because sigcontext has 16-byte alignment2798// - struct sigcontext uc_mcontext2799// [1]2800// https://github.com/torvalds/linux/blob/master/arch/riscv/kernel/signal.c2801const pint_t kOffsetSpToSigcontext = 128 + 8 + 8 + 24 + 8 + 128;28022803const pint_t sigctx = _registers.getSP() + kOffsetSpToSigcontext;2804_registers.setIP(_addressSpace.get64(sigctx));2805for (int i = UNW_RISCV_X1; i <= UNW_RISCV_X31; ++i) {2806uint64_t value = _addressSpace.get64(sigctx + static_cast<pint_t>(i * 8));2807_registers.setRegister(i, value);2808}2809_isSignalFrame = true;2810return UNW_STEP_SUCCESS;2811}2812#endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&2813// defined(_LIBUNWIND_TARGET_RISCV)28142815#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) && \2816defined(_LIBUNWIND_TARGET_S390X)2817template <typename A, typename R>2818bool UnwindCursor<A, R>::setInfoForSigReturn(Registers_s390x &) {2819// Look for the sigreturn trampoline. The trampoline's body is a2820// specific instruction (see below). Typically the trampoline comes from the2821// vDSO (i.e. the __kernel_[rt_]sigreturn function). A libc might provide its2822// own restorer function, though, or user-mode QEMU might write a trampoline2823// onto the stack.2824const pint_t pc = static_cast<pint_t>(this->getReg(UNW_REG_IP));2825// The PC might contain an invalid address if the unwind info is bad, so2826// directly accessing it could cause a SIGSEGV.2827if (!isReadableAddr(pc))2828return false;2829const auto inst = *reinterpret_cast<const uint16_t *>(pc);2830if (inst == 0x0a77 || inst == 0x0aad) {2831_info = {};2832_info.start_ip = pc;2833_info.end_ip = pc + 2;2834_isSigReturn = true;2835return true;2836}2837return false;2838}28392840template <typename A, typename R>2841int UnwindCursor<A, R>::stepThroughSigReturn(Registers_s390x &) {2842// Determine current SP.2843const pint_t sp = static_cast<pint_t>(this->getReg(UNW_REG_SP));2844// According to the s390x ABI, the CFA is at (incoming) SP + 160.2845const pint_t cfa = sp + 160;28462847// Determine current PC and instruction there (this must be either2848// a "svc __NR_sigreturn" or "svc __NR_rt_sigreturn").2849const pint_t pc = static_cast<pint_t>(this->getReg(UNW_REG_IP));2850const uint16_t inst = _addressSpace.get16(pc);28512852// Find the addresses of the signo and sigcontext in the frame.2853pint_t pSigctx = 0;2854pint_t pSigno = 0;28552856// "svc __NR_sigreturn" uses a non-RT signal trampoline frame.2857if (inst == 0x0a77) {2858// Layout of a non-RT signal trampoline frame, starting at the CFA:2859// - 8-byte signal mask2860// - 8-byte pointer to sigcontext, followed by signo2861// - 4-byte signo2862pSigctx = _addressSpace.get64(cfa + 8);2863pSigno = pSigctx + 344;2864}28652866// "svc __NR_rt_sigreturn" uses a RT signal trampoline frame.2867if (inst == 0x0aad) {2868// Layout of a RT signal trampoline frame, starting at the CFA:2869// - 8-byte retcode (+ alignment)2870// - 128-byte siginfo struct (starts with signo)2871// - ucontext struct:2872// - 8-byte long (uc_flags)2873// - 8-byte pointer (uc_link)2874// - 24-byte stack_t2875// - 8 bytes of padding because sigcontext has 16-byte alignment2876// - sigcontext/mcontext_t2877pSigctx = cfa + 8 + 128 + 8 + 8 + 24 + 8;2878pSigno = cfa + 8;2879}28802881assert(pSigctx != 0);2882assert(pSigno != 0);28832884// Offsets from sigcontext to each register.2885const pint_t kOffsetPc = 8;2886const pint_t kOffsetGprs = 16;2887const pint_t kOffsetFprs = 216;28882889// Restore all registers.2890for (int i = 0; i < 16; ++i) {2891uint64_t value = _addressSpace.get64(pSigctx + kOffsetGprs +2892static_cast<pint_t>(i * 8));2893_registers.setRegister(UNW_S390X_R0 + i, value);2894}2895for (int i = 0; i < 16; ++i) {2896static const int fpr[16] = {2897UNW_S390X_F0, UNW_S390X_F1, UNW_S390X_F2, UNW_S390X_F3,2898UNW_S390X_F4, UNW_S390X_F5, UNW_S390X_F6, UNW_S390X_F7,2899UNW_S390X_F8, UNW_S390X_F9, UNW_S390X_F10, UNW_S390X_F11,2900UNW_S390X_F12, UNW_S390X_F13, UNW_S390X_F14, UNW_S390X_F152901};2902double value = _addressSpace.getDouble(pSigctx + kOffsetFprs +2903static_cast<pint_t>(i * 8));2904_registers.setFloatRegister(fpr[i], value);2905}2906_registers.setIP(_addressSpace.get64(pSigctx + kOffsetPc));29072908// SIGILL, SIGFPE and SIGTRAP are delivered with psw_addr2909// after the faulting instruction rather than before it.2910// Do not set _isSignalFrame in that case.2911uint32_t signo = _addressSpace.get32(pSigno);2912_isSignalFrame = (signo != 4 && signo != 5 && signo != 8);29132914return UNW_STEP_SUCCESS;2915}2916#endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&2917// defined(_LIBUNWIND_TARGET_S390X)29182919template <typename A, typename R> int UnwindCursor<A, R>::step(bool stage2) {2920(void)stage2;2921// Bottom of stack is defined is when unwind info cannot be found.2922if (_unwindInfoMissing)2923return UNW_STEP_END;29242925// Use unwinding info to modify register set as if function returned.2926int result;2927#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)2928if (_isSigReturn) {2929result = this->stepThroughSigReturn();2930} else2931#endif2932{2933#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)2934result = this->stepWithCompactEncoding(stage2);2935#elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)2936result = this->stepWithSEHData();2937#elif defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)2938result = this->stepWithTBTableData();2939#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)2940result = this->stepWithDwarfFDE(stage2);2941#elif defined(_LIBUNWIND_ARM_EHABI)2942result = this->stepWithEHABI();2943#else2944#error Need _LIBUNWIND_SUPPORT_COMPACT_UNWIND or \2945_LIBUNWIND_SUPPORT_SEH_UNWIND or \2946_LIBUNWIND_SUPPORT_DWARF_UNWIND or \2947_LIBUNWIND_ARM_EHABI2948#endif2949}29502951// update info based on new PC2952if (result == UNW_STEP_SUCCESS) {2953this->setInfoBasedOnIPRegister(true);2954if (_unwindInfoMissing)2955return UNW_STEP_END;2956}29572958return result;2959}29602961template <typename A, typename R>2962void UnwindCursor<A, R>::getInfo(unw_proc_info_t *info) {2963if (_unwindInfoMissing)2964memset(info, 0, sizeof(*info));2965else2966*info = _info;2967}29682969template <typename A, typename R>2970bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,2971unw_word_t *offset) {2972return _addressSpace.findFunctionName((pint_t)this->getReg(UNW_REG_IP),2973buf, bufLen, offset);2974}29752976#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)2977template <typename A, typename R>2978bool UnwindCursor<A, R>::isReadableAddr(const pint_t addr) const {2979// We use SYS_rt_sigprocmask, inspired by Abseil's AddressIsReadable.29802981const auto sigsetAddr = reinterpret_cast<sigset_t *>(addr);2982// We have to check that addr is nullptr because sigprocmask allows that2983// as an argument without failure.2984if (!sigsetAddr)2985return false;2986const auto saveErrno = errno;2987// We MUST use a raw syscall here, as wrappers may try to access2988// sigsetAddr which may cause a SIGSEGV. A raw syscall however is2989// safe. Additionally, we need to pass the kernel_sigset_size, which is2990// different from libc sizeof(sigset_t). For the majority of architectures,2991// it's 64 bits (_NSIG), and libc NSIG is _NSIG + 1.2992const auto kernelSigsetSize = NSIG / 8;2993[[maybe_unused]] const int Result = syscall(2994SYS_rt_sigprocmask, /*how=*/~0, sigsetAddr, nullptr, kernelSigsetSize);2995// Because our "how" is invalid, this syscall should always fail, and our2996// errno should always be EINVAL or an EFAULT. This relies on the Linux2997// kernel to check copy_from_user before checking if the "how" argument is2998// invalid.2999assert(Result == -1);3000assert(errno == EFAULT || errno == EINVAL);3001const auto readable = errno != EFAULT;3002errno = saveErrno;3003return readable;3004}3005#endif30063007#if defined(_LIBUNWIND_USE_CET) || defined(_LIBUNWIND_USE_GCS)3008extern "C" void *__libunwind_cet_get_registers(unw_cursor_t *cursor) {3009AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;3010return co->get_registers();3011}3012#endif3013} // namespace libunwind30143015#endif // __UNWINDCURSOR_HPP__301630173018