svn commit: r348798 - head/sys/amd64/amd64
Konstantin Belousov
kib at FreeBSD.org
Sat Jun 8 13:40:58 UTC 2019
Author: kib
Date: Sat Jun 8 13:40:57 2019
New Revision: 348798
URL: https://svnweb.freebsd.org/changeset/base/348798
Log:
amd64 trap.c: Modernize syntax around trap_msg[].
Convert the array to use C99 initializers.
Make it constant.
Replace MAX_TRAP_MSG with nitems().
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Modified:
head/sys/amd64/amd64/trap.c
Modified: head/sys/amd64/amd64/trap.c
==============================================================================
--- head/sys/amd64/amd64/trap.c Sat Jun 8 09:34:02 2019 (r348797)
+++ head/sys/amd64/amd64/trap.c Sat Jun 8 13:40:57 2019 (r348798)
@@ -118,41 +118,41 @@ static bool trap_user_dtrace(struct trapframe *,
int (**hook)(struct trapframe *));
#endif
-#define MAX_TRAP_MSG 32
-static char *trap_msg[] = {
- "", /* 0 unused */
- "privileged instruction fault", /* 1 T_PRIVINFLT */
- "", /* 2 unused */
- "breakpoint instruction fault", /* 3 T_BPTFLT */
- "", /* 4 unused */
- "", /* 5 unused */
- "arithmetic trap", /* 6 T_ARITHTRAP */
- "", /* 7 unused */
- "", /* 8 unused */
- "general protection fault", /* 9 T_PROTFLT */
- "debug exception", /* 10 T_TRCTRAP */
- "", /* 11 unused */
- "page fault", /* 12 T_PAGEFLT */
- "", /* 13 unused */
- "alignment fault", /* 14 T_ALIGNFLT */
- "", /* 15 unused */
- "", /* 16 unused */
- "", /* 17 unused */
- "integer divide fault", /* 18 T_DIVIDE */
- "non-maskable interrupt trap", /* 19 T_NMI */
- "overflow trap", /* 20 T_OFLOW */
- "FPU bounds check fault", /* 21 T_BOUND */
- "FPU device not available", /* 22 T_DNA */
- "double fault", /* 23 T_DOUBLEFLT */
- "FPU operand fetch fault", /* 24 T_FPOPFLT */
- "invalid TSS fault", /* 25 T_TSSFLT */
- "segment not present fault", /* 26 T_SEGNPFLT */
- "stack fault", /* 27 T_STKFLT */
- "machine check trap", /* 28 T_MCHK */
- "SIMD floating-point exception", /* 29 T_XMMFLT */
- "reserved (unknown) fault", /* 30 T_RESERVED */
- "", /* 31 unused (reserved) */
- "DTrace pid return trap", /* 32 T_DTRACE_RET */
+static const char UNKNOWN[] = "unknown";
+static const char *trap_msg[] = {
+ [0] = UNKNOWN, /* unused */
+ [T_PRIVINFLT] = "privileged instruction fault",
+ [2] = UNKNOWN, /* unused */
+ [T_BPTFLT] = "breakpoint instruction fault",
+ [4] = UNKNOWN, /* unused */
+ [5] = UNKNOWN, /* unused */
+ [T_ARITHTRAP] = "arithmetic trap",
+ [7] = UNKNOWN, /* unused */
+ [8] = UNKNOWN, /* unused */
+ [T_PROTFLT] = "general protection fault",
+ [T_TRCTRAP] = "debug exception",
+ [11] = UNKNOWN, /* unused */
+ [T_PAGEFLT] = "page fault",
+ [13] = UNKNOWN, /* unused */
+ [T_ALIGNFLT] = "alignment fault",
+ [15] = UNKNOWN, /* unused */
+ [16] = UNKNOWN, /* unused */
+ [17] = UNKNOWN, /* unused */
+ [T_DIVIDE] = "integer divide fault",
+ [T_NMI] = "non-maskable interrupt trap",
+ [T_OFLOW] = "overflow trap",
+ [T_BOUND] = "FPU bounds check fault",
+ [T_DNA] = "FPU device not available",
+ [T_DOUBLEFLT] = "double fault",
+ [T_FPOPFLT] = "FPU operand fetch fault",
+ [T_TSSFLT] = "invalid TSS fault",
+ [T_SEGNPFLT] = "segment not present fault",
+ [T_STKFLT] = "stack fault",
+ [T_MCHK] = "machine check trap",
+ [T_XMMFLT] = "SIMD floating-point exception",
+ [T_RESERVED] = "reserved (unknown) fault",
+ [31] = UNKNOWN, /* reserved */
+ [T_DTRACE_RET] = "DTrace pid return trap",
};
static int prot_fault_translation;
@@ -879,7 +879,6 @@ trap_fatal(frame, eva)
int code, ss;
u_int type;
struct soft_segment_descriptor softseg;
- char *msg;
#ifdef KDB
bool handled;
#endif
@@ -889,11 +888,8 @@ trap_fatal(frame, eva)
sdtossd(&gdt[NGDT * PCPU_GET(cpuid) + IDXSEL(frame->tf_cs & 0xffff)],
&softseg);
- if (type <= MAX_TRAP_MSG)
- msg = trap_msg[type];
- else
- msg = "UNKNOWN";
- printf("\n\nFatal trap %d: %s while in %s mode\n", type, msg,
+ printf("\n\nFatal trap %d: %s while in %s mode\n", type,
+ type < nitems(trap_msg) ? trap_msg[type] : UNKNOWN,
TRAPF_USERMODE(frame) ? "user" : "kernel");
#ifdef SMP
/* two separate prints in case of a trap on an unmapped page */
@@ -944,10 +940,8 @@ trap_fatal(frame, eva)
}
#endif
printf("trap number = %d\n", type);
- if (type <= MAX_TRAP_MSG)
- panic("%s", trap_msg[type]);
- else
- panic("unknown/reserved trap");
+ panic("%s", type < nitems(trap_msg) ? trap_msg[type] :
+ "unknown/reserved trap");
}
#ifdef KDTRACE_HOOKS
More information about the svn-src-head
mailing list