Have #ip protocol's connect()s throw errors
[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 #define error(e, x, ...)                                                                                                \
14         do {                                                                                                                            \
15                 set_error(e, x, ##__VA_ARGS__);                                                                 \
16                 longjmp(&get_cur_errbuf()->jmpbuf, 1);                                                  \
17         } while(0)
18 #define nexterror() longjmp(&(errpop(errstack, ARRAY_SIZE(errstack), &curindex, \
19                                                                          prev_errbuf)->jmpbuf), 1)
20 #define poperror() errpop(errstack, ARRAY_SIZE(errstack), &curindex,    \
21                                                   prev_errbuf)
22 /* Give Akaros people a hint that we need a real error message. */
23 #define ERROR_FIXME "This space in %s@%d needs filling in.", __FILE__, __LINE__
24
25 struct errbuf *errpush(struct errbuf *errstack, int stacksize, int *curindex,
26                                                 struct errbuf **prev_errbuf);
27 struct errbuf *errpop(struct errbuf *errstack, int stacksize, int *curindex,
28                                           struct errbuf *prev_errbuf);