xref: /optee_os/core/include/kernel/panic.h (revision 1bb929836182ecb96d2d9d268daa807c67596396)
1*1bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */
2b0104773SPascal Brand /*
3b0104773SPascal Brand  * Copyright (c) 2014, STMicroelectronics International N.V.
4b0104773SPascal Brand  * All rights reserved.
5b0104773SPascal Brand  *
6b0104773SPascal Brand  * Redistribution and use in source and binary forms, with or without
7b0104773SPascal Brand  * modification, are permitted provided that the following conditions are met:
8b0104773SPascal Brand  *
9b0104773SPascal Brand  * 1. Redistributions of source code must retain the above copyright notice,
10b0104773SPascal Brand  * this list of conditions and the following disclaimer.
11b0104773SPascal Brand  *
12b0104773SPascal Brand  * 2. Redistributions in binary form must reproduce the above copyright notice,
13b0104773SPascal Brand  * this list of conditions and the following disclaimer in the documentation
14b0104773SPascal Brand  * and/or other materials provided with the distribution.
15b0104773SPascal Brand  *
16b0104773SPascal Brand  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17b0104773SPascal Brand  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b0104773SPascal Brand  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b0104773SPascal Brand  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20b0104773SPascal Brand  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21b0104773SPascal Brand  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22b0104773SPascal Brand  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23b0104773SPascal Brand  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24b0104773SPascal Brand  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25b0104773SPascal Brand  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26b0104773SPascal Brand  * POSSIBILITY OF SUCH DAMAGE.
27b0104773SPascal Brand  */
28b0104773SPascal Brand 
29b0104773SPascal Brand #ifndef KERNEL_PANIC_H
30b0104773SPascal Brand #define KERNEL_PANIC_H
31b0104773SPascal Brand 
32cebdec51SJens Wiklander #include <compiler.h>
33cebdec51SJens Wiklander 
3487a092a7SEtienne Carriere /* debug disabled => __FILE__, ... and panic message are not built. */
353f17b838SEtienne Carriere #if defined(CFG_TEE_CORE_DEBUG)
3687a092a7SEtienne Carriere #define __panic(str)	__do_panic(__FILE__, __LINE__, __func__, str)
3787a092a7SEtienne Carriere #else
3887a092a7SEtienne Carriere #define __panic(str)	__do_panic((void *)0, 0, (void *)0, (void *)0)
3987a092a7SEtienne Carriere #endif
40b0104773SPascal Brand 
4187a092a7SEtienne Carriere void __do_panic(const char *file, const int line, const char *func,
4287a092a7SEtienne Carriere 		const char *msg) __noreturn;
4387a092a7SEtienne Carriere 
4487a092a7SEtienne Carriere /*
4587a092a7SEtienne Carriere  * Suppress GCC warning on expansion of the panic() macro with no argument:
4687a092a7SEtienne Carriere  *  'ISO C99 requires at least one argument for the "..." in a variadic macro'
4787a092a7SEtienne Carriere  * Occurs when '-pedantic' is combined with '-std=gnu99'.
4887a092a7SEtienne Carriere  * Suppression applies only to this file and the expansion of macros defined in
4987a092a7SEtienne Carriere  * this file.
5087a092a7SEtienne Carriere  */
5187a092a7SEtienne Carriere #pragma GCC system_header
5287a092a7SEtienne Carriere 
5387a092a7SEtienne Carriere /* panic() can get a string or no argument */
5487a092a7SEtienne Carriere #define _panic0()	__panic((void *)0)
5587a092a7SEtienne Carriere #define _panic1(s)	__panic(s)
5687a092a7SEtienne Carriere #define _panic_fn(a, b, name, ...) name
5787a092a7SEtienne Carriere #define panic(...) _panic_fn("", ##__VA_ARGS__, _panic1, _panic0)(__VA_ARGS__)
58b0104773SPascal Brand 
59b0104773SPascal Brand #endif /*KERNEL_PANIC_H*/
60