summaryrefslogtreecommitdiff
path: root/libunwind/src
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-01-17 20:45:01 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-01-17 20:45:01 +0000
commit706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch)
tree4adf86a776049cbf7f69a1929c4babcbbef925eb /libunwind/src
parent7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff)
Notes
Diffstat (limited to 'libunwind/src')
-rw-r--r--libunwind/src/AddressSpace.hpp8
-rw-r--r--libunwind/src/DwarfInstructions.hpp9
-rw-r--r--libunwind/src/RWMutex.hpp2
-rw-r--r--libunwind/src/Registers.hpp265
-rw-r--r--libunwind/src/UnwindCursor.hpp20
-rw-r--r--libunwind/src/UnwindLevel1-gcc-ext.c9
-rw-r--r--libunwind/src/UnwindRegistersRestore.S81
-rw-r--r--libunwind/src/UnwindRegistersSave.S80
-rw-r--r--libunwind/src/config.h3
-rw-r--r--libunwind/src/libunwind.cpp2
10 files changed, 470 insertions, 9 deletions
diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 908c898d7403..7433476f9117 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -27,7 +27,7 @@
#if _LIBUNWIND_USE_DLADDR
#include <dlfcn.h>
-#if defined(__unix__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBUNWIND_LINK_DL_LIB)
#pragma comment(lib, "dl")
#endif
#endif
@@ -433,8 +433,12 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
HANDLE process = GetCurrentProcess();
DWORD needed;
- if (!EnumProcessModules(process, mods, sizeof(mods), &needed))
+ if (!EnumProcessModules(process, mods, sizeof(mods), &needed)) {
+ DWORD err = GetLastError();
+ _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: EnumProcessModules failed, "
+ "returned error %d", (int)err);
return false;
+ }
for (unsigned i = 0; i < (needed / sizeof(HMODULE)); i++) {
PIMAGE_DOS_HEADER pidh = (PIMAGE_DOS_HEADER)mods[i];
diff --git a/libunwind/src/DwarfInstructions.hpp b/libunwind/src/DwarfInstructions.hpp
index 29a070fa3e04..ee98f538d437 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -34,7 +34,7 @@ public:
typedef typename A::sint_t sint_t;
static int stepWithDwarf(A &addressSpace, pint_t pc, pint_t fdeStart,
- R &registers);
+ R &registers, bool &isSignalFrame);
private:
@@ -150,7 +150,8 @@ v128 DwarfInstructions<A, R>::getSavedVectorRegister(
template <typename A, typename R>
int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
- pint_t fdeStart, R &registers) {
+ pint_t fdeStart, R &registers,
+ bool &isSignalFrame) {
FDE_Info fdeInfo;
CIE_Info cieInfo;
if (CFI_Parser<A>::decodeFDE(addressSpace, fdeStart, &fdeInfo,
@@ -196,6 +197,8 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
// restoring SP means setting it to CFA.
newRegisters.setSP(cfa);
+ isSignalFrame = cieInfo.isSignalFrame;
+
#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
@@ -430,7 +433,7 @@ DwarfInstructions<A, R>::evaluateExpression(pint_t expression, A &addressSpace,
// pick from
reg = addressSpace.get8(p);
p += 1;
- value = sp[-reg];
+ value = sp[-(int)reg];
*(++sp) = value;
if (log)
fprintf(stderr, "duplicate %d in stack\n", reg);
diff --git a/libunwind/src/RWMutex.hpp b/libunwind/src/RWMutex.hpp
index 954e94c322d4..fcd3f4967d17 100644
--- a/libunwind/src/RWMutex.hpp
+++ b/libunwind/src/RWMutex.hpp
@@ -17,7 +17,7 @@
#include <windows.h>
#elif !defined(_LIBUNWIND_HAS_NO_THREADS)
#include <pthread.h>
-#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA)
+#if defined(__ELF__) && defined(_LIBUNWIND_LINK_PTHREAD_LIB)
#pragma comment(lib, "pthread")
#endif
#endif
diff --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index a36c6cf90d3f..416ed61df74a 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -34,6 +34,7 @@ enum {
REGISTERS_MIPS_O32,
REGISTERS_MIPS_NEWABI,
REGISTERS_SPARC,
+ REGISTERS_RISCV,
};
#if defined(_LIBUNWIND_TARGET_I386)
@@ -3517,6 +3518,270 @@ inline const char *Registers_sparc::getRegisterName(int regNum) {
}
#endif // _LIBUNWIND_TARGET_SPARC
+#if defined(_LIBUNWIND_TARGET_RISCV)
+/// Registers_riscv holds the register state of a thread in a 64-bit RISC-V
+/// process.
+class _LIBUNWIND_HIDDEN Registers_riscv {
+public:
+ Registers_riscv();
+ Registers_riscv(const void *registers);
+
+ bool validRegister(int num) const;
+ uint64_t getRegister(int num) const;
+ void setRegister(int num, uint64_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_RISCV; }
+ static int getArch() { return REGISTERS_RISCV; }
+
+ uint64_t getSP() const { return _registers[2]; }
+ void setSP(uint64_t value) { _registers[2] = value; }
+ uint64_t getIP() const { return _registers[1]; }
+ void setIP(uint64_t value) { _registers[1] = value; }
+
+private:
+
+ uint64_t _registers[32];
+ double _floats[32];
+};
+
+inline Registers_riscv::Registers_riscv(const void *registers) {
+ static_assert((check_fit<Registers_riscv, unw_context_t>::does_fit),
+ "riscv registers do not fit into unw_context_t");
+ memcpy(&_registers, registers, sizeof(_registers));
+ static_assert(sizeof(_registers) == 0x100,
+ "expected float registers to be at offset 256");
+ memcpy(_floats,
+ static_cast<const uint8_t *>(registers) + sizeof(_registers),
+ sizeof(_floats));
+}
+
+inline Registers_riscv::Registers_riscv() {
+ memset(&_registers, 0, sizeof(_registers));
+ memset(&_floats, 0, sizeof(_floats));
+}
+
+inline bool Registers_riscv::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_RISCV_F31)
+ return false;
+ return true;
+}
+
+inline uint64_t Registers_riscv::getRegister(int regNum) const {
+ if (regNum == UNW_REG_IP)
+ return _registers[1];
+ if (regNum == UNW_REG_SP)
+ return _registers[2];
+ if (regNum == UNW_RISCV_X0)
+ return 0;
+ if ((regNum > 0) && (regNum < 32))
+ return _registers[regNum];
+ _LIBUNWIND_ABORT("unsupported riscv register");
+}
+
+inline void Registers_riscv::setRegister(int regNum, uint64_t value) {
+ if (regNum == UNW_REG_IP)
+ _registers[1] = value;
+ else if (regNum == UNW_REG_SP)
+ _registers[2] = value;
+ else if (regNum == UNW_RISCV_X0)
+ /* x0 is hardwired to zero */
+ return;
+ else if ((regNum > 0) && (regNum < 32))
+ _registers[regNum] = value;
+ else
+ _LIBUNWIND_ABORT("unsupported riscv register");
+}
+
+inline const char *Registers_riscv::getRegisterName(int regNum) {
+ switch (regNum) {
+ case UNW_REG_IP:
+ return "pc";
+ case UNW_REG_SP:
+ return "sp";
+ case UNW_RISCV_X0:
+ return "zero";
+ case UNW_RISCV_X1:
+ return "ra";
+ case UNW_RISCV_X2:
+ return "sp";
+ case UNW_RISCV_X3:
+ return "gp";
+ case UNW_RISCV_X4:
+ return "tp";
+ case UNW_RISCV_X5:
+ return "t0";
+ case UNW_RISCV_X6:
+ return "t1";
+ case UNW_RISCV_X7:
+ return "t2";
+ case UNW_RISCV_X8:
+ return "s0";
+ case UNW_RISCV_X9:
+ return "s1";
+ case UNW_RISCV_X10:
+ return "a0";
+ case UNW_RISCV_X11:
+ return "a1";
+ case UNW_RISCV_X12:
+ return "a2";
+ case UNW_RISCV_X13:
+ return "a3";
+ case UNW_RISCV_X14:
+ return "a4";
+ case UNW_RISCV_X15:
+ return "a5";
+ case UNW_RISCV_X16:
+ return "a6";
+ case UNW_RISCV_X17:
+ return "a7";
+ case UNW_RISCV_X18:
+ return "s2";
+ case UNW_RISCV_X19:
+ return "s3";
+ case UNW_RISCV_X20:
+ return "s4";
+ case UNW_RISCV_X21:
+ return "s5";
+ case UNW_RISCV_X22:
+ return "s6";
+ case UNW_RISCV_X23:
+ return "s7";
+ case UNW_RISCV_X24:
+ return "s8";
+ case UNW_RISCV_X25:
+ return "s9";
+ case UNW_RISCV_X26:
+ return "s10";
+ case UNW_RISCV_X27:
+ return "s11";
+ case UNW_RISCV_X28:
+ return "t3";
+ case UNW_RISCV_X29:
+ return "t4";
+ case UNW_RISCV_X30:
+ return "t5";
+ case UNW_RISCV_X31:
+ return "t6";
+ case UNW_RISCV_F0:
+ return "ft0";
+ case UNW_RISCV_F1:
+ return "ft1";
+ case UNW_RISCV_F2:
+ return "ft2";
+ case UNW_RISCV_F3:
+ return "ft3";
+ case UNW_RISCV_F4:
+ return "ft4";
+ case UNW_RISCV_F5:
+ return "ft5";
+ case UNW_RISCV_F6:
+ return "ft6";
+ case UNW_RISCV_F7:
+ return "ft7";
+ case UNW_RISCV_F8:
+ return "fs0";
+ case UNW_RISCV_F9:
+ return "fs1";
+ case UNW_RISCV_F10:
+ return "fa0";
+ case UNW_RISCV_F11:
+ return "fa1";
+ case UNW_RISCV_F12:
+ return "fa2";
+ case UNW_RISCV_F13:
+ return "fa3";
+ case UNW_RISCV_F14:
+ return "fa4";
+ case UNW_RISCV_F15:
+ return "fa5";
+ case UNW_RISCV_F16:
+ return "fa6";
+ case UNW_RISCV_F17:
+ return "fa7";
+ case UNW_RISCV_F18:
+ return "fs2";
+ case UNW_RISCV_F19:
+ return "fs3";
+ case UNW_RISCV_F20:
+ return "fs4";
+ case UNW_RISCV_F21:
+ return "fs5";
+ case UNW_RISCV_F22:
+ return "fs6";
+ case UNW_RISCV_F23:
+ return "fs7";
+ case UNW_RISCV_F24:
+ return "fs8";
+ case UNW_RISCV_F25:
+ return "fs9";
+ case UNW_RISCV_F26:
+ return "fs10";
+ case UNW_RISCV_F27:
+ return "fs11";
+ case UNW_RISCV_F28:
+ return "ft8";
+ case UNW_RISCV_F29:
+ return "ft9";
+ case UNW_RISCV_F30:
+ return "ft10";
+ case UNW_RISCV_F31:
+ return "ft11";
+ default:
+ return "unknown register";
+ }
+}
+
+inline bool Registers_riscv::validFloatRegister(int regNum) const {
+ if (regNum < UNW_RISCV_F0)
+ return false;
+ if (regNum > UNW_RISCV_F31)
+ return false;
+ return true;
+}
+
+inline double Registers_riscv::getFloatRegister(int regNum) const {
+#if defined(__riscv_flen) && __riscv_flen == 64
+ assert(validFloatRegister(regNum));
+ return _floats[regNum - UNW_RISCV_F0];
+#else
+ _LIBUNWIND_ABORT("libunwind not built with float support");
+#endif
+}
+
+inline void Registers_riscv::setFloatRegister(int regNum, double value) {
+#if defined(__riscv_flen) && __riscv_flen == 64
+ assert(validFloatRegister(regNum));
+ _floats[regNum - UNW_RISCV_F0] = value;
+#else
+ _LIBUNWIND_ABORT("libunwind not built with float support");
+#endif
+}
+
+inline bool Registers_riscv::validVectorRegister(int) const {
+ return false;
+}
+
+inline v128 Registers_riscv::getVectorRegister(int) const {
+ _LIBUNWIND_ABORT("no riscv vector register support yet");
+}
+
+inline void Registers_riscv::setVectorRegister(int, v128) {
+ _LIBUNWIND_ABORT("no riscv vector register support yet");
+}
+#endif // _LIBUNWIND_TARGET_RISCV
} // namespace libunwind
#endif // __REGISTERS_HPP__
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index b4d44e111a65..31be8366d238 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -929,7 +929,7 @@ private:
return DwarfInstructions<A, R>::stepWithDwarf(_addressSpace,
(pint_t)this->getReg(UNW_REG_IP),
(pint_t)_info.unwind_info,
- _registers);
+ _registers, _isSignalFrame);
}
#endif
@@ -995,6 +995,12 @@ private:
int stepWithCompactEncoding(Registers_sparc &) { return UNW_EINVAL; }
#endif
+#if defined (_LIBUNWIND_TARGET_RISCV)
+ int stepWithCompactEncoding(Registers_riscv &) {
+ return UNW_EINVAL;
+ }
+#endif
+
bool compactSaysUseDwarf(uint32_t *offset=NULL) const {
R dummy;
return compactSaysUseDwarf(dummy, offset);
@@ -1061,6 +1067,12 @@ private:
bool compactSaysUseDwarf(Registers_sparc &, uint32_t *) const { return true; }
#endif
+#if defined (_LIBUNWIND_TARGET_RISCV)
+ bool compactSaysUseDwarf(Registers_riscv &, uint32_t *) const {
+ return true;
+ }
+#endif
+
#endif // defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
@@ -1127,6 +1139,12 @@ private:
compact_unwind_encoding_t dwarfEncoding(Registers_sparc &) const { return 0; }
#endif
+#if defined (_LIBUNWIND_TARGET_RISCV)
+ compact_unwind_encoding_t dwarfEncoding(Registers_riscv &) const {
+ return 0;
+ }
+#endif
+
#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
diff --git a/libunwind/src/UnwindLevel1-gcc-ext.c b/libunwind/src/UnwindLevel1-gcc-ext.c
index 63e4083a4579..008df815665e 100644
--- a/libunwind/src/UnwindLevel1-gcc-ext.c
+++ b/libunwind/src/UnwindLevel1-gcc-ext.c
@@ -221,7 +221,14 @@ _LIBUNWIND_EXPORT uintptr_t _Unwind_GetCFA(struct _Unwind_Context *context) {
_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,
int *ipBefore) {
_LIBUNWIND_TRACE_API("_Unwind_GetIPInfo(context=%p)", (void *)context);
- *ipBefore = 0;
+ int isSignalFrame = __unw_is_signal_frame((unw_cursor_t *)context);
+ // Negative means some kind of error (probably UNW_ENOINFO), but we have no
+ // good way to report that, and this maintains backward compatibility with the
+ // implementation that hard-coded zero in every case, even signal frames.
+ if (isSignalFrame <= 0)
+ *ipBefore = 0;
+ else
+ *ipBefore = 1;
return _Unwind_GetIP(context);
}
diff --git a/libunwind/src/UnwindRegistersRestore.S b/libunwind/src/UnwindRegistersRestore.S
index 8122bf3e1b2e..cbb2fd447005 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -1029,6 +1029,87 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_sparc6jumptoEv)
jmp %o7
nop
+#elif defined(__riscv) && __riscv_xlen == 64
+
+//
+// void libunwind::Registers_riscv::jumpto()
+//
+// On entry:
+// thread_state pointer is in a0
+//
+ .p2align 2
+DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_riscv6jumptoEv)
+#if defined(__riscv_flen) && __riscv_flen == 64
+ fld f0, (8 * 32 + 8 * 0)(a0)
+ fld f1, (8 * 32 + 8 * 1)(a0)
+ fld f2, (8 * 32 + 8 * 2)(a0)
+ fld f3, (8 * 32 + 8 * 3)(a0)
+ fld f4, (8 * 32 + 8 * 4)(a0)
+ fld f5, (8 * 32 + 8 * 5)(a0)
+ fld f6, (8 * 32 + 8 * 6)(a0)
+ fld f7, (8 * 32 + 8 * 7)(a0)
+ fld f8, (8 * 32 + 8 * 8)(a0)
+ fld f9, (8 * 32 + 8 * 9)(a0)
+ fld f10, (8 * 32 + 8 * 10)(a0)
+ fld f11, (8 * 32 + 8 * 11)(a0)
+ fld f12, (8 * 32 + 8 * 12)(a0)
+ fld f13, (8 * 32 + 8 * 13)(a0)
+ fld f14, (8 * 32 + 8 * 14)(a0)
+ fld f15, (8 * 32 + 8 * 15)(a0)
+ fld f16, (8 * 32 + 8 * 16)(a0)
+ fld f17, (8 * 32 + 8 * 17)(a0)
+ fld f18, (8 * 32 + 8 * 18)(a0)
+ fld f19, (8 * 32 + 8 * 19)(a0)
+ fld f20, (8 * 32 + 8 * 20)(a0)
+ fld f21, (8 * 32 + 8 * 21)(a0)
+ fld f22, (8 * 32 + 8 * 22)(a0)
+ fld f23, (8 * 32 + 8 * 23)(a0)
+ fld f24, (8 * 32 + 8 * 24)(a0)
+ fld f25, (8 * 32 + 8 * 25)(a0)
+ fld f26, (8 * 32 + 8 * 26)(a0)
+ fld f27, (8 * 32 + 8 * 27)(a0)
+ fld f28, (8 * 32 + 8 * 28)(a0)
+ fld f29, (8 * 32 + 8 * 29)(a0)
+ fld f30, (8 * 32 + 8 * 30)(a0)
+ fld f31, (8 * 32 + 8 * 31)(a0)
+#endif
+
+ // x0 is zero
+ ld x1, (8 * 1)(a0)
+ ld x2, (8 * 2)(a0)
+ ld x3, (8 * 3)(a0)
+ ld x4, (8 * 4)(a0)
+ ld x5, (8 * 5)(a0)
+ ld x6, (8 * 6)(a0)
+ ld x7, (8 * 7)(a0)
+ ld x8, (8 * 8)(a0)
+ ld x9, (8 * 9)(a0)
+ // skip a0 for now
+ ld x11, (8 * 11)(a0)
+ ld x12, (8 * 12)(a0)
+ ld x13, (8 * 13)(a0)
+ ld x14, (8 * 14)(a0)
+ ld x15, (8 * 15)(a0)
+ ld x16, (8 * 16)(a0)
+ ld x17, (8 * 17)(a0)
+ ld x18, (8 * 18)(a0)
+ ld x19, (8 * 19)(a0)
+ ld x20, (8 * 20)(a0)
+ ld x21, (8 * 21)(a0)
+ ld x22, (8 * 22)(a0)
+ ld x23, (8 * 23)(a0)
+ ld x24, (8 * 24)(a0)
+ ld x25, (8 * 25)(a0)
+ ld x26, (8 * 26)(a0)
+ ld x27, (8 * 27)(a0)
+ ld x28, (8 * 28)(a0)
+ ld x29, (8 * 29)(a0)
+ ld x30, (8 * 30)(a0)
+ ld x31, (8 * 31)(a0)
+ ld x10, (8 * 10)(a0) // restore a0
+
+ ret // jump to ra
+
#endif
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
diff --git a/libunwind/src/UnwindRegistersSave.S b/libunwind/src/UnwindRegistersSave.S
index 54505e53bac7..da91abc233de 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -974,6 +974,86 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
std %i6, [%o0 + 120]
jmp %o7
clr %o0 // return UNW_ESUCCESS
+
+#elif defined(__riscv) && __riscv_xlen == 64
+
+#
+# extern int __unw_getcontext(unw_context_t* thread_state)
+#
+# On entry:
+# thread_state pointer is in a0
+#
+DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
+ // x0 is zero
+ sd x1, (8 * 1)(a0)
+ sd x2, (8 * 2)(a0)
+ sd x3, (8 * 3)(a0)
+ sd x4, (8 * 4)(a0)
+ sd x5, (8 * 5)(a0)
+ sd x6, (8 * 6)(a0)
+ sd x7, (8 * 7)(a0)
+ sd x8, (8 * 8)(a0)
+ sd x9, (8 * 9)(a0)
+ sd x10, (8 * 10)(a0)
+ sd x11, (8 * 11)(a0)
+ sd x12, (8 * 12)(a0)
+ sd x13, (8 * 13)(a0)
+ sd x14, (8 * 14)(a0)
+ sd x15, (8 * 15)(a0)
+ sd x16, (8 * 16)(a0)
+ sd x17, (8 * 17)(a0)
+ sd x18, (8 * 18)(a0)
+ sd x19, (8 * 19)(a0)
+ sd x20, (8 * 20)(a0)
+ sd x21, (8 * 21)(a0)
+ sd x22, (8 * 22)(a0)
+ sd x23, (8 * 23)(a0)
+ sd x24, (8 * 24)(a0)
+ sd x25, (8 * 25)(a0)
+ sd x26, (8 * 26)(a0)
+ sd x27, (8 * 27)(a0)
+ sd x28, (8 * 28)(a0)
+ sd x29, (8 * 29)(a0)
+ sd x30, (8 * 30)(a0)
+ sd x31, (8 * 31)(a0)
+
+#if defined(__riscv_flen) && __riscv_flen == 64
+ fsd f0, (8 * 32 + 8 * 0)(a0)
+ fsd f1, (8 * 32 + 8 * 1)(a0)
+ fsd f2, (8 * 32 + 8 * 2)(a0)
+ fsd f3, (8 * 32 + 8 * 3)(a0)
+ fsd f4, (8 * 32 + 8 * 4)(a0)
+ fsd f5, (8 * 32 + 8 * 5)(a0)
+ fsd f6, (8 * 32 + 8 * 6)(a0)
+ fsd f7, (8 * 32 + 8 * 7)(a0)
+ fsd f8, (8 * 32 + 8 * 8)(a0)
+ fsd f9, (8 * 32 + 8 * 9)(a0)
+ fsd f10, (8 * 32 + 8 * 10)(a0)
+ fsd f11, (8 * 32 + 8 * 11)(a0)
+ fsd f12, (8 * 32 + 8 * 12)(a0)
+ fsd f13, (8 * 32 + 8 * 13)(a0)
+ fsd f14, (8 * 32 + 8 * 14)(a0)
+ fsd f15, (8 * 32 + 8 * 15)(a0)
+ fsd f16, (8 * 32 + 8 * 16)(a0)
+ fsd f17, (8 * 32 + 8 * 17)(a0)
+ fsd f18, (8 * 32 + 8 * 18)(a0)
+ fsd f19, (8 * 32 + 8 * 19)(a0)
+ fsd f20, (8 * 32 + 8 * 20)(a0)
+ fsd f21, (8 * 32 + 8 * 21)(a0)
+ fsd f22, (8 * 32 + 8 * 22)(a0)
+ fsd f23, (8 * 32 + 8 * 23)(a0)
+ fsd f24, (8 * 32 + 8 * 24)(a0)
+ fsd f25, (8 * 32 + 8 * 25)(a0)
+ fsd f26, (8 * 32 + 8 * 26)(a0)
+ fsd f27, (8 * 32 + 8 * 27)(a0)
+ fsd f28, (8 * 32 + 8 * 28)(a0)
+ fsd f29, (8 * 32 + 8 * 29)(a0)
+ fsd f30, (8 * 32 + 8 * 30)(a0)
+ fsd f31, (8 * 32 + 8 * 31)(a0)
+#endif
+
+ li a0, 0 // return UNW_ESUCCESS
+ ret // jump to ra
#endif
WEAK_ALIAS(__unw_getcontext, unw_getcontext)
diff --git a/libunwind/src/config.h b/libunwind/src/config.h
index 09bb261647ca..dcd3cef94552 100644
--- a/libunwind/src/config.h
+++ b/libunwind/src/config.h
@@ -103,7 +103,8 @@
defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__) || \
(!defined(__APPLE__) && defined(__arm__)) || \
(defined(__arm64__) || defined(__aarch64__)) || \
- defined(__mips__)
+ defined(__mips__) || \
+ defined(__riscv)
#if !defined(_LIBUNWIND_BUILD_SJLJ_APIS)
#define _LIBUNWIND_BUILD_ZERO_COST_APIS
#endif
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index 31f30f5cd709..1ee58ad1971e 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -58,6 +58,8 @@ _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,
# warning The MIPS architecture is not supported with this ABI and environment!
#elif defined(__sparc__)
# define REGISTER_KIND Registers_sparc
+#elif defined(__riscv) && __riscv_xlen == 64
+# define REGISTER_KIND Registers_riscv
#else
# error Architecture not supported
#endif