add swifi to the build/install.
[minix.git] / include / setjmp.h
blob1417bcd30bc23038bfce419f735ab44ceb1cb994
1 /* The <setjmp.h> header relates to the C phenomenon known as setjmp/longjmp.
2 * It is used to escape out of the current situation into a previous one.
4 * The actual implementations of all these functions and, by extension, parts
5 * of this header, are both compiler- and architecture-dependent. Currently
6 * two compilers are supported: ACK and GCC. Each of these has their own
7 * implementation of the functions in their runtime system library code.
8 * As it is impossible to predict the requirements for any other compilers,
9 * this header may not be compatible with such other compilers either.
11 * The ACK compiler will not enregister any variables inside a function
12 * containing a setjmp call, even if those variables are explicitly declared
13 * as register variables. Thus for ACK, of all the registers, only the
14 * program counter, stack pointer and frame pointer have to be saved into the
15 * jmp_buf structure. This makes the jmp_buf structure very small, and
16 * moreover, the implementation of the setjmp/longjmp calls (written in EM)
17 * architecture-independent and thus very portable. The ACK compiler
18 * recognizes only the symbol __setjmp as being such a setjmp call.
20 * The GCC compiler recognizes all of the setjmp/_setjmp/__setjmp name
21 * variants as calls to setjmp functions, and treats them as special
22 * accordingly, but does require that the setjmp implementation save and
23 * restore most of the registers. It has no portable setjmp and longjmp
24 * functions like ACK, and therefore has to have enough space in the jmp_buf
25 * structure to store the registers on any architecture it's ported to.
27 * Taking the common denominator of both compilers, the function definitions
28 * in this header rely on the presence of merely two functions: __setjmp and
29 * longjmp. On the other hand, the size of jmp_buf depends on the compiler
30 * used: for ACK, jmp_buf is exactly big enough to store the three mentioned
31 * registers; for GCC and any other compiler, the size is chosen in such a
32 * way that it's likely to offer enough room to store registers for any
33 * architecture. The POSIX sigjmp_buf is identical to jmp_buf in all cases.
35 * As far as porting is concerned --
37 * All code writers/porters that have to deal with the actual contents of the
38 * jmp_buf structure in one way or another, should look at <sys/jmp_buf.h>.
40 * Porters of a new compiler to Minix have to make sure the compiler
41 * recognizes at least __setjmp as a setjmp call (if applicable) and provide
42 * library implementations of __setjmp and longjmp conforming to their
43 * declarations below; if this is not possible, compiler-specific code will
44 * have to be added to this header.
46 * Porters of Minix+GCC to other architectures have to make sure that the
47 * __regs array of the jmp_buf structure is large enough to hold all the
48 * registers the __setjmp implementation for that architecture has to save.
51 #ifndef _SETJMP_H
52 #define _SETJMP_H
54 #ifndef _ANSI_H
55 #include <ansi.h>
56 #endif
58 typedef struct {
59 #if defined(__ACK__)
60 _PROTOTYPE(void (*__pc),(void)); /* program counter */
61 void *__sp; /* stack pointer */
62 void *__lb; /* local base (ACKspeak for frame pointer) */
63 long __mask; /* must have size >= sizeof(sigset_t) */
64 int __flags;
65 #else /* GCC */
66 int __flags; /* XXX - long might give better alignment */
67 long __mask; /* must have size >= sizeof(sigset_t) */
68 void *__regs[16]; /* actual use is architecture dependent */
69 #endif
70 } jmp_buf[1];
72 _PROTOTYPE( int __setjmp, (jmp_buf _env, int _savemask) );
73 _PROTOTYPE( void longjmp, (jmp_buf _env, int _val) );
75 #define setjmp(env) __setjmp((env), 1)
77 #ifdef _MINIX
78 #define _setjmp(env) __setjmp((env), 0)
79 #define _longjmp(env, val) longjmp((env), (val))
80 #endif
82 #ifdef _POSIX_SOURCE
83 typedef jmp_buf sigjmp_buf;
84 #define sigsetjmp(env, savemask) __setjmp((env), (savemask))
85 #define siglongjmp(env, val) longjmp((env), (val))
86 #endif /* _POSIX_SOURCE */
88 #endif /* _SETJMP_H */