From 8f2753c9fe3d859158a226a0fdb6cc090d2d45c4 Mon Sep 17 00:00:00 2001 From: rosenrost <52100845+rosenrost@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:45:37 +0100 Subject: [PATCH] Make sigsetjmp() an alias of setjmp() sigsetjmp() called setjmp() as a separate function, so setjmp() saved the stack pointer and return address of sigsetjmp() instead of its caller. A later longjmp() then returned into the stack frame of sigsetjmp(), which no longer existed. It only worked if the compiler happened to turn the call into a jump. --- sources/setjmp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sources/setjmp.c b/sources/setjmp.c index df7503a..7b7b13f 100644 --- a/sources/setjmp.c +++ b/sources/setjmp.c @@ -51,9 +51,15 @@ void longjmp(jmp_buf buf, int val) } -int sigsetjmp(jmp_buf buf, int mask) -{ - return setjmp(buf); -} +/* + * sigsetjmp() must not call setjmp(), otherwise the context of sigsetjmp() + * itself would be saved, which no longer exists when longjmp() is called. + * Signal masks are not supported, so the mask argument is simply ignored, + * which is safe with the caller-pops-arguments calling convention. + */ +#if __GNUC__ >= 8 +#pragma GCC diagnostic ignored "-Wattribute-alias" +#endif +int sigsetjmp(jmp_buf buf, int mask) __attribute__((alias("setjmp"))); #endif