]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151040: Fix `test_c_stack_unwind` on RISC-V (#152370)
authorIvy Xu <fakeshadow1337@gmail.com>
Mon, 29 Jun 2026 14:47:21 +0000 (22:47 +0800)
committerGitHub <noreply@github.com>
Mon, 29 Jun 2026 14:47:21 +0000 (16:47 +0200)
Modules/_testinternalcapi.c

index 6506bd53b0377ad2f098ff5734e54203854c9ee3..f6ff7820821ce128a5e2a1d5c8e554777c9371ed 100644 (file)
@@ -98,6 +98,11 @@ static const uintptr_t min_frame_pointer_addr = 0x1000;
 // https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html#STACK
 #  define FRAME_POINTER_NEXT_OFFSET 0
 #  define FRAME_POINTER_RETURN_OFFSET 2
+#elif defined(__riscv)
+// RISC-V saves the return address at fp[-1], and the previous frame pointer at fp[-2].
+// See: https://riscv-non-isa.github.io/riscv-elf-psabi-doc/#_frame_pointer_convention
+#  define FRAME_POINTER_NEXT_OFFSET -2
+#  define FRAME_POINTER_RETURN_OFFSET -1
 #elif defined(__loongarch__)
 // On LoongArch, the frame pointer is the caller's stack pointer.
 // The saved frame pointer is stored at fp[-2], and the return