@samitouri / QOSamiQemu / commits / 654dce6c52

linux-user/ppc: Fix ppc64 rt_sigframe stack offset

The kernel's 64-bit signal delivery (signal_64.c) uses: newsp = frame - __SIGNAL_FRAMESIZE while the 32-bit path (signal_32.c) uses: newsp = frame - (__SIGNAL_FRAMESIZE + 16) The extra 16 bytes in the 32-bit case is to place siginfo and ucontext at the same offsets as older kernels (see the comment in signal_32.c). The 64-bit rt_sigframe starts with ucontext directly and does not need this adjustment. QEMU's setup_rt_frame() unconditionally used (SIGNAL_FRAMESIZE + 16) for both 32-bit and 64-bit, placing the handler's SP 16 bytes too low on ppc64. Signal delivery and return still worked because do_rt_sigreturn had the matching wrong offset, but the vDSO DWARF unwind info encodes the correct kernel offset. This caused any DWARF unwinder (libunwind, libgcc, etc.) to compute a CFA that is 16 bytes off, reading garbage register values from the signal frame. Define RT_SIGFRAME_ADJUST (0 on ppc64, 16 on ppc32) and use it in both setup_rt_frame and do_rt_sigreturn to match the kernel. This was verified by A/B testing with libunwind's test suite: ppc64le: Gtest-bt, Ltest-bt, Gtest-concurrent, Ltest-concurrent, and Ltest-sig-context all change from FAIL to PASS. ppc64be: Gtest-bt, Ltest-bt, and Ltest-sig-context all change from FAIL to PASS. Signed-off-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Helge Deller <deller@gmx.de> Cc: qemu-stable@nongnu.org

Matt Turner committed Apr 16, 2026 at 14:25 UTC 654dce6c523612d38e8d53818dbc7c03cbe535a3
1 file changed +14 -2
linux-user/ppc/signal.c
+14 -2
@@ -210,6 +210,18 @@ QEMU_BUILD_BUG_ON(offsetof(struct target_rt_sigframe, uc.tuc_mcontext)
210
211 #endif
212
213 +#ifdef TARGET_PPC64
214 +#define RT_SIGFRAME_ADJUST 0
215 +#else
216 +/*
217 + * For 32-bit rt sigframes we have an extra 16 bytes of gap
218 + * on top of __SIGNAL_FRAMESIZE; this is to get the siginfo
219 + * and ucontext in the same positions as in older kernels.
220 + * See Linux's arch/powerpc/kernel/signal_32.c.
221 + */
222 +#define RT_SIGFRAME_ADJUST 16
223 +#endif
224 +
225 #if defined(TARGET_PPC64)
226
227 struct target_func_ptr {
@@ -525,7 +537,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
537 env->fpscr = 0;
538
539 /* Create a stack frame for the caller of the handler. */
528 - newsp = rt_sf_addr - (SIGNAL_FRAMESIZE + 16);
540 + newsp = rt_sf_addr - (SIGNAL_FRAMESIZE + RT_SIGFRAME_ADJUST);
541 err |= put_user(env->gpr[1], newsp, target_ulong);
542
543 if (err)
@@ -641,7 +653,7 @@ long do_rt_sigreturn(CPUPPCState *env)
653 struct target_rt_sigframe *rt_sf = NULL;
654 target_ulong rt_sf_addr;
655
644 - rt_sf_addr = env->gpr[1] + SIGNAL_FRAMESIZE + 16;
656 + rt_sf_addr = env->gpr[1] + SIGNAL_FRAMESIZE + RT_SIGFRAME_ADJUST;
657 if (!lock_user_struct(VERIFY_READ, rt_sf, rt_sf_addr, 1))
658 goto sigsegv;
659