summaryrefslogtreecommitdiffstats
path: root/usr/include/setjmp.h
blob: 5916cd8a32948ac43eabbd9bda7898f07ed76d29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * setjmp.h
 */

#ifndef _SETJMP_H
#define _SETJMP_H

#include <klibc/extern.h>
#include <klibc/compiler.h>
#include <stddef.h>
#include <signal.h>

#include <klibc/archsetjmp.h>

__extern int setjmp(jmp_buf);
__extern __noreturn longjmp(jmp_buf, int);

/*
  Whose bright idea was it to add unrelated functionality to just about
  the only function in the standard C library (setjmp) which cannot be
  wrapped by an ordinary function wrapper?  Anyway, the damage is done,
  and therefore, this wrapper *must* be inline.  However, gcc will
  complain if this is an inline function for unknown reason, and
  therefore sigsetjmp() needs to be a macro.
*/

struct __sigjmp_buf {
	jmp_buf __jmpbuf;
	sigset_t __sigs;
	unsigned char __sigs_saved;
};

typedef struct __sigjmp_buf sigjmp_buf[1];

#define sigsetjmp(__env, __save) \
({ \
  struct __sigjmp_buf *__e = (__env); \
  if (__save) { \
    sigprocmask(0, NULL, &__e->__sigs); \
    __e->__sigs_saved = 1; \
  } else \
    __e->__sigs_saved = 0; \
  setjmp(__e->__jmpbuf); \
})

__extern __noreturn siglongjmp(sigjmp_buf, int);

#endif				/* _SETJMP_H */