Added explicit errno reporting from error() API.
[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(e, x,...) do {set_errstr(x, ##__VA_ARGS__);                               \
15                                                         set_errno(e);                                                           \
16                                                         longjmp(&get_cur_errbuf()->jmpbuf, 1);} while(0)
17 #define nexterror() do {errpop(errstack, ARRAY_SIZE(errstack), &curindex,      \
18                             prev_errbuf);                                      \
19                      longjmp(&(get_cur_errbuf())->jmpbuf, 1);} while (0)
20 #define poperror() do {errpop(errstack, ARRAY_SIZE(errstack), &curindex,       \
21                        prev_errbuf);} while (0)
22
23 int errpush(struct errbuf *errstack, int stacksize, int *curindex,
24             struct errbuf **prev_errbuf);
25 void errpop(struct errbuf *errstack, int stacksize, int *curindex,
26             struct errbuf *prev_errbuf);
27
28 #endif /* ROS_KERN_ERR_H */