L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
assert.h
Go to the documentation of this file.
1
5/*
6 * (c) 2015 Adam Lackorzynski <adam@l4re.org>
7 *
8 * License: see LICENSE.spdx (in this directory or the directories above)
9 */
10#pragma once
11
12#ifdef NDEBUG
13
14#define l4_assert(x) do { } while (0)
15#define l4_check(x) do { (void)(x); } while (0)
16
17#else
18
19#include <l4/sys/compiler.h>
20#include <l4/sys/thread.h>
21#include <l4/sys/vcon.h>
22
32#define l4_assert(expr) \
33 l4_assert_fn(!!(expr), __FILE__ ":" L4_stringify(__LINE__) ": Assertion \"" \
34 L4_stringify(expr) "\" failed.\n")
35
36#define l4_check(expr) l4_assert(expr)
37
42void l4_assert_fn(unsigned expr, const char *text) L4_NOTHROW;
43
48void l4_assert_abort(const char *text) L4_NOTHROW;
49
50
51/* IMPLEMENTATION -----------------------------------------------------------*/
52
54void l4_assert_abort(const char *text) L4_NOTHROW
55{
56 l4_vcon_write(L4_BASE_LOG_CAP, text, __builtin_strlen(text));
57 for (;;)
60}
61
63void l4_assert_fn(unsigned expr, const char *text) L4_NOTHROW
64{
65 if (L4_LIKELY(expr))
66 return;
67
68 l4_assert_abort(text);
69}
70
71#endif /* NDEBUG */
L4 compiler related defines.
@ L4_BASE_LOG_CAP
Capability selector for the log object.
Definition consts.h:351
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:157
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:919
@ L4_THREAD_EX_REGS_TRIGGER_EXCEPTION
Trigger artificial exception in thread.
Definition thread.h:777
long l4_vcon_write(l4_cap_idx_t vcon, char const *buf, unsigned size) L4_NOTHROW
Write data to virtual console.
Definition vcon.h:334
#define L4_ALWAYS_INLINE
Always inline a function.
Definition compiler.h:58
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:159
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
#define L4_NORETURN
Noreturn function attribute.
Definition compiler.h:197
#define L4_LIKELY(x)
Expression is likely to execute.
Definition compiler.h:274
Virtual console interface.