MOS Source Code
Loading...
Searching...
No Matches
panic.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include "mos/platform/platform_defs.h"
6#include "mos/syslog/printk.h"
7
8#include <mos/types.h>
9#include <stdarg.h>
10
11typedef void(kmsg_handler_t)(const char *func, u32 line, const char *fmt, va_list args);
12
13typedef struct
14{
15 bool *enabled;
16 void (*hook)(void);
17 const char *const name;
18 long long __padding;
20
21MOS_STATIC_ASSERT(sizeof(panic_hook_t) == 32, "panic_hook_t size mismatch");
22
23typedef struct
24{
26 const char *file, *func;
29
30#define MOS_EMIT_PANIC_HOOK(e, f, n) MOS_PUT_IN_SECTION(".mos.panic_hooks", panic_hook_t, f##_hook, { .enabled = e, .hook = f, .name = n })
31
32#define MOS_PANIC_HOOK_FEAT(_feat, _f, _n) MOS_EMIT_PANIC_HOOK(mos_debug_enabled_ptr(_feat), _f, _n)
33#define MOS_PANIC_HOOK(_f, _name) MOS_EMIT_PANIC_HOOK(NULL, _f, _name)
34
36void kwarn_handler_remove(void);
37
39
40__printf(3, 4) void mos_kwarn(const char *func, u32 line, const char *fmt, ...);
41
44
46
47#define MOS_MAKE_PANIC_POINT(panic_instruction, file, func, line) \
48 __asm__ volatile("1: " panic_instruction "\n\t" \
49 ".pushsection .mos.panic_list,\"aw\"\n\t" MOS_PLATFORM_PANIC_POINT_ASM ".popsection\n\t" \
50 "\n\t" \
51 : \
52 : "i"(file), "i"(func), "i"(line) \
53 : "memory")
54
55#define mos_panic(fmt, ...) \
56 do \
57 { \
58 pr_emerg(fmt, ##__VA_ARGS__); \
59 MOS_MAKE_PANIC_POINT(MOS_PLATFORM_PANIC_INSTR, __FILE__, __func__, __LINE__); \
60 __builtin_unreachable(); \
61 } while (0)
62
63#define mos_panic_inline(fmt, ...) \
64 do \
65 { \
66 pr_emerg(fmt, ##__VA_ARGS__); \
67 static const panic_point_t point = { .ip = 0, .file = __FILE__, .line = __LINE__, .func = __func__ }; \
68 try_handle_kernel_panics_at(&point); \
69 } while (0)
char args[3][16]
Definition avr_io.c:16
MOSAPI void(1, 2) fatal_abort(const char *fmt
#define __END_DECLS
Definition mos_global.h:23
#define __BEGIN_DECLS
Definition mos_global.h:22
#define MOS_STATIC_ASSERT
Definition mos_global.h:14
#define __printf(a, b)
Definition mos_global.h:30
void mos_kwarn(const char *func, u32 line, const char *fmt,...)
Definition panic.c:163
void kwarn_handler_set(kmsg_handler_t *handler)
Definition panic.c:36
u32 line
Definition panic.h:40
u32 const char * fmt
Definition panic.h:40
void try_handle_kernel_panics_at(const panic_point_t *point)
Definition panic.c:78
void kmsg_handler_t(const char *func, u32 line, const char *fmt, va_list args)
Definition panic.h:11
u32 const char void try_handle_kernel_panics(ptr_t ip)
Definition panic.c:67
void kwarn_handler_remove(void)
Definition panic.c:42
bool * enabled
Definition panic.h:15
long long __padding
Definition panic.h:18
const char *const name
Definition panic.h:17
ptr_t ip
Definition panic.h:25
const char * file
Definition panic.h:26
unsigned int u32
Definition types.h:21
unsigned long ptr_t
Definition types.h:25
unsigned long long u64
Definition types.h:23