-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpanic.c
80 lines (61 loc) · 1.77 KB
/
panic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright(c) 2021 John Sanpe <[email protected]>
*/
#include <panic.h>
#include <initcall.h>
#include <proc.h>
#include <delay.h>
#include <power.h>
#include <printk.h>
#include <export.h>
int panic_timeout = CONFIG_PANIC_TIMEOUT;
unsigned int panic_timestep = CONFIG_PANIC_TIMESTEP;
EXPORT_SYMBOL(panic_timeout);
EXPORT_SYMBOL(panic_timestep);
DEFINE_NOTIFIER_SPIN_HEAD(panic_notifier);
DEFINE_NOTIFIER_SPIN_HEAD(panic_blink);
EXPORT_SYMBOL(panic_notifier);
EXPORT_SYMBOL(panic_blink);
static state panic_bootarg(char *args)
{
char *options;
/* get timeout and split commands */
options = strchr(args, ':');
if (options) {
*options++ = '\0';
panic_timeout = atoi(options);
}
panic_timestep = atoui(args);
return -ENOERR;
}
bootarg_initcall("panic_timeout", panic_bootarg);
void __noreturn __cold vpanic(const char *fmt, va_list args)
{
unsigned int count, state;
char buff[512];
irq_local_disable();
preempt_disable();
vsnprintf(buff, sizeof(buff), fmt, args);
pr_emerg("Kernel Panic: %s\n", buff);
notifier_spin_chain_call(&panic_notifier, NULL, -1, NULL);
pr_emerg("---[ end Kernel panic ]---\n");
irq_local_enable();
if (panic_timeout < 0)
kernel_reboot();
if (panic_timeout > 0)
pr_emerg("Rebooting in %d millisecond...\n", panic_timeout);
for (count = state = 0; !panic_timeout ||
count < panic_timeout; count += panic_timestep) {
notifier_spin_chain_call(&panic_blink, (void *)(state ^= 1), -1, NULL);
mdelay(panic_timestep);
}
kernel_reboot();
}
void __noreturn __cold panic(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vpanic(fmt, args);
}
EXPORT_SYMBOL(panic);