1 /*
2  * Copyright (c) 2019 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/sys/__assert.h>
8 #include <zephyr/sys/printk.h>
9 #include <zephyr/kernel.h>
10 #include <zephyr/llext/symbol.h>
11 
12 /**
13  * @brief Assert Action Handler
14  *
15  * This routine implements the action to be taken when an assertion fails.
16  *
17  * System designers may wish to substitute this implementation to take other
18  * actions, such as logging program counter, line number, debug information
19  * to a persistent repository and/or rebooting the system.
20  *
21  * @param N/A
22  */
23 #ifdef CONFIG_ASSERT_NO_FILE_INFO
assert_post_action(void)24 __weak void assert_post_action(void)
25 #else
26 __weak void assert_post_action(const char *file, unsigned int line)
27 #endif
28 {
29 #ifndef CONFIG_ASSERT_NO_FILE_INFO
30 	ARG_UNUSED(file);
31 	ARG_UNUSED(line);
32 #endif
33 
34 #ifdef CONFIG_USERSPACE
35 	/* User threads aren't allowed to induce kernel panics; generate
36 	 * an oops instead.
37 	 */
38 	if (k_is_user_context()) {
39 		k_oops();
40 	}
41 #endif
42 
43 	k_panic();
44 }
45 EXPORT_SYMBOL(assert_post_action);
46 
assert_print(const char * fmt,...)47 void assert_print(const char *fmt, ...)
48 {
49 	va_list ap;
50 
51 	va_start(ap, fmt);
52 
53 	vprintk(fmt, ap);
54 
55 	va_end(ap);
56 }
57 EXPORT_SYMBOL(assert_print);
58