From 968d925976275b4e085426c697a7931cb65668c9 Mon Sep 17 00:00:00 2001 From: bluhm Date: Fri, 7 Jul 2023 16:27:46 +0000 Subject: [PATCH] Expand the counters in struct mbstat from u_short to u_long. Use malloc(9) memory instead of kernel stack for sysctl kern.mbstat. from yasuoka@; chunk missed in previous commit; OK claudio@ tb@ --- sys/kern/kern_sysctl.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 2c79d238113..b71f9824be1 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.416 2023/07/02 19:02:27 cheloha Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.417 2023/07/07 16:27:46 bluhm Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -515,20 +515,22 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case KERN_MBSTAT: { extern struct cpumem *mbstat; uint64_t counters[MBSTAT_COUNT]; - struct mbstat mbs; + struct mbstat *mbs; unsigned int i; + int ret; - memset(&mbs, 0, sizeof(mbs)); + mbs = malloc(sizeof(*mbs), M_TEMP, M_WAITOK | M_ZERO); counters_read(mbstat, counters, MBSTAT_COUNT); for (i = 0; i < MBSTAT_TYPES; i++) - mbs.m_mtypes[i] = counters[i]; + mbs->m_mtypes[i] = counters[i]; - mbs.m_drops = counters[MBSTAT_DROPS]; - mbs.m_wait = counters[MBSTAT_WAIT]; - mbs.m_drain = counters[MBSTAT_DRAIN]; + mbs->m_drops = counters[MBSTAT_DROPS]; + mbs->m_wait = counters[MBSTAT_WAIT]; + mbs->m_drain = counters[MBSTAT_DRAIN]; - return (sysctl_rdstruct(oldp, oldlenp, newp, - &mbs, sizeof(mbs))); + ret = sysctl_rdstruct(oldp, oldlenp, newp, mbs, sizeof(*mbs)); + free(mbs, M_TEMP, sizeof(*mbs)); + return (ret); } case KERN_MSGBUFSIZE: case KERN_CONSBUFSIZE: { -- 2.20.1