L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
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
53void l4_assert_fn(unsigned expr, const char *text) L4_NOTHROW;
54
59void l4_assert_abort(const char *text) L4_NOTHROW;
60
61
62/* IMPLEMENTATION -----------------------------------------------------------*/
63
65void 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
74void l4_assert_fn(unsigned 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 compiler related defines.
@ L4_BASE_LOG_CAP
Capability selector for the log object.
Definition consts.h:336
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:168
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:912
@ L4_THREAD_EX_REGS_TRIGGER_EXCEPTION
Trigger artificial exception in thread.
Definition thread.h:762
long l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Write data to virtual console.
Definition vcon.h:345
#define L4_ALWAYS_INLINE
Always inline a function.
Definition compiler.h:69
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:188
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
#define L4_NORETURN
Noreturn function attribute.
Definition compiler.h:218
#define L4_LIKELY(x)
Expression is likely to execute.
Definition compiler.h:295
Virtual console interface.