akaros/kern/include/assert.h
<<
>>
Prefs
   1/* See COPYRIGHT for copyright information. */
   2
   3#pragma once
   4
   5#include <compiler.h>
   6
   7void _warn(const char *, int, const char *, ...);
   8struct hw_trapframe;
   9void _panic(struct hw_trapframe *, const char *, int, const char *, ...)
  10        __attribute__((noreturn));
  11
  12#define warn(...) _warn(__FILE__, __LINE__, __VA_ARGS__)
  13#define warn_once(...) run_once_racy(warn(__VA_ARGS__))
  14#define warn_on(x) do { if (x) warn(#x);} while (0)
  15#define warn_on_once(x) do { if (x) warn_once(#x);} while (0)
  16
  17#define warn_on_user_ptr(x) do { \
  18        uintptr_t _x = (uintptr_t)(x); \
  19        warn_on(_x && _x < ULIM); \
  20} while (0)
  21
  22#define panic(...) _panic(NULL, __FILE__, __LINE__, __VA_ARGS__)
  23#define panic_hwtf(x, ...) _panic(x, __FILE__, __LINE__, __VA_ARGS__)
  24#define exhausted(...) _panic(NULL, __FILE__, __LINE__, __VA_ARGS__)
  25
  26#define assert(x)               \
  27        do { if (unlikely(!(x))) panic("assertion failed: %s", #x); } while (0)
  28
  29#define error_check(e, x) \
  30        do { if (unlikely(!(x))) error(e, "Assertion failed: " #x); } while (0)
  31
  32// static_assert(x) will generate a compile-time error if 'x' is false.
  33#define static_assert(x)        switch (x) case 0: case (x):
  34
  35#ifdef CONFIG_DEVELOPMENT_ASSERTIONS
  36#define dassert(x) assert(x)
  37#else
  38#define dassert(x) ((void) (x))  // 'Use' value, stop compile warnings
  39#endif /* DEVELOPMENT_ASSERTIONS */
  40