xref: /freebsd/share/man/man9/panic.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1d46ebd58SMike Pritchard.\"     $NetBSD: panic.9,v 1.2 1996/10/09 17:20:04 explorer Exp $
2d46ebd58SMike Pritchard.\"
3*d5e105bfSMitchell Horne.\" SPDX-License-Identifier: BSD-4-Clause
4*d5e105bfSMitchell Horne.\"
5d46ebd58SMike Pritchard.\" Copyright (c) 1996 Michael Graff.
6d46ebd58SMike Pritchard.\" All rights reserved.
7*d5e105bfSMitchell Horne.\" Copyright (c) 2023 The FreeBSD Foundation
8*d5e105bfSMitchell Horne.\"
9*d5e105bfSMitchell Horne.\" Portions of this documentation were written by Mitchell Horne
10*d5e105bfSMitchell Horne.\" under sponsorship from the FreeBSD Foundation.
11d46ebd58SMike Pritchard.\"
12d46ebd58SMike Pritchard.\" Redistribution and use in source and binary forms, with or without
13d46ebd58SMike Pritchard.\" modification, are permitted provided that the following conditions
14d46ebd58SMike Pritchard.\" are met:
15d46ebd58SMike Pritchard.\" 1. Redistributions of source code must retain the above copyright
16d46ebd58SMike Pritchard.\"    notice, this list of conditions and the following disclaimer.
17d46ebd58SMike Pritchard.\" 2. Redistributions in binary form must reproduce the above copyright
18d46ebd58SMike Pritchard.\"    notice, this list of conditions and the following disclaimer in the
19d46ebd58SMike Pritchard.\"    documentation and/or other materials provided with the distribution.
20d46ebd58SMike Pritchard.\" 3. All advertising materials mentioning features or use of this software
21d46ebd58SMike Pritchard.\"    must display the following acknowledgement:
22d46ebd58SMike Pritchard.\"      This product includes software developed by Michael Graff
23d46ebd58SMike Pritchard.\"      for the NetBSD Project.
24*d5e105bfSMitchell Horne.\" 4. The name of the author may not be used to endorse or promote products
25d46ebd58SMike Pritchard.\"    derived from this software without specific prior written permission
26d46ebd58SMike Pritchard.\"
27d46ebd58SMike Pritchard.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28d46ebd58SMike Pritchard.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29d46ebd58SMike Pritchard.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30d46ebd58SMike Pritchard.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31d46ebd58SMike Pritchard.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32d46ebd58SMike Pritchard.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33d46ebd58SMike Pritchard.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34d46ebd58SMike Pritchard.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35d46ebd58SMike Pritchard.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36d46ebd58SMike Pritchard.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37d46ebd58SMike Pritchard.\"
38*d5e105bfSMitchell Horne.Dd March 17, 2023
39d46ebd58SMike Pritchard.Dt PANIC 9
40d46ebd58SMike Pritchard.Os
41d46ebd58SMike Pritchard.Sh NAME
42d46ebd58SMike Pritchard.Nm panic
43eb083802SRuslan Ermilov.Nd bring down system on fatal error
44d46ebd58SMike Pritchard.Sh SYNOPSIS
45e8b6bb6fSBruce Evans.In sys/types.h
46e8b6bb6fSBruce Evans.In sys/systm.h
47*d5e105bfSMitchell Horne.Vt extern char *panicstr;
48d46ebd58SMike Pritchard.Ft void
49d0353b83SRuslan Ermilov.Fn panic "const char *fmt" ...
50da10a603SMark Johnston.Ft void
51da10a603SMark Johnston.Fn vpanic "const char *fmt" "va_list ap"
52*d5e105bfSMitchell Horne.Fn KERNEL_PANICKED
53d46ebd58SMike Pritchard.Sh DESCRIPTION
54d46ebd58SMike PritchardThe
55d46ebd58SMike Pritchard.Fn panic
56da10a603SMark Johnstonand
57da10a603SMark Johnston.Fn vpanic
58da10a603SMark Johnstonfunctions terminate the running system.
59e8b6bb6fSBruce EvansThe message
60d46ebd58SMike Pritchard.Fa fmt
61d46ebd58SMike Pritchardis a
62d46ebd58SMike Pritchard.Xr printf 3
63e8b6bb6fSBruce Evansstyle format string.
64*d5e105bfSMitchell HorneThe message is printed to the console and
65*d5e105bfSMitchell Horne.Va panicstr
66*d5e105bfSMitchell Horneis set pointing to the address of the message text.
67*d5e105bfSMitchell HorneThis can be retrieved from a core dump at a later time.
68d46ebd58SMike Pritchard.Pp
69*d5e105bfSMitchell HorneUpon entering the
70*d5e105bfSMitchell Horne.Fn panic
71*d5e105bfSMitchell Hornefunction the panicking thread disables interrupts and calls
72*d5e105bfSMitchell Horne.Xr critical_enter 9 .
73*d5e105bfSMitchell HorneThis prevents the thread from being preempted or interrupted while the system
74*d5e105bfSMitchell Horneis still in a running state.
75*d5e105bfSMitchell HorneNext, it will instruct the other CPUs in the system to stop.
76*d5e105bfSMitchell HorneThis synchronizes with other threads to prevent concurrent panic conditions
77*d5e105bfSMitchell Hornefrom interfering with one another.
78*d5e105bfSMitchell HorneIn the unlikely event of concurrent panics, only one panicking thread will proceed.
79d46ebd58SMike Pritchard.Pp
80*d5e105bfSMitchell HorneControl will be passed to the kernel debugger via
81*d5e105bfSMitchell Horne.Fn kdb_enter .
82*d5e105bfSMitchell HorneThis is conditional on a debugger being installed and enabled by the
83*d5e105bfSMitchell Horne.Va debugger_on_panic
84*d5e105bfSMitchell Hornevariable; see
85*d5e105bfSMitchell Horne.Xr ddb 4
86*d5e105bfSMitchell Horneand
87*d5e105bfSMitchell Horne.Xr gdb 4 .
88*d5e105bfSMitchell HorneThe debugger may initiate a system reset, or it may eventually return.
89*d5e105bfSMitchell Horne.Pp
90*d5e105bfSMitchell HorneFinally,
91*d5e105bfSMitchell Horne.Xr kern_reboot 9
92*d5e105bfSMitchell Horneis called to restart the system, and a kernel dump will be requested.
93d46ebd58SMike PritchardIf
94d46ebd58SMike Pritchard.Fn panic
95*d5e105bfSMitchell Horneis called recursively (from the disk sync routines, for example),
96*d5e105bfSMitchell Horne.Fn kern_reboot
97*d5e105bfSMitchell Hornewill be instructed not to sync the disks.
98*d5e105bfSMitchell Horne.Pp
99*d5e105bfSMitchell HorneThe
100*d5e105bfSMitchell Horne.Fn vpanic
101*d5e105bfSMitchell Hornefunction implements the main body of
102*d5e105bfSMitchell Horne.Fn panic .
103*d5e105bfSMitchell HorneIt is suitable to be called by functions which perform their own
104*d5e105bfSMitchell Hornevariable-length argument processing.
105*d5e105bfSMitchell HorneIn all other cases,
106*d5e105bfSMitchell Horne.Fn panic
107*d5e105bfSMitchell Horneis preferred.
108*d5e105bfSMitchell Horne.Pp
109*d5e105bfSMitchell HorneThe
110*d5e105bfSMitchell Horne.Fn KERNEL_PANICKED
111*d5e105bfSMitchell Hornemacro is the preferred way to determine if the system has panicked.
112*d5e105bfSMitchell HorneIt returns a boolean value.
113*d5e105bfSMitchell HorneMost often this is used to avoid taking an action that cannot possibly succeed
114*d5e105bfSMitchell Hornein a panic context.
115*d5e105bfSMitchell Horne.Sh EXECUTION CONTEXT
116*d5e105bfSMitchell Horne.\" TODO: This text describes the kernel debugger / kernel dump execution
117*d5e105bfSMitchell Horne.\" context as well. It could be moved to a future kdb(9) page, and this
118*d5e105bfSMitchell Horne.\" section would become a pointer.
119*d5e105bfSMitchell HorneOnce the panic has been initiated, code executing in a panic context is subject
120*d5e105bfSMitchell Horneto the following restrictions:
121*d5e105bfSMitchell Horne.Bl -bullet
122*d5e105bfSMitchell Horne.It
123*d5e105bfSMitchell HorneSingle-threaded execution.
124*d5e105bfSMitchell HorneThe scheduler is disabled, and other CPUs are stopped/forced idle.
125*d5e105bfSMitchell HorneFunctions that manipulate the scheduler state must be avoided.
126*d5e105bfSMitchell HorneThis includes, but is not limited to,
127*d5e105bfSMitchell Horne.Xr wakeup 9
128*d5e105bfSMitchell Horneand
129*d5e105bfSMitchell Horne.Xr sleepqueue 9
130*d5e105bfSMitchell Hornefunctions.
131*d5e105bfSMitchell Horne.It
132*d5e105bfSMitchell HorneInterrupts are disabled.
133*d5e105bfSMitchell HorneDevice I/O (e.g. to the console) must be achieved with polling.
134*d5e105bfSMitchell Horne.It
135*d5e105bfSMitchell HorneDynamic memory allocation cannot be relied on, and must be avoided.
136*d5e105bfSMitchell Horne.It
137*d5e105bfSMitchell HorneLock acquisition/release will be ignored, meaning these operations will appear
138*d5e105bfSMitchell Horneto succeed.
139*d5e105bfSMitchell Horne.It
140*d5e105bfSMitchell HorneSleeping on a resource is not strictly prohibited, but will result in an
141*d5e105bfSMitchell Horneimmediate return from the sleep function.
142*d5e105bfSMitchell HorneTime-based sleeps such as
143*d5e105bfSMitchell Horne.Xr pause 9
144*d5e105bfSMitchell Hornemay be performed as a busy-wait.
145*d5e105bfSMitchell Horne.El
146d46ebd58SMike Pritchard.Sh RETURN VALUES
147d46ebd58SMike PritchardThe
148d46ebd58SMike Pritchard.Fn panic
149*d5e105bfSMitchell Horneand
150*d5e105bfSMitchell Horne.Fn vpanic
151*d5e105bfSMitchell Hornefunctions do not return.
152*d5e105bfSMitchell Horne.Sh SEE ALSO
153*d5e105bfSMitchell Horne.Xr printf 3 ,
154*d5e105bfSMitchell Horne.Xr ddb 4 ,
155*d5e105bfSMitchell Horne.Xr gdb 4 ,
156*d5e105bfSMitchell Horne.Xr KASSERT 9 ,
157*d5e105bfSMitchell Horne.Xr kern_reboot 9
158