summaryrefslogtreecommitdiff
path: root/lib/libunwind
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2019-06-17 22:28:52 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2019-06-17 22:28:52 +0000
commit68a18d1be9bd7a51e7d0e71290640557e3cbecaf (patch)
tree73d3facded35803d6c2f71016635395d013ef7c6 /lib/libunwind
parentb4a1f8521384650da3ecc0ca80a87a4339df1a1d (diff)
Merge libc++, libc++abi and libunwind version 8.0.0.
Ports build by naddy@ Tested by visa on octeon Tested by kettenis on macppc and sparc64
Diffstat (limited to 'lib/libunwind')
-rw-r--r--lib/libunwind/include/__libunwind_config.h24
-rw-r--r--lib/libunwind/include/libunwind.h41
-rw-r--r--lib/libunwind/src/AddressSpace.hpp14
-rw-r--r--lib/libunwind/src/DwarfInstructions.hpp38
-rw-r--r--lib/libunwind/src/DwarfParser.hpp87
-rw-r--r--lib/libunwind/src/EHHeaderParser.hpp16
-rw-r--r--lib/libunwind/src/Registers.hpp243
-rw-r--r--lib/libunwind/src/UnwindCursor.hpp550
-rw-r--r--lib/libunwind/src/UnwindRegistersRestore.S110
-rw-r--r--lib/libunwind/src/UnwindRegistersSave.S33
-rw-r--r--lib/libunwind/src/assembly.h14
-rw-r--r--lib/libunwind/src/libunwind.cpp2
12 files changed, 1079 insertions, 93 deletions
diff --git a/lib/libunwind/include/__libunwind_config.h b/lib/libunwind/include/__libunwind_config.h
index 9effc8ac58a..fbc7f08f9a0 100644
--- a/lib/libunwind/include/__libunwind_config.h
+++ b/lib/libunwind/include/__libunwind_config.h
@@ -23,6 +23,7 @@
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM 287
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_OR1K 32
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_MIPS 65
+#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC 31
#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC64 32
#if defined(_LIBUNWIND_IS_NATIVE_ONLY)
@@ -35,7 +36,11 @@
# define _LIBUNWIND_TARGET_X86_64 1
# if defined(_WIN64)
# define _LIBUNWIND_CONTEXT_SIZE 54
-# define _LIBUNWIND_CURSOR_SIZE 66
+# ifdef __SEH__
+# define _LIBUNWIND_CURSOR_SIZE 204
+# else
+# define _LIBUNWIND_CURSOR_SIZE 66
+# endif
# else
# define _LIBUNWIND_CONTEXT_SIZE 21
# define _LIBUNWIND_CURSOR_SIZE 33
@@ -54,11 +59,18 @@
# elif defined(__aarch64__)
# define _LIBUNWIND_TARGET_AARCH64 1
# define _LIBUNWIND_CONTEXT_SIZE 66
-# define _LIBUNWIND_CURSOR_SIZE 78
+# if defined(__SEH__)
+# define _LIBUNWIND_CURSOR_SIZE 164
+# else
+# define _LIBUNWIND_CURSOR_SIZE 78
+# endif
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64
# elif defined(__arm__)
# define _LIBUNWIND_TARGET_ARM 1
-# if defined(__ARM_WMMX)
+# if defined(__SEH__)
+# define _LIBUNWIND_CONTEXT_SIZE 42
+# define _LIBUNWIND_CURSOR_SIZE 80
+# elif defined(__ARM_WMMX)
# define _LIBUNWIND_CONTEXT_SIZE 61
# define _LIBUNWIND_CURSOR_SIZE 68
# else
@@ -108,6 +120,11 @@
# define _LIBUNWIND_CONTEXT_SIZE 33
# define _LIBUNWIND_CURSOR_SIZE 45
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC64
+# elif defined(__sparc__)
+ #define _LIBUNWIND_TARGET_SPARC 1
+ #define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC
+ #define _LIBUNWIND_CONTEXT_SIZE 16
+ #define _LIBUNWIND_CURSOR_SIZE 23
# else
# error "Unsupported architecture."
# endif
@@ -121,6 +138,7 @@
# define _LIBUNWIND_TARGET_OR1K 1
# define _LIBUNWIND_TARGET_MIPS_O32 1
# define _LIBUNWIND_TARGET_MIPS_NEWABI 1
+# define _LIBUNWIND_TARGET_SPARC 1
# define _LIBUNWIND_TARGET_SPARC64 1
# define _LIBUNWIND_CONTEXT_SIZE 167
# define _LIBUNWIND_CURSOR_SIZE 179
diff --git a/lib/libunwind/include/libunwind.h b/lib/libunwind/include/libunwind.h
index 97d2b82290c..29c4aebde5a 100644
--- a/lib/libunwind/include/libunwind.h
+++ b/lib/libunwind/include/libunwind.h
@@ -57,6 +57,9 @@ enum {
UNW_EINVAL = -6547, /* unsupported operation or bad value */
UNW_EBADVERSION = -6548, /* unwind info has unsupported version */
UNW_ENOINFO = -6549 /* no unwind info found */
+#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY)
+ , UNW_ECROSSRASIGNING = -6550 /* cross unwind with return address signing */
+#endif
};
struct unw_context_t {
@@ -547,6 +550,8 @@ enum {
UNW_ARM64_X31 = 31,
UNW_ARM64_SP = 31,
// reserved block
+ UNW_ARM64_RA_SIGN_STATE = 34,
+ // reserved block
UNW_ARM64_D0 = 64,
UNW_ARM64_D1 = 65,
UNW_ARM64_D2 = 66,
@@ -818,4 +823,40 @@ enum {
UNW_MIPS_LO = 65,
};
+// SPARC registers
+enum {
+ UNW_SPARC_G0 = 0,
+ UNW_SPARC_G1 = 1,
+ UNW_SPARC_G2 = 2,
+ UNW_SPARC_G3 = 3,
+ UNW_SPARC_G4 = 4,
+ UNW_SPARC_G5 = 5,
+ UNW_SPARC_G6 = 6,
+ UNW_SPARC_G7 = 7,
+ UNW_SPARC_O0 = 8,
+ UNW_SPARC_O1 = 9,
+ UNW_SPARC_O2 = 10,
+ UNW_SPARC_O3 = 11,
+ UNW_SPARC_O4 = 12,
+ UNW_SPARC_O5 = 13,
+ UNW_SPARC_O6 = 14,
+ UNW_SPARC_O7 = 15,
+ UNW_SPARC_L0 = 16,
+ UNW_SPARC_L1 = 17,
+ UNW_SPARC_L2 = 18,
+ UNW_SPARC_L3 = 19,
+ UNW_SPARC_L4 = 20,
+ UNW_SPARC_L5 = 21,
+ UNW_SPARC_L6 = 22,
+ UNW_SPARC_L7 = 23,
+ UNW_SPARC_I0 = 24,
+ UNW_SPARC_I1 = 25,
+ UNW_SPARC_I2 = 26,
+ UNW_SPARC_I3 = 27,
+ UNW_SPARC_I4 = 28,
+ UNW_SPARC_I5 = 29,
+ UNW_SPARC_I6 = 30,
+ UNW_SPARC_I7 = 31,
+};
+
#endif
diff --git a/lib/libunwind/src/AddressSpace.hpp b/lib/libunwind/src/AddressSpace.hpp
index 35d38a185a8..2bedc4c4e7f 100644
--- a/lib/libunwind/src/AddressSpace.hpp
+++ b/lib/libunwind/src/AddressSpace.hpp
@@ -156,7 +156,7 @@ namespace libunwind {
struct UnwindInfoSections {
#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) || defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) || \
defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
- // No dso_base for ARM EHABI.
+ // No dso_base for SEH or ARM EHABI.
uintptr_t dso_base;
#endif
#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
@@ -237,7 +237,7 @@ private:
/// LocalAddressSpace is used as a template parameter to UnwindCursor when
/// unwinding a thread in the same process. The wrappers compile away,
/// making local unwinds fast.
-class __attribute__((visibility("hidden"))) LocalAddressSpace {
+class _LIBUNWIND_HIDDEN LocalAddressSpace {
public:
typedef uintptr_t pint_t;
typedef intptr_t sint_t;
@@ -515,6 +515,10 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
}
}
return false;
+#elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
+ // Don't even bother, since Windows has functions that do all this stuff
+ // for us.
+ return true;
#elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__) && \
(__ANDROID_API__ < 21)
int length = 0;
@@ -591,11 +595,11 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
#endif
cbdata->sects->dwarf_index_section = eh_frame_hdr_start;
cbdata->sects->dwarf_index_section_length = phdr->p_memsz;
- EHHeaderParser<LocalAddressSpace>::decodeEHHdr(
+ found_hdr = EHHeaderParser<LocalAddressSpace>::decodeEHHdr(
*cbdata->addressSpace, eh_frame_hdr_start, phdr->p_memsz,
hdrInfo);
- cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
- found_hdr = true;
+ if (found_hdr)
+ cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
}
}
diff --git a/lib/libunwind/src/DwarfInstructions.hpp b/lib/libunwind/src/DwarfInstructions.hpp
index 93de0c0ea57..fcf2dd0c739 100644
--- a/lib/libunwind/src/DwarfInstructions.hpp
+++ b/lib/libunwind/src/DwarfInstructions.hpp
@@ -165,7 +165,7 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
&cieInfo) == NULL) {
PrologInfo prolog;
if (CFI_Parser<A>::parseFDEInstructions(addressSpace, fdeInfo, cieInfo, pc,
- &prolog)) {
+ R::getArch(), &prolog)) {
// get pointer to cfa (architecture specific)
pint_t cfa = getCFA(addressSpace, prolog, registers);
@@ -204,6 +204,42 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
// restoring SP means setting it to CFA.
newRegisters.setSP(cfa);
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+ // If the target is aarch64 then the return address may have been signed
+ // using the v8.3 pointer authentication extensions. The original
+ // return address needs to be authenticated before the return address is
+ // restored. autia1716 is used instead of autia as autia1716 assembles
+ // to a NOP on pre-v8.3a architectures.
+ if ((R::getArch() == REGISTERS_ARM64) &&
+ prolog.savedRegisters[UNW_ARM64_RA_SIGN_STATE].value) {
+#if !defined(_LIBUNWIND_IS_NATIVE_ONLY)
+ return UNW_ECROSSRASIGNING;
+#else
+ register unsigned long long x17 __asm("x17") = returnAddress;
+ register unsigned long long x16 __asm("x16") = cfa;
+
+ // These are the autia1716/autib1716 instructions. The hint instructions
+ // are used here as gcc does not assemble autia1716/autib1716 for pre
+ // armv8.3a targets.
+ if (cieInfo.addressesSignedWithBKey)
+ asm("hint 0xe" : "+r"(x17) : "r"(x16)); // autib1716
+ else
+ asm("hint 0xc" : "+r"(x17) : "r"(x16)); // autia1716
+ returnAddress = x17;
+#endif
+ }
+#endif
+
+#if defined(_LIBUNWIND_TARGET_SPARC)
+ if (R::getArch() == REGISTERS_SPARC) {
+ // Skip call site instruction and delay slot
+ returnAddress += 8;
+ // Skip unimp instruction if function returns a struct
+ if ((addressSpace.get32(returnAddress) & 0xC1C00000) == 0)
+ returnAddress += 4;
+ }
+#endif
+
// Return address is address after call site instruction, so setting IP to
// that does simualates a return.
newRegisters.setIP(returnAddress);
diff --git a/lib/libunwind/src/DwarfParser.hpp b/lib/libunwind/src/DwarfParser.hpp
index 699e4fb56e4..7a7aba46e1d 100644
--- a/lib/libunwind/src/DwarfParser.hpp
+++ b/lib/libunwind/src/DwarfParser.hpp
@@ -20,6 +20,7 @@
#include "libunwind.h"
#include "dwarf2.h"
+#include "Registers.hpp"
#include "config.h"
@@ -49,6 +50,9 @@ public:
bool isSignalFrame;
bool fdesHaveAugmentationData;
uint8_t returnAddressRegister;
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+ bool addressesSignedWithBKey;
+#endif
};
/// Information about an FDE (Frame Description Entry)
@@ -104,7 +108,7 @@ public:
FDE_Info *fdeInfo, CIE_Info *cieInfo);
static bool parseFDEInstructions(A &addressSpace, const FDE_Info &fdeInfo,
const CIE_Info &cieInfo, pint_t upToPC,
- PrologInfo *results);
+ int arch, PrologInfo *results);
static const char *parseCIE(A &addressSpace, pint_t cie, CIE_Info *cieInfo);
@@ -112,7 +116,7 @@ private:
static bool parseInstructions(A &addressSpace, pint_t instructions,
pint_t instructionsEnd, const CIE_Info &cieInfo,
pint_t pcoffset,
- PrologInfoStackEntry *&rememberStack,
+ PrologInfoStackEntry *&rememberStack, int arch,
PrologInfo *results);
};
@@ -264,6 +268,9 @@ const char *CFI_Parser<A>::parseCIE(A &addressSpace, pint_t cie,
cieInfo->dataAlignFactor = 0;
cieInfo->isSignalFrame = false;
cieInfo->fdesHaveAugmentationData = false;
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+ cieInfo->addressesSignedWithBKey = false;
+#endif
cieInfo->cieStart = cie;
pint_t p = cie;
pint_t cieLength = (pint_t)addressSpace.get32(p);
@@ -327,6 +334,11 @@ const char *CFI_Parser<A>::parseCIE(A &addressSpace, pint_t cie,
case 'S':
cieInfo->isSignalFrame = true;
break;
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+ case 'B':
+ cieInfo->addressesSignedWithBKey = true;
+ break;
+#endif
default:
// ignore unknown letters
break;
@@ -344,7 +356,7 @@ template <typename A>
bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,
const FDE_Info &fdeInfo,
const CIE_Info &cieInfo, pint_t upToPC,
- PrologInfo *results) {
+ int arch, PrologInfo *results) {
// clear results
memset(results, '\0', sizeof(PrologInfo));
PrologInfoStackEntry *rememberStack = NULL;
@@ -352,10 +364,11 @@ bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,
// parse CIE then FDE instructions
return parseInstructions(addressSpace, cieInfo.cieInstructions,
cieInfo.cieStart + cieInfo.cieLength, cieInfo,
- (pint_t)(-1), rememberStack, results) &&
+ (pint_t)(-1), rememberStack, arch, results) &&
parseInstructions(addressSpace, fdeInfo.fdeInstructions,
fdeInfo.fdeStart + fdeInfo.fdeLength, cieInfo,
- upToPC - fdeInfo.pcStart, rememberStack, results);
+ upToPC - fdeInfo.pcStart, rememberStack, arch,
+ results);
}
/// "run" the DWARF instructions
@@ -364,7 +377,7 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions,
pint_t instructionsEnd,
const CIE_Info &cieInfo, pint_t pcoffset,
PrologInfoStackEntry *&rememberStack,
- PrologInfo *results) {
+ int arch, PrologInfo *results) {
pint_t p = instructions;
pint_t codeOffset = 0;
PrologInfo initialState = *results;
@@ -648,17 +661,6 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions,
"expression=0x%" PRIx64 ", length=%" PRIu64 ")\n",
reg, results->savedRegisters[reg].value, length);
break;
- case DW_CFA_GNU_window_save:
- // Hardcodes windowed registers for SPARC
- for (reg = 16; reg < 32; reg++) {
- if (reg == 31)
- results->savedRegisters[reg].location = kRegisterInCFADecrypt;
- else
- results->savedRegisters[reg].location = kRegisterInCFA;
- results->savedRegisters[reg].value = (reg - 16) * sizeof(pint_t);
- }
- _LIBUNWIND_TRACE_DWARF("DW_CFA_GNU_window_save");
- break;
case DW_CFA_GNU_args_size:
length = addressSpace.getULEB128(p, instructionsEnd);
results->spExtraArgSize = (uint32_t)length;
@@ -678,6 +680,57 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions,
_LIBUNWIND_TRACE_DWARF(
"DW_CFA_GNU_negative_offset_extended(%" PRId64 ")\n", offset);
break;
+
+#if defined(_LIBUNWIND_TARGET_AARCH64) || defined(_LIBUNWIND_TARGET_SPARC) \
+ || defined(_LIBUNWIND_TARGET_SPARC64)
+ // The same constant is used to represent different instructions on
+ // AArch64 (negate_ra_state) and SPARC (window_save).
+ static_assert(DW_CFA_AARCH64_negate_ra_state == DW_CFA_GNU_window_save,
+ "uses the same constant");
+ case DW_CFA_AARCH64_negate_ra_state:
+ switch (arch) {
+#if defined(_LIBUNWIND_TARGET_AARCH64)
+ case REGISTERS_ARM64:
+ results->savedRegisters[UNW_ARM64_RA_SIGN_STATE].value ^= 0x1;
+ _LIBUNWIND_TRACE_DWARF("DW_CFA_AARCH64_negate_ra_state\n");
+ break;
+#endif
+#if defined(_LIBUNWIND_TARGET_SPARC64)
+ case REGISTERS_SPARC64:
+ // Hardcodes windowed registers for SPARC
+ for (reg = 16; reg < 32; reg++) {
+ if (reg == 31)
+ results->savedRegisters[reg].location = kRegisterInCFADecrypt;
+ else
+ results->savedRegisters[reg].location = kRegisterInCFA;
+ results->savedRegisters[reg].value = (reg - 16) * sizeof(pint_t);
+ }
+ _LIBUNWIND_TRACE_DWARF("DW_CFA_GNU_window_save");
+ break;
+#endif
+#if defined(_LIBUNWIND_TARGET_SPARC)
+ // case DW_CFA_GNU_window_save:
+ case REGISTERS_SPARC:
+ _LIBUNWIND_TRACE_DWARF("DW_CFA_GNU_window_save()\n");
+ for (reg = UNW_SPARC_O0; reg <= UNW_SPARC_O7; reg++) {
+ results->savedRegisters[reg].location = kRegisterInRegister;
+ results->savedRegisters[reg].value =
+ ((int64_t)reg - UNW_SPARC_O0) + UNW_SPARC_I0;
+ }
+
+ for (reg = UNW_SPARC_L0; reg <= UNW_SPARC_I7; reg++) {
+ results->savedRegisters[reg].location = kRegisterInCFA;
+ results->savedRegisters[reg].value =
+ ((int64_t)reg - UNW_SPARC_L0) * 4;
+ }
+ break;
+#endif
+ }
+ break;
+#else
+ (void)arch;
+#endif
+
default:
operand = opcode & 0x3F;
switch (opcode & 0xC0) {
diff --git a/lib/libunwind/src/EHHeaderParser.hpp b/lib/libunwind/src/EHHeaderParser.hpp
index d6f4e1259a6..dc5cc04571a 100644
--- a/lib/libunwind/src/EHHeaderParser.hpp
+++ b/lib/libunwind/src/EHHeaderParser.hpp
@@ -36,7 +36,7 @@ public:
uint8_t table_enc;
};
- static void decodeEHHdr(A &addressSpace, pint_t ehHdrStart, pint_t ehHdrEnd,
+ static bool decodeEHHdr(A &addressSpace, pint_t ehHdrStart, pint_t ehHdrEnd,
EHHeaderInfo &ehHdrInfo);
static bool findFDE(A &addressSpace, pint_t pc, pint_t ehHdrStart,
uint32_t sectionLength,
@@ -53,12 +53,14 @@ private:
};
template <typename A>
-void EHHeaderParser<A>::decodeEHHdr(A &addressSpace, pint_t ehHdrStart,
+bool EHHeaderParser<A>::decodeEHHdr(A &addressSpace, pint_t ehHdrStart,
pint_t ehHdrEnd, EHHeaderInfo &ehHdrInfo) {
pint_t p = ehHdrStart;
uint8_t version = addressSpace.get8(p++);
- if (version != 1)
- _LIBUNWIND_ABORT("Unsupported .eh_frame_hdr version");
+ if (version != 1) {
+ _LIBUNWIND_LOG0("Unsupported .eh_frame_hdr version");
+ return false;
+ }
uint8_t eh_frame_ptr_enc = addressSpace.get8(p++);
uint8_t fde_count_enc = addressSpace.get8(p++);
@@ -71,6 +73,8 @@ void EHHeaderParser<A>::decodeEHHdr(A &addressSpace, pint_t ehHdrStart,
? 0
: addressSpace.getEncodedP(p, ehHdrEnd, fde_count_enc, ehHdrStart);
ehHdrInfo.table = p;
+
+ return true;
}
template <typename A>
@@ -102,7 +106,9 @@ bool EHHeaderParser<A>::findFDE(A &addressSpace, pint_t pc, pint_t ehHdrStart,
pint_t ehHdrEnd = ehHdrStart + sectionLength;
EHHeaderParser<A>::EHHeaderInfo hdrInfo;
- EHHeaderParser<A>::decodeEHHdr(addressSpace, ehHdrStart, ehHdrEnd, hdrInfo);
+ if (!EHHeaderParser<A>::decodeEHHdr(addressSpace, ehHdrStart, ehHdrEnd,
+ hdrInfo))
+ return false;
if (hdrInfo.fde_count == 0)
return false;
diff --git a/lib/libunwind/src/Registers.hpp b/lib/libunwind/src/Registers.hpp
index 5696357855d..9e69ca8e898 100644
--- a/lib/libunwind/src/Registers.hpp
+++ b/lib/libunwind/src/Registers.hpp
@@ -24,6 +24,19 @@ namespace libunwind {
// For emulating 128-bit registers
struct v128 { uint32_t vec[4]; };
+enum {
+ REGISTERS_X86,
+ REGISTERS_X86_64,
+ REGISTERS_PPC,
+ REGISTERS_PPC64,
+ REGISTERS_ARM64,
+ REGISTERS_ARM,
+ REGISTERS_OR1K,
+ REGISTERS_MIPS_O32,
+ REGISTERS_MIPS_NEWABI,
+ REGISTERS_SPARC,
+ REGISTERS_SPARC64,
+};
#if defined(_LIBUNWIND_TARGET_I386)
/// Registers_x86 holds the register state of a thread in a 32-bit intel
@@ -42,9 +55,10 @@ public:
bool validVectorRegister(int) const { return false; }
v128 getVectorRegister(int num) const;
void setVectorRegister(int num, v128 value);
- const char *getRegisterName(int num);
+ static const char *getRegisterName(int num);
void jumpto();
static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86; }
+ static int getArch() { return REGISTERS_X86; }
uint32_t getSP() const { return _registers.__esp; }
void setSP(uint32_t value) { _registers.__esp = value; }
@@ -249,9 +263,10 @@ public:
bool validVectorRegister(int) const;
v128 getVectorRegister(int num) const;
void setVectorRegister(int num, v128 value);
- const char *getRegisterName(int num);
+ static const char *getRegisterName(int num);
void jumpto();
static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86_64; }
+ static int getArch() { return REGISTERS_X86_64; }
uint64_t getSP() const { return _registers.__rsp; }
void setSP(uint64_t value) { _registers.__rsp = value; }
@@ -519,6 +534,7 @@ inline bool Registers_x86_64::validVectorRegister(int regNum) const {
return false;
return true;
#else
+ (void)regNum; // suppress unused parameter warning
return false;
#endif
}
@@ -528,6 +544,7 @@ inline v128 Registers_x86_64::getVectorRegister(int regNum) const {
assert(validVectorRegister(regNum));
return _xmm[regNum - UNW_X86_64_XMM0];
#else
+ (void)regNum; // suppress unused parameter warning
_LIBUNWIND_ABORT("no x86_64 vector registers");
#endif
}
@@ -537,6 +554,7 @@ inline void Registers_x86_64::setVectorRegister(int regNum, v128 value) {
assert(validVectorRegister(regNum));
_xmm[regNum - UNW_X86_64_XMM0] = value;
#else
+ (void)regNum; (void)value; // suppress unused parameter warnings
_LIBUNWIND_ABORT("no x86_64 vector registers");
#endif
}
@@ -560,9 +578,10 @@ public:
bool validVectorRegister(int num) const;
v128 getVectorRegister(int num) const;
void setVectorRegister(int num, v128 value);
- const char *getRegisterName(int num);
+ static const char *getRegisterName(int num);
void jumpto();
static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC; }
+ static int getArch() { return REGISTERS_PPC; }
uint64_t getSP() const { return _registers.__r1; }
void setSP(uint32_t value) { _registers.__r1 = value; }
@@ -1126,9 +1145,10 @@ public:
bool validVectorRegister(int num) const;
v128 getVectorRegister(int num) const;
void setVectorRegister(int num, v128 value);
- const char *getRegisterName(int num);
+ static const char *getRegisterName(int num);
void jumpto();
static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC64; }
+ static int getArch() { return REGISTERS_PPC64; }
uint64_t getSP() const { return _registers.__r1; }
void setSP(uint64_t value) { _registers.__r1 = value; }
@@ -1768,9 +1788,10 @@ public:
bool validVectorRegister(int num) const;
v128 getVectorRegister(int num) const;
void setVectorRegister(int num, v128 value);
- const char *getRegisterName(int num);
+ static const char *getRegisterName(int num);
void jumpto();
static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64; }
+ static int getArch() { return REGISTERS_ARM64; }
uint64_t getSP() const { return _registers.__sp; }
void setSP(uint64_t value) { _registers.__sp = value; }
@@ -1787,7 +1808,7 @@ private:
uint64_t __lr; // Link register x30
uint64_t __sp; // Stack pointer x31
uint64_t __pc; // Program counter
- uint64_t padding; // 16-byte align
+ uint64_t __ra_sign_state; // RA sign state register
};
GPRs _registers;
@@ -1823,6 +1844,8 @@ inline bool Registers_arm64::validRegister(int regNum) const {
return false;
if (regNum > 95)
return false;
+ if (regNum == UNW_ARM64_RA_SIGN_STATE)
+ return true;
if ((regNum > 31) && (regNum < 64))
return false;
return true;
@@ -1833,6 +1856,8 @@ inline uint64_t Registers_arm64::getRegister(int regNum) const {
return _registers.__pc;
if (regNum == UNW_REG_SP)
return _registers.__sp;
+ if (regNum == UNW_ARM64_RA_SIGN_STATE)
+ return _registers.__ra_sign_state;
if ((regNum >= 0) && (regNum < 32))
return _registers.__x[regNum];
_LIBUNWIND_ABORT("unsupported arm64 register");
@@ -1843,6 +1868,8 @@ inline void Registers_arm64::setRegister(int regNum, uint64_t value) {
_registers.__pc = value;
else if (regNum == UNW_REG_SP)
_registers.__sp = value;
+ else if (regNum == UNW_ARM64_RA_SIGN_STATE)
+ _registers.__ra_sign_state = value;
else if ((regNum >= 0) && (regNum < 32))
_registers.__x[regNum] = value;
else
@@ -2039,12 +2066,13 @@ public:
bool validVectorRegister(int num) const;
v128 getVectorRegister(int num) const;
void setVectorRegister(int num, v128 value);
- const char *getRegisterName(int num);
+ static const char *getRegisterName(int num);
void jumpto() {
restoreSavedFloatRegisters();
restoreCoreAndJumpTo();
}
static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM; }
+ static int getArch() { return REGISTERS_ARM; }
uint32_t getSP() const { return _registers.__sp; }
void setSP(uint32_t value) { _registers.__sp = value; }
@@ -2154,7 +2182,7 @@ inline Registers_arm::Registers_arm()
memset(&_vfp_d16_d31, 0, sizeof(_vfp_d16_d31));
#if defined(__ARM_WMMX)
_saved_iwmmx = false;
- _saved_iwmmx_control = false;
+ _saved_iwmmx_control = false;
memset(&_iwmmx, 0, sizeof(_iwmmx));
memset(&_iwmmx_control, 0, sizeof(_iwmmx_control));
#endif
@@ -2520,9 +2548,10 @@ public:
bool validVectorRegister(int num) const;
v128 getVectorRegister(int num) const;
void setVectorRegister(int num, v128 value);
- const char *getRegisterName(int num);
+ static const char *getRegisterName(int num);
void jumpto();
static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_OR1K; }
+ static int getArch() { return REGISTERS_OR1K; }
uint64_t getSP() const { return _registers.__r[1]; }
void setSP(uint32_t value) { _registers.__r[1] = value; }
@@ -2720,6 +2749,7 @@ public:
const char *getRegisterName(int num);
void jumpto();
static int lastDwarfRegNum() { return 31; }
+ static int getArch() { return REGISTERS_SPARC64; }
uint64_t getSP() const { return _registers.__o[6] + 2047; }
void setSP(uint64_t value) { _registers.__o[6] = value - 2047; }
@@ -2860,9 +2890,10 @@ public:
bool validVectorRegister(int num) const;
v128 getVectorRegister(int num) const;
void setVectorRegister(int num, v128 value);
- const char *getRegisterName(int num);
+ static const char *getRegisterName(int num);
void jumpto();
static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_MIPS; }
+ static int getArch() { return REGISTERS_MIPS_O32; }
uint32_t getSP() const { return _registers.__r[29]; }
void setSP(uint32_t value) { _registers.__r[29] = value; }
@@ -2909,10 +2940,12 @@ inline bool Registers_mips_o32::validRegister(int regNum) const {
return false;
if (regNum <= UNW_MIPS_R31)
return true;
+#if __mips_isa_rev != 6
if (regNum == UNW_MIPS_HI)
return true;
if (regNum == UNW_MIPS_LO)
return true;
+#endif
#if defined(__mips_hard_float) && __mips_fpr == 32
if (regNum >= UNW_MIPS_F0 && regNum <= UNW_MIPS_F31)
return true;
@@ -3180,9 +3213,10 @@ public:
bool validVectorRegister(int num) const;
v128 getVectorRegister(int num) const;
void setVectorRegister(int num, v128 value);
- const char *getRegisterName(int num);
+ static const char *getRegisterName(int num);
void jumpto();
static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_MIPS; }
+ static int getArch() { return REGISTERS_MIPS_NEWABI; }
uint64_t getSP() const { return _registers.__r[29]; }
void setSP(uint64_t value) { _registers.__r[29] = value; }
@@ -3224,10 +3258,12 @@ inline bool Registers_mips_newabi::validRegister(int regNum) const {
return false;
if (regNum <= UNW_MIPS_R31)
return true;
+#if __mips_isa_rev != 6
if (regNum == UNW_MIPS_HI)
return true;
if (regNum == UNW_MIPS_LO)
return true;
+#endif
// FIXME: Hard float, DSP accumulator registers, MSA registers
return false;
}
@@ -3450,6 +3486,191 @@ inline const char *Registers_mips_newabi::getRegisterName(int regNum) {
}
}
#endif // _LIBUNWIND_TARGET_MIPS_NEWABI
+
+#if defined(_LIBUNWIND_TARGET_SPARC)
+/// Registers_sparc holds the register state of a thread in a 32-bit Sparc
+/// process.
+class _LIBUNWIND_HIDDEN Registers_sparc {
+public:
+ Registers_sparc();
+ Registers_sparc(const void *registers);
+
+ bool validRegister(int num) const;
+ uint32_t getRegister(int num) const;
+ void setRegister(int num, uint32_t value);
+ bool validFloatRegister(int num) const;
+ double getFloatRegister(int num) const;
+ void setFloatRegister(int num, double value);
+ bool validVectorRegister(int num) const;
+ v128 getVectorRegister(int num) const;
+ void setVectorRegister(int num, v128 value);
+ static const char *getRegisterName(int num);
+ void jumpto();
+ static int lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC; }
+ static int getArch() { return REGISTERS_SPARC; }
+
+ uint64_t getSP() const { return _registers.__regs[UNW_SPARC_O6]; }
+ void setSP(uint32_t value) { _registers.__regs[UNW_SPARC_O6] = value; }
+ uint64_t getIP() const { return _registers.__regs[UNW_SPARC_O7]; }
+ void setIP(uint32_t value) { _registers.__regs[UNW_SPARC_O7] = value; }
+
+private:
+ struct sparc_thread_state_t {
+ unsigned int __regs[32];
+ };
+
+ sparc_thread_state_t _registers;
+};
+
+inline Registers_sparc::Registers_sparc(const void *registers) {
+ static_assert((check_fit<Registers_sparc, unw_context_t>::does_fit),
+ "sparc registers do not fit into unw_context_t");
+ memcpy(&_registers, static_cast<const uint8_t *>(registers),
+ sizeof(_registers));
+}
+
+inline Registers_sparc::Registers_sparc() {
+ memset(&_registers, 0, sizeof(_registers));
+}
+
+inline bool Registers_sparc::validRegister(int regNum) const {
+ if (regNum == UNW_REG_IP)
+ return true;
+ if (regNum == UNW_REG_SP)
+ return true;
+ if (regNum < 0)
+ return false;
+ if (regNum <= UNW_SPARC_I7)
+ return true;
+ return false;
+}
+
+inline uint32_t Registers_sparc::getRegister(int regNum) const {
+ if ((UNW_SPARC_G0 <= regNum) && (regNum <= UNW_SPARC_I7)) {
+ return _registers.__regs[regNum];
+ }
+
+ switch (regNum) {
+ case UNW_REG_IP:
+ return _registers.__regs[UNW_SPARC_O7];
+ case UNW_REG_SP:
+ return _registers.__regs[UNW_SPARC_O6];
+ }
+ _LIBUNWIND_ABORT("unsupported sparc register");
+}
+
+inline void Registers_sparc::setRegister(int regNum, uint32_t value) {
+ if ((UNW_SPARC_G0 <= regNum) && (regNum <= UNW_SPARC_I7)) {
+ _registers.__regs[regNum] = value;
+ return;
+ }
+
+ switch (regNum) {
+ case UNW_REG_IP:
+ _registers.__regs[UNW_SPARC_O7] = value;
+ return;
+ case UNW_REG_SP:
+ _registers.__regs[UNW_SPARC_O6] = value;
+ return;
+ }
+ _LIBUNWIND_ABORT("unsupported sparc register");
+}
+
+inline bool Registers_sparc::validFloatRegister(int) const { return false; }
+
+inline double Registers_sparc::getFloatRegister(int) const {
+ _LIBUNWIND_ABORT("no Sparc float registers");
+}
+
+inline void Registers_sparc::setFloatRegister(int, double) {
+ _LIBUNWIND_ABORT("no Sparc float registers");
+}
+
+inline bool Registers_sparc::validVectorRegister(int) const { return false; }
+
+inline v128 Registers_sparc::getVectorRegister(int) const {
+ _LIBUNWIND_ABORT("no Sparc vector registers");
+}
+
+inline void Registers_sparc::setVectorRegister(int, v128) {
+ _LIBUNWIND_ABORT("no Sparc vector registers");
+}
+
+inline const char *Registers_sparc::getRegisterName(int regNum) {
+ switch (regNum) {
+ case UNW_REG_IP:
+ return "pc";
+ case UNW_SPARC_G0:
+ return "g0";
+ case UNW_SPARC_G1:
+ return "g1";
+ case UNW_SPARC_G2:
+ return "g2";
+ case UNW_SPARC_G3:
+ return "g3";
+ case UNW_SPARC_G4:
+ return "g4";
+ case UNW_SPARC_G5:
+ return "g5";
+ case UNW_SPARC_G6:
+ return "g6";
+ case UNW_SPARC_G7:
+ return "g7";
+ case UNW_SPARC_O0:
+ return "o0";
+ case UNW_SPARC_O1:
+ return "o1";
+ case UNW_SPARC_O2:
+ return "o2";
+ case UNW_SPARC_O3:
+ return "o3";
+ case UNW_SPARC_O4:
+ return "o4";
+ case UNW_SPARC_O5:
+ return "o5";
+ case UNW_REG_SP:
+ case UNW_SPARC_O6:
+ return "sp";
+ case UNW_SPARC_O7:
+ return "o7";
+ case UNW_SPARC_L0:
+ return "l0";
+ case UNW_SPARC_L1:
+ return "l1";
+ case UNW_SPARC_L2:
+ return "l2";
+ case UNW_SPARC_L3:
+ return "l3";
+ case UNW_SPARC_L4:
+ return "l4";
+ case UNW_SPARC_L5:
+ return "l5";
+ case UNW_SPARC_L6:
+ return "l6";
+ case UNW_SPARC_L7:
+ return "l7";
+ case UNW_SPARC_I0:
+ return "i0";
+ case UNW_SPARC_I1:
+ return "i1";
+ case UNW_SPARC_I2:
+ return "i2";
+ case UNW_SPARC_I3:
+ return "i3";
+ case UNW_SPARC_I4:
+ return "i4";
+ case UNW_SPARC_I5:
+ return "i5";
+ case UNW_SPARC_I6:
+ return "fp";
+ case UNW_SPARC_I7:
+ return "i7";
+ default:
+ return "unknown register";
+ }
+}
+#endif // _LIBUNWIND_TARGET_SPARC
+
} // namespace libunwind
#endif // __REGISTERS_HPP__
diff --git a/lib/libunwind/src/UnwindCursor.hpp b/lib/libunwind/src/UnwindCursor.hpp
index cc75bdd796c..4fbd31b079d 100644
--- a/lib/libunwind/src/UnwindCursor.hpp
+++ b/lib/libunwind/src/UnwindCursor.hpp
@@ -18,10 +18,51 @@
#include <stdlib.h>
#include <unwind.h>
+#ifdef _WIN32
+ #include <windows.h>
+ #include <ntverp.h>
+#endif
#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif
+#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
+// Provide a definition for the DISPATCHER_CONTEXT struct for old (Win7 and
+// earlier) SDKs.
+// MinGW-w64 has always provided this struct.
+ #if defined(_WIN32) && defined(_LIBUNWIND_TARGET_X86_64) && \
+ !defined(__MINGW32__) && VER_PRODUCTBUILD < 8000
+struct _DISPATCHER_CONTEXT {
+ ULONG64 ControlPc;
+ ULONG64 ImageBase;
+ PRUNTIME_FUNCTION FunctionEntry;
+ ULONG64 EstablisherFrame;
+ ULONG64 TargetIp;
+ PCONTEXT ContextRecord;
+ PEXCEPTION_ROUTINE LanguageHandler;
+ PVOID HandlerData;
+ PUNWIND_HISTORY_TABLE HistoryTable;
+ ULONG ScopeIndex;
+ ULONG Fill0;
+};
+ #endif
+
+struct UNWIND_INFO {
+ uint8_t Version : 3;
+ uint8_t Flags : 5;
+ uint8_t SizeOfProlog;
+ uint8_t CountOfCodes;
+ uint8_t FrameRegister : 4;
+ uint8_t FrameOffset : 4;
+ uint16_t UnwindCodes[2];
+};
+
+extern "C" _Unwind_Reason_Code __libunwind_seh_personality(
+ int, _Unwind_Action, uint64_t, _Unwind_Exception *,
+ struct _Unwind_Context *);
+
+#endif
+
#include "config.h"
#include "AddressSpace.hpp"
@@ -414,6 +455,419 @@ public:
#endif
};
+#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
+
+/// \c UnwindCursor contains all state (including all register values) during
+/// an unwind. This is normally stack-allocated inside a unw_cursor_t.
+template <typename A, typename R>
+class UnwindCursor : public AbstractUnwindCursor {
+ typedef typename A::pint_t pint_t;
+public:
+ UnwindCursor(unw_context_t *context, A &as);
+ UnwindCursor(CONTEXT *context, A &as);
+ UnwindCursor(A &as, void *threadArg);
+ virtual ~UnwindCursor() {}
+ virtual bool validReg(int);
+ virtual unw_word_t getReg(int);
+ virtual void setReg(int, unw_word_t);
+ virtual bool validFloatReg(int);
+ virtual unw_fpreg_t getFloatReg(int);
+ virtual void setFloatReg(int, unw_fpreg_t);
+ virtual int step();
+ virtual void getInfo(unw_proc_info_t *);
+ virtual void jumpto();
+ virtual bool isSignalFrame();
+ virtual bool getFunctionName(char *buf, size_t len, unw_word_t *off);
+ virtual void setInfoBasedOnIPRegister(bool isReturnAddress = false);
+ virtual const char *getRegisterName(int num);
+#ifdef __arm__
+ virtual void saveVFPAsX();
+#endif
+
+ DISPATCHER_CONTEXT *getDispatcherContext() { return &_dispContext; }
+ void setDispatcherContext(DISPATCHER_CONTEXT *disp) { _dispContext = *disp; }
+
+private:
+
+ pint_t getLastPC() const { return _dispContext.ControlPc; }
+ void setLastPC(pint_t pc) { _dispContext.ControlPc = pc; }
+ RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) {
+ _dispContext.FunctionEntry = RtlLookupFunctionEntry(pc,
+ &_dispContext.ImageBase,
+ _dispContext.HistoryTable);
+ *base = _dispContext.ImageBase;
+ return _dispContext.FunctionEntry;
+ }
+ bool getInfoFromSEH(pint_t pc);
+ int stepWithSEHData() {
+ _dispContext.LanguageHandler = RtlVirtualUnwind(UNW_FLAG_UHANDLER,
+ _dispContext.ImageBase,
+ _dispContext.ControlPc,
+ _dispContext.FunctionEntry,
+ _dispContext.ContextRecord,
+ &_dispContext.HandlerData,
+ &_dispContext.EstablisherFrame,
+ NULL);
+ // Update some fields of the unwind info now, since we have them.
+ _info.lsda = reinterpret_cast<unw_word_t>(_dispContext.HandlerData);
+ if (_dispContext.LanguageHandler) {
+ _info.handler = reinterpret_cast<unw_word_t>(__libunwind_seh_personality);
+ } else
+ _info.handler = 0;
+ return UNW_STEP_SUCCESS;
+ }
+
+ A &_addressSpace;
+ unw_proc_info_t _info;
+ DISPATCHER_CONTEXT _dispContext;
+ CONTEXT _msContext;
+ UNWIND_HISTORY_TABLE _histTable;
+ bool _unwindInfoMissing;
+};
+
+
+template <typename A, typename R>
+UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
+ : _addressSpace(as), _unwindInfoMissing(false) {
+ static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
+ "UnwindCursor<> does not fit in unw_cursor_t");
+ memset(&_info, 0, sizeof(_info));
+ memset(&_histTable, 0, sizeof(_histTable));
+ _dispContext.ContextRecord = &_msContext;
+ _dispContext.HistoryTable = &_histTable;
+ // Initialize MS context from ours.
+ R r(context);
+ _msContext.ContextFlags = CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_FLOATING_POINT;
+#if defined(_LIBUNWIND_TARGET_X86_64)
+ _msContext.Rax = r.getRegister(UNW_X86_64_RAX);
+ _msContext.Rcx = r.getRegister(UNW_X86_64_RCX);
+ _msContext.Rdx = r.getRegister(UNW_X86_64_RDX);
+ _msContext.Rbx = r.getRegister(UNW_X86_64_RBX);
+ _msContext.Rsp = r.getRegister(UNW_X86_64_RSP);
+ _msContext.Rbp = r.getRegister(UNW_X86_64_RBP);
+ _msContext.Rsi = r.getRegister(UNW_X86_64_RSI);
+ _msContext.Rdi = r.getRegister(UNW_X86_64_RDI);
+ _msContext.R8 = r.getRegister(UNW_X86_64_R8);
+ _msContext.R9 = r.getRegister(UNW_X86_64_R9);
+ _msContext.R10 = r.getRegister(UNW_X86_64_R10);
+ _msContext.R11 = r.getRegister(UNW_X86_64_R11);
+ _msContext.R12 = r.getRegister(UNW_X86_64_R12);
+ _msContext.R13 = r.getRegister(UNW_X86_64_R13);
+ _msContext.R14 = r.getRegister(UNW_X86_64_R14);
+ _msContext.R15 = r.getRegister(UNW_X86_64_R15);
+ _msContext.Rip = r.getRegister(UNW_REG_IP);
+ union {
+ v128 v;
+ M128A m;
+ } t;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM0);
+ _msContext.Xmm0 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM1);
+ _msContext.Xmm1 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM2);
+ _msContext.Xmm2 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM3);
+ _msContext.Xmm3 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM4);
+ _msContext.Xmm4 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM5);
+ _msContext.Xmm5 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM6);
+ _msContext.Xmm6 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM7);
+ _msContext.Xmm7 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM8);
+ _msContext.Xmm8 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM9);
+ _msContext.Xmm9 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM10);
+ _msContext.Xmm10 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM11);
+ _msContext.Xmm11 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM12);
+ _msContext.Xmm12 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM13);
+ _msContext.Xmm13 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM14);
+ _msContext.Xmm14 = t.m;
+ t.v = r.getVectorRegister(UNW_X86_64_XMM15);
+ _msContext.Xmm15 = t.m;
+#elif defined(_LIBUNWIND_TARGET_ARM)
+ _msContext.R0 = r.getRegister(UNW_ARM_R0);
+ _msContext.R1 = r.getRegister(UNW_ARM_R1);
+ _msContext.R2 = r.getRegister(UNW_ARM_R2);
+ _msContext.R3 = r.getRegister(UNW_ARM_R3);
+ _msContext.R4 = r.getRegister(UNW_ARM_R4);
+ _msContext.R5 = r.getRegister(UNW_ARM_R5);
+ _msContext.R6 = r.getRegister(UNW_ARM_R6);
+ _msContext.R7 = r.getRegister(UNW_ARM_R7);
+ _msContext.R8 = r.getRegister(UNW_ARM_R8);
+ _msContext.R9 = r.getRegister(UNW_ARM_R9);
+ _msContext.R10 = r.getRegister(UNW_ARM_R10);
+ _msContext.R11 = r.getRegister(UNW_ARM_R11);
+ _msContext.R12 = r.getRegister(UNW_ARM_R12);
+ _msContext.Sp = r.getRegister(UNW_ARM_SP);
+ _msContext.Lr = r.getRegister(UNW_ARM_LR);
+ _msContext.Pc = r.getRegister(UNW_ARM_IP);
+ for (int i = UNW_ARM_D0; i <= UNW_ARM_D31; ++i) {
+ union {
+ uint64_t w;
+ double d;
+ } d;
+ d.d = r.getFloatRegister(i);
+ _msContext.D[i - UNW_ARM_D0] = d.w;
+ }
+#elif defined(_LIBUNWIND_TARGET_AARCH64)
+ for (int i = UNW_ARM64_X0; i <= UNW_ARM64_X30; ++i)
+ _msContext.X[i - UNW_ARM64_X0] = r.getRegister(i);
+ _msContext.Sp = r.getRegister(UNW_REG_SP);
+ _msContext.Pc = r.getRegister(UNW_REG_IP);
+ for (int i = UNW_ARM64_D0; i <= UNW_ARM64_D31; ++i)
+ _msContext.V[i - UNW_ARM64_D0].D[0] = r.getFloatRegister(i);
+#endif
+}
+
+template <typename A, typename R>
+UnwindCursor<A, R>::UnwindCursor(CONTEXT *context, A &as)
+ : _addressSpace(as), _unwindInfoMissing(false) {
+ static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
+ "UnwindCursor<> does not fit in unw_cursor_t");
+ memset(&_info, 0, sizeof(_info));
+ memset(&_histTable, 0, sizeof(_histTable));
+ _dispContext.ContextRecord = &_msContext;
+ _dispContext.HistoryTable = &_histTable;
+ _msContext = *context;
+}
+
+
+template <typename A, typename R>
+bool UnwindCursor<A, R>::validReg(int regNum) {
+ if (regNum == UNW_REG_IP || regNum == UNW_REG_SP) return true;
+#if defined(_LIBUNWIND_TARGET_X86_64)
+ if (regNum >= UNW_X86_64_RAX && regNum <= UNW_X86_64_R15) return true;
+#elif defined(_LIBUNWIND_TARGET_ARM)
+ if (regNum >= UNW_ARM_R0 && regNum <= UNW_ARM_R15) return true;
+#elif defined(_LIBUNWIND_TARGET_AARCH64)
+ if (regNum >= UNW_ARM64_X0 && regNum <= UNW_ARM64_X30) return true;
+#endif
+ return false;
+}
+
+template <typename A, typename R>
+unw_word_t UnwindCursor<A, R>::getReg(int regNum) {
+ switch (regNum) {
+#if defined(_LIBUNWIND_TARGET_X86_64)
+ case UNW_REG_IP: return _msContext.Rip;
+ case UNW_X86_64_RAX: return _msContext.Rax;
+ case UNW_X86_64_RDX: return _msContext.Rdx;
+ case UNW_X86_64_RCX: return _msContext.Rcx;
+ case UNW_X86_64_RBX: return _msContext.Rbx;
+ case UNW_REG_SP:
+ case UNW_X86_64_RSP: return _msContext.Rsp;
+ case UNW_X86_64_RBP: return _msContext.Rbp;
+ case UNW_X86_64_RSI: return _msContext.Rsi;
+ case UNW_X86_64_RDI: return _msContext.Rdi;
+ case UNW_X86_64_R8: return _msContext.R8;
+ case UNW_X86_64_R9: return _msContext.R9;
+ case UNW_X86_64_R10: return _msContext.R10;
+ case UNW_X86_64_R11: return _msContext.R11;
+ case UNW_X86_64_R12: return _msContext.R12;
+ case UNW_X86_64_R13: return _msContext.R13;
+ case UNW_X86_64_R14: return _msContext.R14;
+ case UNW_X86_64_R15: return _msContext.R15;
+#elif defined(_LIBUNWIND_TARGET_ARM)
+ case UNW_ARM_R0: return _msContext.R0;
+ case UNW_ARM_R1: return _msContext.R1;
+ case UNW_ARM_R2: return _msContext.R2;
+ case UNW_ARM_R3: return _msContext.R3;
+ case UNW_ARM_R4: return _msContext.R4;
+ case UNW_ARM_R5: return _msContext.R5;
+ case UNW_ARM_R6: return _msContext.R6;
+ case UNW_ARM_R7: return _msContext.R7;
+ case UNW_ARM_R8: return _msContext.R8;
+ case UNW_ARM_R9: return _msContext.R9;
+ case UNW_ARM_R10: return _msContext.R10;
+ case UNW_ARM_R11: return _msContext.R11;
+ case UNW_ARM_R12: return _msContext.R12;
+ case UNW_REG_SP:
+ case UNW_ARM_SP: return _msContext.Sp;
+ case UNW_ARM_LR: return _msContext.Lr;
+ case UNW_REG_IP:
+ case UNW_ARM_IP: return _msContext.Pc;
+#elif defined(_LIBUNWIND_TARGET_AARCH64)
+ case UNW_REG_SP: return _msContext.Sp;
+ case UNW_REG_IP: return _msContext.Pc;
+ default: return _msContext.X[regNum - UNW_ARM64_X0];
+#endif
+ }
+ _LIBUNWIND_ABORT("unsupported register");
+}
+
+template <typename A, typename R>
+void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {
+ switch (regNum) {
+#if defined(_LIBUNWIND_TARGET_X86_64)
+ case UNW_REG_IP: _msContext.Rip = value; break;
+ case UNW_X86_64_RAX: _msContext.Rax = value; break;
+ case UNW_X86_64_RDX: _msContext.Rdx = value; break;
+ case UNW_X86_64_RCX: _msContext.Rcx = value; break;
+ case UNW_X86_64_RBX: _msContext.Rbx = value; break;
+ case UNW_REG_SP:
+ case UNW_X86_64_RSP: _msContext.Rsp = value; break;
+ case UNW_X86_64_RBP: _msContext.Rbp = value; break;
+ case UNW_X86_64_RSI: _msContext.Rsi = value; break;
+ case UNW_X86_64_RDI: _msContext.Rdi = value; break;
+ case UNW_X86_64_R8: _msContext.R8 = value; break;
+ case UNW_X86_64_R9: _msContext.R9 = value; break;
+ case UNW_X86_64_R10: _msContext.R10 = value; break;
+ case UNW_X86_64_R11: _msContext.R11 = value; break;
+ case UNW_X86_64_R12: _msContext.R12 = value; break;
+ case UNW_X86_64_R13: _msContext.R13 = value; break;
+ case UNW_X86_64_R14: _msContext.R14 = value; break;
+ case UNW_X86_64_R15: _msContext.R15 = value; break;
+#elif defined(_LIBUNWIND_TARGET_ARM)
+ case UNW_ARM_R0: _msContext.R0 = value; break;
+ case UNW_ARM_R1: _msContext.R1 = value; break;
+ case UNW_ARM_R2: _msContext.R2 = value; break;
+ case UNW_ARM_R3: _msContext.R3 = value; break;
+ case UNW_ARM_R4: _msContext.R4 = value; break;
+ case UNW_ARM_R5: _msContext.R5 = value; break;
+ case UNW_ARM_R6: _msContext.R6 = value; break;
+ case UNW_ARM_R7: _msContext.R7 = value; break;
+ case UNW_ARM_R8: _msContext.R8 = value; break;
+ case UNW_ARM_R9: _msContext.R9 = value; break;
+ case UNW_ARM_R10: _msContext.R10 = value; break;
+ case UNW_ARM_R11: _msContext.R11 = value; break;
+ case UNW_ARM_R12: _msContext.R12 = value; break;
+ case UNW_REG_SP:
+ case UNW_ARM_SP: _msContext.Sp = value; break;
+ case UNW_ARM_LR: _msContext.Lr = value; break;
+ case UNW_REG_IP:
+ case UNW_ARM_IP: _msContext.Pc = value; break;
+#elif defined(_LIBUNWIND_TARGET_AARCH64)
+ case UNW_REG_SP: _msContext.Sp = value; break;
+ case UNW_REG_IP: _msContext.Pc = value; break;
+ case UNW_ARM64_X0:
+ case UNW_ARM64_X1:
+ case UNW_ARM64_X2:
+ case UNW_ARM64_X3:
+ case UNW_ARM64_X4:
+ case UNW_ARM64_X5:
+ case UNW_ARM64_X6:
+ case UNW_ARM64_X7:
+ case UNW_ARM64_X8:
+ case UNW_ARM64_X9:
+ case UNW_ARM64_X10:
+ case UNW_ARM64_X11:
+ case UNW_ARM64_X12:
+ case UNW_ARM64_X13:
+ case UNW_ARM64_X14:
+ case UNW_ARM64_X15:
+ case UNW_ARM64_X16:
+ case UNW_ARM64_X17:
+ case UNW_ARM64_X18:
+ case UNW_ARM64_X19:
+ case UNW_ARM64_X20:
+ case UNW_ARM64_X21:
+ case UNW_ARM64_X22:
+ case UNW_ARM64_X23:
+ case UNW_ARM64_X24:
+ case UNW_ARM64_X25:
+ case UNW_ARM64_X26:
+ case UNW_ARM64_X27:
+ case UNW_ARM64_X28:
+ case UNW_ARM64_FP:
+ case UNW_ARM64_LR: _msContext.X[regNum - UNW_ARM64_X0] = value; break;
+#endif
+ default:
+ _LIBUNWIND_ABORT("unsupported register");
+ }
+}
+
+template <typename A, typename R>
+bool UnwindCursor<A, R>::validFloatReg(int regNum) {
+#if defined(_LIBUNWIND_TARGET_ARM)
+ if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) return true;
+ if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) return true;
+#elif defined(_LIBUNWIND_TARGET_AARCH64)
+ if (regNum >= UNW_ARM64_D0 && regNum <= UNW_ARM64_D31) return true;
+#endif
+ return false;
+}
+
+template <typename A, typename R>
+unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {
+#if defined(_LIBUNWIND_TARGET_ARM)
+ if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) {
+ union {
+ uint32_t w;
+ float f;
+ } d;
+ d.w = _msContext.S[regNum - UNW_ARM_S0];
+ return d.f;
+ }
+ if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) {
+ union {
+ uint64_t w;
+ double d;
+ } d;
+ d.w = _msContext.D[regNum - UNW_ARM_D0];
+ return d.d;
+ }
+ _LIBUNWIND_ABORT("unsupported float register");
+#elif defined(_LIBUNWIND_TARGET_AARCH64)
+ return _msContext.V[regNum - UNW_ARM64_D0].D[0];
+#else
+ _LIBUNWIND_ABORT("float registers unimplemented");
+#endif
+}
+
+template <typename A, typename R>
+void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {
+#if defined(_LIBUNWIND_TARGET_ARM)
+ if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) {
+ union {
+ uint32_t w;
+ float f;
+ } d;
+ d.f = value;
+ _msContext.S[regNum - UNW_ARM_S0] = d.w;
+ }
+ if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) {
+ union {
+ uint64_t w;
+ double d;
+ } d;
+ d.d = value;
+ _msContext.D[regNum - UNW_ARM_D0] = d.w;
+ }
+ _LIBUNWIND_ABORT("unsupported float register");
+#elif defined(_LIBUNWIND_TARGET_AARCH64)
+ _msContext.V[regNum - UNW_ARM64_D0].D[0] = value;
+#else
+ _LIBUNWIND_ABORT("float registers unimplemented");
+#endif
+}
+
+template <typename A, typename R> void UnwindCursor<A, R>::jumpto() {
+ RtlRestoreContext(&_msContext, nullptr);
+}
+
+#ifdef __arm__
+template <typename A, typename R> void UnwindCursor<A, R>::saveVFPAsX() {}
+#endif
+
+template <typename A, typename R>
+const char *UnwindCursor<A, R>::getRegisterName(int regNum) {
+ return R::getRegisterName(regNum);
+}
+
+template <typename A, typename R> bool UnwindCursor<A, R>::isSignalFrame() {
+ return false;
+}
+
+#else // !defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) || !defined(_WIN32)
+
/// UnwindCursor contains all state (including all register values) during
/// an unwind. This is normally stack allocated inside a unw_cursor_t.
template <typename A, typename R>
@@ -529,6 +983,10 @@ private:
}
#endif
+#if defined(_LIBUNWIND_TARGET_SPARC)
+ int stepWithCompactEncoding(Registers_sparc &) { return UNW_EINVAL; }
+#endif
+
bool compactSaysUseDwarf(uint32_t *offset=NULL) const {
R dummy;
return compactSaysUseDwarf(dummy, offset);
@@ -590,6 +1048,11 @@ private:
return true;
}
#endif
+
+#if defined(_LIBUNWIND_TARGET_SPARC)
+ bool compactSaysUseDwarf(Registers_sparc &, uint32_t *) const { return true; }
+#endif
+
#endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
@@ -652,13 +1115,32 @@ private:
}
#endif
+#if defined(_LIBUNWIND_TARGET_SPARC)
+ compact_unwind_encoding_t dwarfEncoding(Registers_sparc &) const { return 0; }
+#endif
+
#if defined (_LIBUNWIND_TARGET_SPARC64)
compact_unwind_encoding_t dwarfEncoding(Registers_sparc64 &) const {
return 0;
}
#endif
+
#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
+#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
+ // For runtime environments using SEH unwind data without Windows runtime
+ // support.
+ pint_t getLastPC() const { /* FIXME: Implement */ return 0; }
+ void setLastPC(pint_t pc) { /* FIXME: Implement */ }
+ RUNTIME_FUNCTION *lookUpSEHUnwindInfo(pint_t pc, pint_t *base) {
+ /* FIXME: Implement */
+ *base = 0;
+ return nullptr;
+ }
+ bool getInfoFromSEH(pint_t pc);
+ int stepWithSEHData() { /* FIXME: Implement */ return 0; }
+#endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
+
A &_addressSpace;
R _registers;
@@ -735,6 +1217,8 @@ template <typename A, typename R> bool UnwindCursor<A, R>::isSignalFrame() {
return _isSignalFrame;
}
+#endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
+
#if defined(_LIBUNWIND_ARM_EHABI)
struct EHABIIndexEntry {
uint32_t functionOffset;
@@ -981,7 +1465,7 @@ bool UnwindCursor<A, R>::getInfoFromDwarfSection(pint_t pc,
if (foundFDE) {
typename CFI_Parser<A>::PrologInfo prolog;
if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo, pc,
- &prolog)) {
+ R::getArch(), &prolog)) {
// Save off parsed FDE info
_info.start_ip = fdeInfo.pcStart;
_info.end_ip = fdeInfo.pcEnd;
@@ -1269,6 +1753,55 @@ bool UnwindCursor<A, R>::getInfoFromCompactEncodingSection(pint_t pc,
#endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
+#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
+template <typename A, typename R>
+bool UnwindCursor<A, R>::getInfoFromSEH(pint_t pc) {
+ pint_t base;
+ RUNTIME_FUNCTION *unwindEntry = lookUpSEHUnwindInfo(pc, &base);
+ if (!unwindEntry) {
+ _LIBUNWIND_DEBUG_LOG("\tpc not in table, pc=0x%llX", (uint64_t) pc);
+ return false;
+ }
+ _info.gp = 0;
+ _info.flags = 0;
+ _info.format = 0;
+ _info.unwind_info_size = sizeof(RUNTIME_FUNCTION);
+ _info.unwind_info = reinterpret_cast<unw_word_t>(unwindEntry);
+ _info.extra = base;
+ _info.start_ip = base + unwindEntry->BeginAddress;
+#ifdef _LIBUNWIND_TARGET_X86_64
+ _info.end_ip = base + unwindEntry->EndAddress;
+ // Only fill in the handler and LSDA if they're stale.
+ if (pc != getLastPC()) {
+ UNWIND_INFO *xdata = reinterpret_cast<UNWIND_INFO *>(base + unwindEntry->UnwindData);
+ if (xdata->Flags & (UNW_FLAG_EHANDLER|UNW_FLAG_UHANDLER)) {
+ // The personality is given in the UNWIND_INFO itself. The LSDA immediately
+ // follows the UNWIND_INFO. (This follows how both Clang and MSVC emit
+ // these structures.)
+ // N.B. UNWIND_INFO structs are DWORD-aligned.
+ uint32_t lastcode = (xdata->CountOfCodes + 1) & ~1;
+ const uint32_t *handler = reinterpret_cast<uint32_t *>(&xdata->UnwindCodes[lastcode]);
+ _info.lsda = reinterpret_cast<unw_word_t>(handler+1);
+ if (*handler) {
+ _info.handler = reinterpret_cast<unw_word_t>(__libunwind_seh_personality);
+ } else
+ _info.handler = 0;
+ } else {
+ _info.lsda = 0;
+ _info.handler = 0;
+ }
+ }
+#elif defined(_LIBUNWIND_TARGET_ARM)
+ _info.end_ip = _info.start_ip + unwindEntry->FunctionLength;
+ _info.lsda = 0; // FIXME
+ _info.handler = 0; // FIXME
+#endif
+ setLastPC(pc);
+ return true;
+}
+#endif
+
+
template <typename A, typename R>
void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
pint_t pc = (pint_t)this->getReg(UNW_REG_IP);
@@ -1319,6 +1852,12 @@ void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
}
#endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
+#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
+ // If there is SEH unwind info, look there next.
+ if (this->getInfoFromSEH(pc))
+ return;
+#endif
+
#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
// If there is dwarf unwind info, look there next.
if (sects.dwarf_section != 0) {
@@ -1348,7 +1887,7 @@ void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
if (msg == NULL) {
typename CFI_Parser<A>::PrologInfo prolog;
if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo,
- pc, &prolog)) {
+ pc, R::getArch(), &prolog)) {
// save off parsed FDE info
_info.start_ip = fdeInfo.pcStart;
_info.end_ip = fdeInfo.pcEnd;
@@ -1377,8 +1916,8 @@ void UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool isReturnAddress) {
// Double check this FDE is for a function that includes the pc.
if ((fdeInfo.pcStart <= pc) && (pc < fdeInfo.pcEnd)) {
typename CFI_Parser<A>::PrologInfo prolog;
- if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo,
- cieInfo, pc, &prolog)) {
+ if (CFI_Parser<A>::parseFDEInstructions(_addressSpace, fdeInfo, cieInfo,
+ pc, R::getArch(), &prolog)) {
// save off parsed FDE info
_info.start_ip = fdeInfo.pcStart;
_info.end_ip = fdeInfo.pcEnd;
@@ -1411,12 +1950,15 @@ int UnwindCursor<A, R>::step() {
int result;
#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
result = this->stepWithCompactEncoding();
+#elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
+ result = this->stepWithSEHData();
#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
result = this->stepWithDwarfFDE();
#elif defined(_LIBUNWIND_ARM_EHABI)
result = this->stepWithEHABI();
#else
#error Need _LIBUNWIND_SUPPORT_COMPACT_UNWIND or \
+ _LIBUNWIND_SUPPORT_SEH_UNWIND or \
_LIBUNWIND_SUPPORT_DWARF_UNWIND or \
_LIBUNWIND_ARM_EHABI
#endif
diff --git a/lib/libunwind/src/UnwindRegistersRestore.S b/lib/libunwind/src/UnwindRegistersRestore.S
index 7b355fdeb4a..bca4876dada 100644
--- a/lib/libunwind/src/UnwindRegistersRestore.S
+++ b/lib/libunwind/src/UnwindRegistersRestore.S
@@ -801,49 +801,6 @@ DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind14Registers_or1k6jumptoEv)
l.jr r9
l.nop
-#elif defined(__sparc__) && defined(__arch64__)
-
-DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind17Registers_sparc646jumptoEv)
-#
-# void libunwind::Registers_sparc64::jumpto()
-#
-# On entry:
-# thread_state pointer is in %o0
-#
- flushw
- ldx [%o0 + 0x08], %g1
- ldx [%o0 + 0x10], %g2
- ldx [%o0 + 0x18], %g3
- ldx [%o0 + 0x20], %g4
- ldx [%o0 + 0x28], %g5
- ldx [%o0 + 0x30], %g6
- ldx [%o0 + 0x38], %g7
- ldx [%o0 + 0x48], %o1
- ldx [%o0 + 0x50], %o2
- ldx [%o0 + 0x58], %o3
- ldx [%o0 + 0x60], %o4
- ldx [%o0 + 0x68], %o5
- ldx [%o0 + 0x70], %o6
- ldx [%o0 + 0x78], %o7
- ldx [%o0 + 0x80], %l0
- ldx [%o0 + 0x88], %l1
- ldx [%o0 + 0x90], %l2
- ldx [%o0 + 0x98], %l3
- ldx [%o0 + 0xa0], %l4
- ldx [%o0 + 0xa8], %l5
- ldx [%o0 + 0xb0], %l6
- ldx [%o0 + 0xb8], %l7
- ldx [%o0 + 0xc0], %i0
- ldx [%o0 + 0xc8], %i1
- ldx [%o0 + 0xd0], %i2
- ldx [%o0 + 0xd8], %i3
- ldx [%o0 + 0xe0], %i4
- ldx [%o0 + 0xe8], %i5
- ldx [%o0 + 0xf0], %i6
- ldx [%o0 + 0xf8], %i7
- jmpl %o7 + 8, %g0
- ldx [%o0 + 0x40], %o0
-
#elif defined(__mips__) && defined(_ABIO32) && _MIPS_SIM == _ABIO32
//
@@ -858,7 +815,7 @@ DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind18Registers_mips_o326jumptoEv)
.set noreorder
.set nomacro
#ifdef __mips_hard_float
-#if __mips_fpr == 32
+#if __mips_fpr != 64
ldc1 $f0, (4 * 36 + 8 * 0)($4)
ldc1 $f2, (4 * 36 + 8 * 2)($4)
ldc1 $f4, (4 * 36 + 8 * 4)($4)
@@ -1043,6 +1000,71 @@ DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind21Registers_mips_newabi6jumptoEv)
ld $4, (8 * 4)($4)
.set pop
+#elif defined(__sparc__) && defined(__arch64__)
+
+DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind17Registers_sparc646jumptoEv)
+#
+# void libunwind::Registers_sparc64::jumpto()
+#
+# On entry:
+# thread_state pointer is in %o0
+#
+ flushw
+ ldx [%o0 + 0x08], %g1
+ ldx [%o0 + 0x10], %g2
+ ldx [%o0 + 0x18], %g3
+ ldx [%o0 + 0x20], %g4
+ ldx [%o0 + 0x28], %g5
+ ldx [%o0 + 0x30], %g6
+ ldx [%o0 + 0x38], %g7
+ ldx [%o0 + 0x48], %o1
+ ldx [%o0 + 0x50], %o2
+ ldx [%o0 + 0x58], %o3
+ ldx [%o0 + 0x60], %o4
+ ldx [%o0 + 0x68], %o5
+ ldx [%o0 + 0x70], %o6
+ ldx [%o0 + 0x78], %o7
+ ldx [%o0 + 0x80], %l0
+ ldx [%o0 + 0x88], %l1
+ ldx [%o0 + 0x90], %l2
+ ldx [%o0 + 0x98], %l3
+ ldx [%o0 + 0xa0], %l4
+ ldx [%o0 + 0xa8], %l5
+ ldx [%o0 + 0xb0], %l6
+ ldx [%o0 + 0xb8], %l7
+ ldx [%o0 + 0xc0], %i0
+ ldx [%o0 + 0xc8], %i1
+ ldx [%o0 + 0xd0], %i2
+ ldx [%o0 + 0xd8], %i3
+ ldx [%o0 + 0xe0], %i4
+ ldx [%o0 + 0xe8], %i5
+ ldx [%o0 + 0xf0], %i6
+ ldx [%o0 + 0xf8], %i7
+ jmpl %o7 + 8, %g0
+ ldx [%o0 + 0x40], %o0
+
+#elif defined(__sparc__)
+
+//
+// void libunwind::Registers_sparc_o32::jumpto()
+//
+// On entry:
+// thread_state pointer is in o0
+//
+DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind15Registers_sparc6jumptoEv)
+ ta 3
+ ldd [%o0 + 64], %l0
+ ldd [%o0 + 72], %l2
+ ldd [%o0 + 80], %l4
+ ldd [%o0 + 88], %l6
+ ldd [%o0 + 96], %i0
+ ldd [%o0 + 104], %i2
+ ldd [%o0 + 112], %i4
+ ldd [%o0 + 120], %i6
+ ld [%o0 + 60], %o7
+ jmp %o7
+ nop
+
#endif
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
diff --git a/lib/libunwind/src/UnwindRegistersSave.S b/lib/libunwind/src/UnwindRegistersSave.S
index a7a0a45b59c..27703c54b6c 100644
--- a/lib/libunwind/src/UnwindRegistersSave.S
+++ b/lib/libunwind/src/UnwindRegistersSave.S
@@ -168,7 +168,7 @@ DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
mflo $8
sw $8, (4 * 34)($4)
#ifdef __mips_hard_float
-#if __mips_fpr == 32
+#if __mips_fpr != 64
sdc1 $f0, (4 * 36 + 8 * 0)($4)
sdc1 $f2, (4 * 36 + 8 * 2)($4)
sdc1 $f4, (4 * 36 + 8 * 4)($4)
@@ -995,9 +995,36 @@ DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
retl
stx %g4, [%o0 + 0x100]
-#endif
+#elif defined(__sparc__)
+#
+# extern int unw_getcontext(unw_context_t* thread_state)
+#
+# On entry:
+# thread_state pointer is in o0
+#
+DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
+ ta 3
+ add %o7, 8, %o7
+ std %g0, [%o0 + 0]
+ std %g2, [%o0 + 8]
+ std %g4, [%o0 + 16]
+ std %g6, [%o0 + 24]
+ std %o0, [%o0 + 32]
+ std %o2, [%o0 + 40]
+ std %o4, [%o0 + 48]
+ std %o6, [%o0 + 56]
+ std %l0, [%o0 + 64]
+ std %l2, [%o0 + 72]
+ std %l4, [%o0 + 80]
+ std %l6, [%o0 + 88]
+ std %i0, [%o0 + 96]
+ std %i2, [%o0 + 104]
+ std %i4, [%o0 + 112]
+ std %i6, [%o0 + 120]
+ jmp %o7
+ clr %o0 // return UNW_ESUCCESS
+#endif
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
NO_EXEC_STACK_DIRECTIVE
-
diff --git a/lib/libunwind/src/assembly.h b/lib/libunwind/src/assembly.h
index 1901265f226..f35680507a7 100644
--- a/lib/libunwind/src/assembly.h
+++ b/lib/libunwind/src/assembly.h
@@ -44,6 +44,7 @@
#if defined(__APPLE__)
#define SYMBOL_IS_FUNC(name)
+#define EXPORT_SYMBOL(name)
#define HIDDEN_SYMBOL(name) .private_extern name
#define NO_EXEC_STACK_DIRECTIVE
@@ -54,6 +55,7 @@
#else
#define SYMBOL_IS_FUNC(name) .type name,@function
#endif
+#define EXPORT_SYMBOL(name)
#define HIDDEN_SYMBOL(name) .hidden name
#if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
@@ -70,10 +72,21 @@
.scl 2 SEPARATOR \
.type 32 SEPARATOR \
.endef
+#define EXPORT_SYMBOL2(name) \
+ .section .drectve,"yn" SEPARATOR \
+ .ascii "-export:", #name, "\0" SEPARATOR \
+ .text
+#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
+#define EXPORT_SYMBOL(name)
+#else
+#define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
+#endif
#define HIDDEN_SYMBOL(name)
#define NO_EXEC_STACK_DIRECTIVE
+#elif defined(__sparc__)
+
#else
#error Unsupported target
@@ -82,6 +95,7 @@
#define DEFINE_LIBUNWIND_FUNCTION(name) \
.globl SYMBOL_NAME(name) SEPARATOR \
+ EXPORT_SYMBOL(name) SEPARATOR \
SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
SYMBOL_NAME(name):
diff --git a/lib/libunwind/src/libunwind.cpp b/lib/libunwind/src/libunwind.cpp
index 20067994e7a..ecd0b03b4ed 100644
--- a/lib/libunwind/src/libunwind.cpp
+++ b/lib/libunwind/src/libunwind.cpp
@@ -69,6 +69,8 @@ _LIBUNWIND_EXPORT int unw_init_local(unw_cursor_t *cursor,
# warning The MIPS architecture is not supported with this ABI and environment!
#elif defined(__sparc__) && defined(__arch64__)
# define REGISTER_KIND Registers_sparc64
+#elif defined(__sparc__)
+# define REGISTER_KIND Registers_sparc
#else
# error Architecture not supported
#endif