37fd8e5359914b8ef62ca01a42684929f09dbcbe
[akaros.git] / kern / include / err.h
1 /* Plan9 style error popping.  For details, read Documentation/plan9.txt */
2
3 #ifndef ROS_KERN_ERR_H
4 #define ROS_KERN_ERR_H
5
6 #include <setjmp.h>
7 #include <kthread.h>
8
9 #define ERRSTACK(x) struct errbuf *prev_errbuf; struct errbuf errstack[(x)];   \
10                     int curindex = 0;
11 #define waserror() (errpush(errstack, ARRAY_SIZE(errstack), &curindex,         \
12                             &prev_errbuf) ||                                   \
13                     setjmp(&(get_cur_errbuf()->jmpbuf)))
14 #define error(x,...) do {set_errstr(x, ##__VA_ARGS__);                         \
15                              longjmp(&get_cur_errbuf()->jmpbuf, 1);} while(0)
16 #define nexterror() do {errpop(errstack, ARRAY_SIZE(errstack), &curindex,      \
17                             prev_errbuf);                                      \
18                      longjmp(&(get_cur_errbuf())->jmpbuf, 1);} while (0)
19 #define poperror() do {errpop(errstack, ARRAY_SIZE(errstack), &curindex,       \
20                        prev_errbuf);} while (0)
21
22 int errpush(struct errbuf *errstack, int stacksize, int *curindex,
23             struct errbuf **prev_errbuf);
24 void errpop(struct errbuf *errstack, int stacksize, int *curindex,
25             struct errbuf *prev_errbuf);
26
27 #endif /* ROS_KERN_ERR_H */