From owner-svn-src-all@freebsd.org Sat Jun 8 13:40:58 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1A3BE15A85A5; Sat, 8 Jun 2019 13:40:58 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AD3DA8B43D; Sat, 8 Jun 2019 13:40:57 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 85D8E1C332; Sat, 8 Jun 2019 13:40:57 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x58Devqw013601; Sat, 8 Jun 2019 13:40:57 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x58DevdV013600; Sat, 8 Jun 2019 13:40:57 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201906081340.x58DevdV013600@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 8 Jun 2019 13:40:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r348798 - head/sys/amd64/amd64 X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/amd64/amd64 X-SVN-Commit-Revision: 348798 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: AD3DA8B43D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.96)[-0.958,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Jun 2019 13:40:58 -0000 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