Added set_error() API to have a single point of entry for setting for errno and errstr.
[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                 set_error(e, x, ##__VA_ARGS__);                                                                 \
17                 longjmp(&get_cur_errbuf()->jmpbuf, 1);                                                  \
18         } while(0)
19 #define nexterror() longjmp(&(errpop(errstack, ARRAY_SIZE(errstack), &curindex, \
20                                                                          prev_errbuf)->jmpbuf), 1)
21 #define poperror() errpop(errstack, ARRAY_SIZE(errstack), &curindex,    \
22                                                   prev_errbuf)
23
24 struct errbuf *errpush(struct errbuf *errstack, int stacksize, int *curindex,
25                                                 struct errbuf **prev_errbuf);
26 struct errbuf *errpop(struct errbuf *errstack, int stacksize, int *curindex,
27                                           struct errbuf *prev_errbuf);
28
29 #endif /* ROS_KERN_ERR_H */