From 043ec220765224dba343eb0e49b87bf1d748c052 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sat, 2 May 2026 16:59:48 +0700 Subject: [PATCH] FIx sigjmp_buf and add tests --- include/setjmp.h | 56 ++----------------- tests/Makefile.tests.mk | 2 + .../bins_dynamic/unistd/alarm_fn.stdout | 1 + .../bins_static/unistd/alarm_fn.stdout | 1 + tests/unistd/alarm_fn.c | 33 +++++++++++ 5 files changed, 41 insertions(+), 52 deletions(-) create mode 100644 tests/expected/bins_dynamic/unistd/alarm_fn.stdout create mode 100644 tests/expected/bins_static/unistd/alarm_fn.stdout create mode 100644 tests/unistd/alarm_fn.c diff --git a/include/setjmp.h b/include/setjmp.h index a8bb37622d..e5167a1203 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -2,67 +2,19 @@ #define _SETJMP_H #ifdef __aarch64__ -typedef unsigned long jmp_buf[22]; -#endif - -#ifdef __arm__ -typedef unsigned long long jmp_buf[32]; +typedef unsigned long long jmp_buf[22]; #endif #ifdef __i386__ -typedef unsigned long jmp_buf[6]; -#endif - -#ifdef __m68k__ -typedef unsigned long jmp_buf[39]; -#endif - -#ifdef __microblaze__ -typedef unsigned long jmp_buf[18]; -#endif - -#ifdef __mips__ -typedef unsigned long long jmp_buf[13]; -#endif - -#ifdef __mips64__ -typedef unsigned long long jmp_buf[23]; -#endif - -#ifdef __mipsn32__ -typedef unsigned long long jmp_buf[23]; -#endif - -#ifdef __or1k__ -typedef unsigned long jmp_buf[13]; -#endif - -#ifdef __powerpc__ -typedef unsigned long long jmp_buf[56]; -#endif - -#ifdef __powerpc64__ -typedef uint128_t jmp_buf[32]; -#endif - -#ifdef __s390x__ -typedef unsigned long jmp_buf[18]; -#endif - -#ifdef __sh__ -typedef unsigned long jmp_buf[15]; -#endif - -#ifdef __x32__ -typedef unsigned long long jmp_buf[8]; +typedef unsigned long long jmp_buf[6]; #endif #ifdef __x86_64__ -typedef unsigned long jmp_buf[16]; +typedef unsigned long long jmp_buf[16]; #endif #ifdef __riscv -typedef unsigned long jmp_buf[26]; +typedef unsigned long long jmp_buf[26]; #endif typedef jmp_buf sigjmp_buf; diff --git a/tests/Makefile.tests.mk b/tests/Makefile.tests.mk index 7c205f07a7..2e5f19fe34 100644 --- a/tests/Makefile.tests.mk +++ b/tests/Makefile.tests.mk @@ -75,6 +75,7 @@ EXPECT_NAMES=\ sigaction \ sigaltstack \ signal \ + sigsetjmp \ stdio/all \ stdio/buffer \ stdio/dprintf \ @@ -161,6 +162,7 @@ EXPECT_NAMES=\ time/tzset \ unistd/access \ unistd/alarm \ + unistd/alarm_fn \ unistd/constants \ unistd/confstr \ unistd/dup \ diff --git a/tests/expected/bins_dynamic/unistd/alarm_fn.stdout b/tests/expected/bins_dynamic/unistd/alarm_fn.stdout new file mode 100644 index 0000000000..58a6753f47 --- /dev/null +++ b/tests/expected/bins_dynamic/unistd/alarm_fn.stdout @@ -0,0 +1 @@ +SIGALRM interrupted the process. diff --git a/tests/expected/bins_static/unistd/alarm_fn.stdout b/tests/expected/bins_static/unistd/alarm_fn.stdout new file mode 100644 index 0000000000..58a6753f47 --- /dev/null +++ b/tests/expected/bins_static/unistd/alarm_fn.stdout @@ -0,0 +1 @@ +SIGALRM interrupted the process. diff --git a/tests/unistd/alarm_fn.c b/tests/unistd/alarm_fn.c new file mode 100644 index 0000000000..6d1135655e --- /dev/null +++ b/tests/unistd/alarm_fn.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include "test_helpers.h" + +static sigjmp_buf jmpenv; + +void alarm_handler(int sig) { + (void)sig; + siglongjmp(jmpenv, 1); +} + +int main() { + struct sigaction sa; + + sa.sa_handler = alarm_handler; + sigemptyset(&sa.sa_mask); + + int sa_status = sigaction(SIGALRM, &sa, NULL); + ERROR_IF(sigaction, sa_status, == -1); + + if (sigsetjmp(jmpenv, 1)) { + printf("SIGALRM interrupted the process.\n"); + return 0; + } + + alarm(1); + sleep(5); + + assert(0); // unreachable +} \ No newline at end of file