Skip to content

Commit

Permalink
options/ansi: provide _setjmp and _longjmp in setjmp.h
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcunt committed Jan 26, 2025
1 parent 1fda4e6 commit 3903480
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
10 changes: 9 additions & 1 deletion options/ansi/include/setjmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 6 additions & 3 deletions options/internal/aarch64/setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]
Expand Down
9 changes: 6 additions & 3 deletions options/internal/m68k/setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ __setjmp:
rts


.global setjmp
.type setjmp, "function"
setjmp:
.global _setjmp
.type _setjmp, "function"
_setjmp:
clr.l %d0
jmp __setjmp

Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions options/internal/riscv64/setjmp.S
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions options/internal/x86/setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions options/internal/x86_64/setjmp.S
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 3903480

Please sign in to comment.