1/*
2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7/**
8 * Declares macros and methods for sel4 specific assert and fail.
9 *
10 * These are unconditional, there are conditional versions of
11 * these in debug_assert.h and are name seL4_DebugAssert and
12 * sl4_DebugCompileTimeAsssert.
13 */
14
15#pragma once
16/**
17 * Hidden function, use the macros seL4_Fail or seL4_Assert.
18 */
19void __assert_fail(const char  *str, const char *file, int line, const char *function);
20
21/**
22 * If expr evaluates to false _seL4_Fail is called with the
23 * expr as a string plus the file, line and function.
24 */
25#define seL4_Fail(s) __assert_fail(s, __FILE__, __LINE__, __func__)
26
27/**
28 * If expr evaluates to false _seL4_AssertFail is called with the
29 * expr as a string plus the file, line and function.
30 */
31#define seL4_Assert(expr) \
32    do { if (!(expr)) { __assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__); } } while(0)
33
34/**
35 * An assert that tests that the expr is a compile time constant and
36 * evaluates to true.
37 *
38 * This code is similar to compile_time_assert in libutils/include/utils/compile_time.h,
39 * we may want to have only one. Also, using __COUNTER__ its not necessary to have name
40 * for uniqueness so I've removed it, although maybe there is another reason for it, like
41 * some compilers don't support __COUNTER__.
42 */
43#define seL4_CompileTimeAssert(expr) \
44    extern char __seL4_CompileTimeAssertFailed_ ## __COUNTER__[__builtin_constant_p(expr) ? ((expr) ? 1 : -1) : -1] __attribute__((unused))
45
46