Avoid an extra function call on the error frame handling.
[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 #include <error.h>
9
10 #define ERRSTACK(x) struct errbuf *prev_errbuf; struct errbuf errstack[(x)];   \
11                     int curindex = 0;
12 #define waserror() setjmp(&(errpush(errstack, ARRAY_SIZE(errstack), &curindex, \
13                                                                         &prev_errbuf)->jmpbuf))
14 #define error(e, x, ...)                                                \
15         do {                                                                            \
16                 if (x != NULL)                                                                                                  \
17                         set_errstr(x, ##__VA_ARGS__);                                                           \
18                 else                                                                                                                    \
19                         set_errstr(errno_to_string(e));                                                         \
20                 set_errno(e);                                                                                                   \
21                 longjmp(&get_cur_errbuf()->jmpbuf, 1);                                                  \
22         } while(0)
23 #define nexterror() longjmp(&(errpop(errstack, ARRAY_SIZE(errstack), &curindex, \
24                                                                          prev_errbuf)->jmpbuf), 1)
25 #define poperror() errpop(errstack, ARRAY_SIZE(errstack), &curindex,    \
26                                                   prev_errbuf)
27
28 struct errbuf *errpush(struct errbuf *errstack, int stacksize, int *curindex,
29                                                 struct errbuf **prev_errbuf);
30 struct errbuf *errpop(struct errbuf *errstack, int stacksize, int *curindex,
31                                           struct errbuf *prev_errbuf);
32
33 #endif /* ROS_KERN_ERR_H */