L4Re - L4 Runtime Environment
assert.h
Go to the documentation of this file.
1 
5 /*
6  * (c) 2015 Adam Lackorzynski <adam@l4re.org>
7  *
8  * This file is part of L4Re and distributed under the terms of the
9  * GNU General Public License 2.
10  * Please see the COPYING-GPL-2 file for details.
11  *
12  * As a special exception, you may use this file as part of a free software
13  * library without restriction. Specifically, if other files instantiate
14  * templates or use macros or inline functions from this file, or you compile
15  * this file and link it with other files to produce an executable, this
16  * file does not by itself cause the resulting executable to be covered by
17  * the GNU General Public License. This exception does not however
18  * invalidate any other reasons why the executable file might be covered by
19  * the GNU General Public License.
20  */
21 #pragma once
22 
23 #ifdef NDEBUG
24 
25 #define l4_assert(x) do { } while (0)
26 #define l4_check(x) do { (void)(x); } while (0)
27 
28 #else
29 
30 #include <l4/sys/compiler.h>
31 #include <l4/sys/thread.h>
32 #include <l4/sys/vcon.h>
33 
43 #define l4_assert(expr) \
44  l4_assert_fn(expr, __FILE__ ":" L4_stringify(__LINE__) ": Assertion \"" \
45  L4_stringify(expr) "\" failed.\n")
46 
47 #define l4_check(expr) l4_assert(expr)
48 
53 void l4_assert_fn(bool expr, const char *text) L4_NOTHROW;
54 
58 L4_INLINE L4_NORETURN
59 void l4_assert_abort(const char *text) L4_NOTHROW;
60 
61 
62 /* IMPLEMENTATION -----------------------------------------------------------*/
63 
64 L4_INLINE L4_NORETURN
65 void l4_assert_abort(const char *text) L4_NOTHROW
66 {
67  l4_vcon_write(L4_BASE_LOG_CAP, text, __builtin_strlen(text));
68  for (;;)
71 }
72 
74 void l4_assert_fn(bool expr, const char *text) L4_NOTHROW
75 {
76  if (L4_LIKELY(expr))
77  return;
78 
79  l4_assert_abort(text);
80 }
81 
82 #endif /* NDEBUG */
l4_msgtag_t l4_thread_ex_regs(l4_cap_idx_t thread, l4_addr_t ip, l4_addr_t sp, l4_umword_t flags) L4_NOTHROW
Exchange basic thread registers.
Definition: thread.h:829
Invalid capability selector.
Definition: consts.h:141
#define L4_ALWAYS_INLINE
L4 Inline function attribute.
Definition: compiler.h:67
L4 compiler related defines.
long l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Write data to virtual console.
Definition: vcon.h:310
#define L4_NORETURN
Noreturn function attribute.
Definition: compiler.h:202
Capability selector for the log object.
Definition: consts.h:263
#define L4_LIKELY(x)
Expression is likely to execute.
Definition: compiler.h:233
Trigger artificial exception in thread.
Definition: thread.h:681
Virtual console interface.
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185