Skip to content

Commit 2ba10f4

Browse files
committed
Add sigsetjmp to headers for non-eh builds.
1 parent 4048aab commit 2ba10f4

1 file changed

Lines changed: 35 additions & 46 deletions

File tree

libc-top-half/musl/include/setjmp.h

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _SETJMP_H
2-
#define _SETJMP_H
1+
#ifndef _SETJMP_H
2+
#define _SETJMP_H
33

44
#ifdef __cplusplus
55
extern "C" {
@@ -8,67 +8,56 @@ extern "C" {
88
#include <features.h>
99

1010
#ifdef __wasilibc_unmodified_upstream
11-
#include <bits/setjmp.h>
11+
// Native setjmp/longjmp
12+
#include <bits/setjmp.h>
1213

13-
typedef struct __jmp_buf_tag {
14-
__jmp_buf __jb;
15-
unsigned long __fl;
16-
unsigned long __ss[128/sizeof(long)];
17-
} jmp_buf[1];
14+
typedef struct __jmp_buf_tag {
15+
__jmp_buf __jb;
16+
unsigned long __fl;
17+
unsigned long __ss[128/sizeof(long)];
18+
} jmp_buf[1];
1819

19-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
20-
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
21-
|| defined(_BSD_SOURCE)
22-
typedef jmp_buf sigjmp_buf;
23-
int sigsetjmp (sigjmp_buf, int);
24-
_Noreturn void siglongjmp (sigjmp_buf, int);
25-
#endif
26-
27-
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
28-
|| defined(_BSD_SOURCE)
29-
int _setjmp (jmp_buf);
30-
_Noreturn void _longjmp (jmp_buf, int);
31-
#endif
3220
#elif defined(__wasm_exception_handling__)
21+
// EH-based setjmp/longjmp
3322
typedef int __jmp_buf[6];
3423

35-
typedef struct __jmp_buf_tag
36-
{
37-
__jmp_buf __jb;
38-
unsigned long __fl;
39-
unsigned long __ss[128 / sizeof(long)];
40-
} jmp_buf[1];
24+
typedef struct __jmp_buf_tag
25+
{
26+
__jmp_buf __jb;
27+
unsigned long __fl;
28+
unsigned long __ss[128 / sizeof(long)];
29+
} jmp_buf[1];
30+
#else
31+
// asyncify-based setjmp/longjmp
32+
#include <wasi/api.h>
33+
typedef __wasi_stack_snapshot_t __jmp_buf_tag;
34+
typedef __wasi_stack_snapshot_t jmp_buf[1];
35+
typedef jmp_buf sigjmp_buf;
36+
#endif
4137

4238
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
43-
#define __setjmp_attr __attribute__((__returns_twice__))
39+
#define __setjmp_attr __attribute__((__returns_twice__))
4440
#else
45-
#define __setjmp_attr
41+
#define __setjmp_attr
4642
#endif
4743

44+
int setjmp (jmp_buf) __setjmp_attr;
45+
_Noreturn void longjmp (jmp_buf, int);
46+
#define setjmp setjmp
47+
4848
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || \
49-
defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
50-
typedef jmp_buf sigjmp_buf;
51-
int sigsetjmp(sigjmp_buf, int) __setjmp_attr;
52-
_Noreturn void siglongjmp(sigjmp_buf, int);
49+
defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
50+
typedef jmp_buf sigjmp_buf;
51+
int sigsetjmp(sigjmp_buf, int) __setjmp_attr;
52+
_Noreturn void siglongjmp(sigjmp_buf, int);
5353
#endif
5454

5555
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
56-
int _setjmp(jmp_buf) __setjmp_attr;
57-
_Noreturn void _longjmp(jmp_buf, int);
56+
int _setjmp(jmp_buf) __setjmp_attr;
57+
_Noreturn void _longjmp(jmp_buf, int);
5858
#endif
5959

6060
#undef __setjmp_attr
61-
#else
62-
#include <wasi/api.h>
63-
typedef __wasi_stack_snapshot_t __jmp_buf_tag;
64-
typedef __wasi_stack_snapshot_t jmp_buf[1];
65-
typedef jmp_buf sigjmp_buf;
66-
#endif
67-
68-
int setjmp (jmp_buf);
69-
_Noreturn void longjmp (jmp_buf, int);
70-
71-
#define setjmp setjmp
7261

7362
#ifdef __cplusplus
7463
}

0 commit comments

Comments
 (0)