From 4a99fefea757bdfb28fd8a0089c829612b505ac9 Mon Sep 17 00:00:00 2001 From: marius Date: Sat, 2 Mar 2013 17:39:20 +0000 Subject: [PATCH] MFC: r246689, r246696 Make SYSCTL_{LONG,QUAD,ULONG,UQUAD}(9) work as advertised and also handle constant values. Reviewed by: kib git-svn-id: svn://svn.freebsd.org/base/stable/8@247657 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/kern/kern_sysctl.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 76f8b81f5..88bc1e661 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -992,7 +992,10 @@ sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS) /* - * Handle a long, signed or unsigned. arg1 points to it. + * Handle a long, signed or unsigned. + * Two cases: + * a variable: point arg1 at it. + * a constant: pass it in arg2. */ int @@ -1007,9 +1010,10 @@ sysctl_handle_long(SYSCTL_HANDLER_ARGS) /* * Attempt to get a coherent snapshot by making a copy of the data. */ - if (!arg1) - return (EINVAL); - tmplong = *(long *)arg1; + if (arg1) + tmplong = *(long *)arg1; + else + tmplong = arg2; #ifdef SCTL_MASK32 if (req->flags & SCTL_MASK32) { tmpint = tmplong; @@ -1021,18 +1025,24 @@ sysctl_handle_long(SYSCTL_HANDLER_ARGS) if (error || !req->newptr) return (error); + if (!arg1) + error = EPERM; #ifdef SCTL_MASK32 - if (req->flags & SCTL_MASK32) { + else if (req->flags & SCTL_MASK32) { error = SYSCTL_IN(req, &tmpint, sizeof(int)); *(long *)arg1 = (long)tmpint; - } else + } #endif + else error = SYSCTL_IN(req, arg1, sizeof(long)); return (error); } /* - * Handle a 64 bit int, signed or unsigned. arg1 points to it. + * Handle a 64 bit int, signed or unsigned. + * Two cases: + * a variable: point arg1 at it. + * a constant: pass it in arg2. */ int @@ -1044,15 +1054,19 @@ sysctl_handle_quad(SYSCTL_HANDLER_ARGS) /* * Attempt to get a coherent snapshot by making a copy of the data. */ - if (!arg1) - return (EINVAL); - tmpout = *(uint64_t *)arg1; + if (arg1) + tmpout = *(uint64_t *)arg1; + else + tmpout = arg2; error = SYSCTL_OUT(req, &tmpout, sizeof(uint64_t)); if (error || !req->newptr) return (error); - error = SYSCTL_IN(req, arg1, sizeof(uint64_t)); + if (!arg1) + error = EPERM; + else + error = SYSCTL_IN(req, arg1, sizeof(uint64_t)); return (error); } -- 2.45.0