From 9b2329f66cfcee3e43b5a0a4ca2bfa02e9a1fb51 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Wed, 15 Jul 2020 23:11:42 +0200 Subject: [PATCH] riscv64: Work around qemu bug old qemu (before april 2020) have a bug in the layout of struct ucontext, so we get invalid values under qemu-userspace emulation when inspecting the signal context. Try to recognize this and graciously error out instead of segfaulting in the backtracer routines. --- tccrun.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tccrun.c b/tccrun.c index 0609cb4c..17f1eebc 100644 --- a/tccrun.c +++ b/tccrun.c @@ -843,8 +843,10 @@ static int rt_get_caller_pc(addr_t *paddr, rt_context *rc, int level) *paddr = rc->ip; } else { addr_t *fp = (addr_t*)rc->fp; - while (--level) + while (--level && fp >= (addr_t*)0x1000) fp = (addr_t *)fp[-2]; + if (fp < (addr_t*)0x1000) + return -1; *paddr = fp[-1]; } return 0;