Fix 'include' issue
[akaros.git] / kern / include / err.h
1 /* Plan9 style error popping.  For details, read Documentation/plan9.txt */
2
3 #pragma once
4
5 #include <setjmp.h>
6 #include <kthread.h>
7 #include <error.h>
8
9 #define ERRSTACK(x) struct errbuf *prev_errbuf; struct errbuf errstack[(x)];   \
10                     int curindex = 0;
11 #define waserror() setjmp(&(errpush(errstack, ARRAY_SIZE(errstack), &curindex, \
12                                                                         &prev_errbuf)->jmpbuf))
13
14 /* In syscall.h, but want to avoid circular include issues. */
15 extern void set_error(int error, const char *fmt, ...);
16 extern struct errbuf *get_cur_errbuf(void);
17
18 #define error(e, x, ...)                                                                                                \
19         do {                                                                                                                            \
20                 set_error(e, x, ##__VA_ARGS__);                                                                 \
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 /* Give Akaros people a hint that we need a real error message. */
28 #define ERROR_FIXME "This space in %s@%d needs filling in.", __FILE__, __LINE__
29
30 struct errbuf *errpush(struct errbuf *errstack, int stacksize, int *curindex,
31                                                 struct errbuf **prev_errbuf);
32 struct errbuf *errpop(struct errbuf *errstack, int stacksize, int *curindex,
33                                           struct errbuf *prev_errbuf);