From 3903480f523ff35db21861c8a212236f535ce1cb Mon Sep 17 00:00:00 2001 From: sanana Date: Sun, 26 Jan 2025 11:50:24 +0300 Subject: [PATCH] options/ansi: provide _setjmp and _longjmp in setjmp.h --- options/ansi/include/setjmp.h | 10 +++++++++- options/internal/aarch64/setjmp.S | 9 ++++++--- options/internal/m68k/setjmp.S | 9 ++++++--- options/internal/riscv64/setjmp.S | 9 ++++++--- options/internal/x86/setjmp.S | 9 ++++++--- options/internal/x86_64/setjmp.S | 9 ++++++--- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/options/ansi/include/setjmp.h b/options/ansi/include/setjmp.h index 91c0ecabbe..6099bb6076 100644 --- a/options/ansi/include/setjmp.h +++ b/options/ansi/include/setjmp.h @@ -18,9 +18,17 @@ typedef struct __jmp_buf { #ifndef __MLIBC_ABI_ONLY -__attribute__((__returns_twice__)) int setjmp(jmp_buf __buffer); +__attribute__((__returns_twice__)) int _setjmp(jmp_buf __buffer); __attribute__((__noreturn__)) void longjmp(jmp_buf __buffer, int __value); +/* setjmp is defined as a function macro in the ISO C standard */ +#define setjmp(env) _setjmp(env) + +#if __MLIBC_POSIX_OPTION +/* POSIX-2017.1 says _longjmp shall be declared as a function */ +__attribute__((__noreturn__)) void _longjmp(jmp_buf __buffer, int __value); +#endif /* __MLIBC_POSIX_OPTION */ + #endif /* !__MLIBC_ABI_ONLY */ /* POSIX Non-local jumps signal extensions */ diff --git a/options/internal/aarch64/setjmp.S b/options/internal/aarch64/setjmp.S index b87dfb3d6d..23f7f72f49 100644 --- a/options/internal/aarch64/setjmp.S +++ b/options/internal/aarch64/setjmp.S @@ -25,9 +25,9 @@ __setjmp: 1: b __sigsetjmp -.global setjmp -.type setjmp, "function" -setjmp: +.global _setjmp +.type _setjmp, "function" +_setjmp: mov x2, xzr b __setjmp @@ -39,7 +39,10 @@ sigsetjmp: .global longjmp .type longjmp, "function" +.global _longjmp +.type _longjmp, "function" longjmp: +_longjmp: ldp x19, x20, [x0, #0] ldp x21, x22, [x0, #16] ldp x23, x24, [x0, #32] diff --git a/options/internal/m68k/setjmp.S b/options/internal/m68k/setjmp.S index 92f253acd7..a33fe102c6 100644 --- a/options/internal/m68k/setjmp.S +++ b/options/internal/m68k/setjmp.S @@ -17,9 +17,9 @@ __setjmp: rts -.global setjmp -.type setjmp, "function" -setjmp: +.global _setjmp +.type _setjmp, "function" +_setjmp: clr.l %d0 jmp __setjmp @@ -31,7 +31,10 @@ sigsetjmp: .global longjmp .type longjmp, "function" +.global _longjmp +.type _longjmp, "function" longjmp: +_longjmp: movea.l 4(%sp),%a0 move.l 8(%sp),%d0 bne 1f diff --git a/options/internal/riscv64/setjmp.S b/options/internal/riscv64/setjmp.S index 51568f7c68..157b08dfb8 100644 --- a/options/internal/riscv64/setjmp.S +++ b/options/internal/riscv64/setjmp.S @@ -1,6 +1,6 @@ -.global setjmp -.type setjmp, "function" -setjmp: +.global _setjmp +.type _setjmp, "function" +_setjmp: sd ra, 0(a0) sd s0, 8(a0) sd s1, 16(a0) @@ -37,7 +37,10 @@ sigsetjmp: .global longjmp .type longjmp, "function" +.global _longjmp +.type _longjmp, "function" longjmp: +_longjmp: ld ra,0(a0) ld s0,8(a0) ld s1,16(a0) diff --git a/options/internal/x86/setjmp.S b/options/internal/x86/setjmp.S index fa6644c7b5..f008909efa 100644 --- a/options/internal/x86/setjmp.S +++ b/options/internal/x86/setjmp.S @@ -20,9 +20,9 @@ __setjmp: 1: jmp __sigsetjmp@PLT -.global setjmp -.type setjmp, "function" -setjmp: +.global _setjmp +.type _setjmp, "function" +_setjmp: xor %edx, %edx jmp __setjmp @@ -34,7 +34,10 @@ sigsetjmp: .global longjmp .type longjmp, "function" +.global _longjmp +.type _longjmp, "function" longjmp: +_longjmp: mov 4(%esp), %ecx mov 0x00(%ecx), %ebx mov 0x04(%ecx), %ebp diff --git a/options/internal/x86_64/setjmp.S b/options/internal/x86_64/setjmp.S index aa8a13433b..f69bc11d45 100644 --- a/options/internal/x86_64/setjmp.S +++ b/options/internal/x86_64/setjmp.S @@ -21,9 +21,9 @@ __setjmp: 1: jmp __sigsetjmp -.global setjmp -.type setjmp, "function" -setjmp: +.global _setjmp +.type _setjmp, "function" +_setjmp: xor %rdx, %rdx jmp __setjmp @@ -35,7 +35,10 @@ sigsetjmp: .global longjmp .type longjmp, "function" +.global _longjmp +.type _longjmp, "function" longjmp: +_longjmp: mov 0x00(%rdi), %rbx mov 0x08(%rdi), %rbp mov 0x10(%rdi), %r12