Module Name: src
Committed By: simonb
Date: Wed Mar 3 08:25:16 UTC 2021
Modified Files:
src/usr.bin/vmstat: vmstat.c
Log Message:
For vmstat -h/-H, calculate the hash element size correctly instead of
assuming that everything that isn't a list is a tailq. Fixes random
reads from kmem that either fail or return incorrect data for the vcache
hash table.
To generate a diff of this commit:
cvs rdiff -u -r1.242 -r1.243 src/usr.bin/vmstat/vmstat.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/vmstat/vmstat.c
diff -u src/usr.bin/vmstat/vmstat.c:1.242 src/usr.bin/vmstat/vmstat.c:1.243
--- src/usr.bin/vmstat/vmstat.c:1.242 Sun Jun 14 21:41:42 2020
+++ src/usr.bin/vmstat/vmstat.c Wed Mar 3 08:25:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.242 2020/06/14 21:41:42 ad Exp $ */
+/* $NetBSD: vmstat.c,v 1.243 2021/03/03 08:25:16 simonb Exp $ */
/*-
* Copyright (c) 1998, 2000, 2001, 2007, 2019, 2020
@@ -71,7 +71,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
#else
-__RCSID("$NetBSD: vmstat.c,v 1.242 2020/06/14 21:41:42 ad Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.243 2021/03/03 08:25:16 simonb Exp $");
#endif
#endif /* not lint */
@@ -1964,8 +1964,20 @@ dohashstat(int verbose, int todo, const
if (hashname != NULL &&
strcmp(hashnl[curhash->hashsize].n_name + 1, hashname))
continue;
- elemsize = curhash->type == HASH_LIST ?
- sizeof(*hashtbl_list) : sizeof(*hashtbl_tailq);
+ switch (curhash->type) {
+ case HASH_LIST:
+ elemsize = sizeof(*hashtbl_list);
+ break;
+ case HASH_SLIST:
+ elemsize = sizeof(*hashtbl_slist);
+ break;
+ case HASH_TAILQ:
+ elemsize = sizeof(*hashtbl_tailq);
+ break;
+ default:
+ /* shouldn't get here */
+ continue;
+ }
deref_kptr((void *)hashnl[curhash->hashsize].n_value,
&hashsize, sizeof(hashsize),
hashnl[curhash->hashsize].n_name);