akaros/kern/include/err.h
<<
>>
Prefs
   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. */
  15extern void set_error(int error, const char *fmt, ...);
  16extern struct errbuf *get_cur_errbuf(void);
  17
  18#define error_jmp() longjmp(&get_cur_errbuf()->jmpbuf, 1)
  19
  20#define error(e, x, ...)                                                \
  21        do {                                                            \
  22                set_error(e, x, ##__VA_ARGS__);                         \
  23                error_jmp();                                            \
  24        } while(0)
  25#define nexterror() longjmp(&(errpop(errstack, ARRAY_SIZE(errstack), &curindex,\
  26                                     prev_errbuf)->jmpbuf), 1)
  27#define poperror() errpop(errstack, ARRAY_SIZE(errstack), &curindex,    \
  28                          prev_errbuf)
  29/* Give Akaros people a hint that we need a real error message. */
  30#define ERROR_FIXME "This space in %s@%d needs filling in.", __FILE__, __LINE__
  31
  32struct errbuf *errpush(struct errbuf *errstack, int stacksize, int *curindex,
  33                       struct errbuf **prev_errbuf);
  34struct errbuf *errpop(struct errbuf *errstack, int stacksize, int *curindex,
  35                      struct errbuf *prev_errbuf);
  36