PCI: properly read the BARs
[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 <syscall.h>
8
9 struct errbuf {
10         struct jmpbuf jmpbuf;
11 };
12
13 /* add 1 in case they forget they need an entry for the passed-in errbuf */
14 #define ERRSTACK(x) struct errbuf *prev_errbuf; struct errbuf errstack[(x)];   \
15                     int curindex = 0;
16 #define waserror() (errpush(errstack, ARRAY_SIZE(errstack), &curindex,         \
17                             &prev_errbuf) ||                                   \
18                     setjmp(&(get_cur_errbuf()->jmpbuf)))
19 #define error(x,...) {set_errstr(x, ##__VA_ARGS__);                            \
20                       longjmp(&get_cur_errbuf()->jmpbuf, 1);}
21 #define nexterror() {errpop(errstack, ARRAY_SIZE(errstack), &curindex,         \
22                             prev_errbuf);                                      \
23                      longjmp(&(get_cur_errbuf())->jmpbuf, 1);}
24 #define poperror() {errpop(errstack, ARRAY_SIZE(errstack), &curindex,          \
25                            prev_errbuf);}
26
27 int errpush(struct errbuf *errstack, int stacksize, int *curindex,
28             struct errbuf **prev_errbuf);
29 void errpop(struct errbuf *errstack, int stacksize, int *curindex,
30             struct errbuf *prev_errbuf);
31
32 #endif /* ROS_KERN_ERR_H */