From owner-freebsd-bugs Sat Dec 4 0:10:15 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 1E61B15349 for ; Sat, 4 Dec 1999 00:10:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id AAA53242; Sat, 4 Dec 1999 00:10:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from kronos.alcnet.com (kronos.alcnet.com [63.69.28.22]) by hub.freebsd.org (Postfix) with ESMTP id 117B315347 for ; Sat, 4 Dec 1999 00:04:36 -0800 (PST) (envelope-from kbyanc@kronos.alcnet.com) Received: (from kbyanc@localhost) by kronos.alcnet.com (8.9.3/8.9.3/antispam) id DAA92493; Sat, 4 Dec 1999 03:04:33 -0500 (EST) Message-Id: <199912040804.DAA92493@kronos.alcnet.com> Date: Sat, 4 Dec 1999 03:04:33 -0500 (EST) From: kbyanc@posi.net Reply-To: kbyanc@posi.net To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: kern/15251: patch to add unsigned support to sysctl Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 15251 >Category: kern >Synopsis: patch to add unsigned support to sysctl >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Dec 4 00:10:01 PST 1999 >Closed-Date: >Last-Modified: >Originator: Kelly Yancey >Release: FreeBSD 3.2-STABLE i386 >Organization: >Environment: 3.3-STABLE, but review of -current sources via cvs-web show the same problems there. >Description: The sysctl interface wasn't providing signed-ness along with type information in oid_fmt. This caused /sbin/sysctl to erroniously display some values as signed when they are in fact unsigned. Unrelated, these patches also address the problem where in /sys/kern/vfs_cache.c is was registering sysctls as integer types when they were in fact longs. While this isn't a problem on i386 where ints and longs are the same size, on alpha this should cause erronious values to be displayed by sysctl. >How-To-Repeat: kern.ps_strings and kern.usrstack are always negative. Run sysctl -a on a box that has been running for a long time, and you will most likely notice negative counts in one of the vm.stats.sys variables. >Fix: Here is a rather sizeable patch which touches the following files: src/sys/sys/sysctl.h Adds SYSCTL_UINT and SYSCTL_ULONG to provide friendly interfaces to the new unsigned int and unsigned long oid formats. The strings "IU" and "LU" are used as oid_fmt identifiers respectively. src/sbin/sysctl/sysctl.c Added support for the new "IU" and "LU" format strings. Also, fixed the displaying of dev_t to treat it as unsigned (as it is defined). src/sys/kern/vfs_cache.c Fixed problem noted above to export u_long-typed variables as unsigned longs rather than (signed) ints. src/sys/kern/kern_exec.c Fixed kern.ps_strings and kern.usrstack to be registered with SYSCTL_ULONG rather than SYSCTL_LONG. I also noted that both ps_strings and usrstack, which are defined as type "long" really should be "vm_size_t". However, I didn't make the change myself because I'de rather someone wiser to comment on the change first :) src/sys/kern/vm_meter.c Fixed the export of all the vm.stats.sys.* tree to use the new SYSCTL_UINT registration hook since all of the source values are unsigned. --- sys/kern/vfs_cache.c.orig Sat Dec 4 01:31:04 1999 +++ sys/kern/vfs_cache.c Sat Dec 4 02:27:14 1999 @@ -72,13 +72,13 @@ static LIST_HEAD(nchashhead, namecache) *nchashtbl; /* Hash Table */ static TAILQ_HEAD(, namecache) ncneg; /* Hash Table */ static u_long nchash; /* size of hash table */ -SYSCTL_INT(_debug, OID_AUTO, nchash, CTLFLAG_RD, &nchash, 0, ""); +SYSCTL_ULONG(_debug, OID_AUTO, nchash, CTLFLAG_RD, &nchash, ""); static u_long ncnegfactor = 16; /* ratio of negative entries */ -SYSCTL_INT(_debug, OID_AUTO, ncnegfactor, CTLFLAG_RW, &ncnegfactor, 0, ""); +SYSCTL_ULONG(_debug, OID_AUTO, ncnegfactor, CTLFLAG_RW, &ncnegfactor, ""); static u_long numneg; /* number of cache entries allocated */ -SYSCTL_INT(_debug, OID_AUTO, numneg, CTLFLAG_RD, &numneg, 0, ""); +SYSCTL_ULONG(_debug, OID_AUTO, numneg, CTLFLAG_RD, &numneg, ""); static u_long numcache; /* number of cache entries allocated */ -SYSCTL_INT(_debug, OID_AUTO, numcache, CTLFLAG_RD, &numcache, 0, ""); +SYSCTL_ULONG(_debug, OID_AUTO, numcache, CTLFLAG_RD, &numcache, ""); struct nchstats nchstats; /* cache effectiveness statistics */ static int doingcache = 1; /* 1 => enable the cache */ @@ -91,7 +91,7 @@ */ SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW, 0, "Name cache statistics"); #define STATNODE(mode, name, var) \ - SYSCTL_INT(_vfs_cache, OID_AUTO, name, mode, var, 0, ""); + SYSCTL_ULONG(_vfs_cache, OID_AUTO, name, mode, var, ""); STATNODE(CTLFLAG_RD, numneg, &numneg); STATNODE(CTLFLAG_RD, numcache, &numcache); static u_long numcalls; STATNODE(CTLFLAG_RD, numcalls, &numcalls); --- sys/vm/vm_meter.c.orig Sat Dec 4 02:16:54 1999 +++ sys/vm/vm_meter.c Sat Dec 4 02:22:40 1999 @@ -105,19 +105,19 @@ wakeup(&proc0); } -SYSCTL_INT(_vm, VM_V_FREE_MIN, v_free_min, +SYSCTL_UINT(_vm, VM_V_FREE_MIN, v_free_min, CTLFLAG_RW, &cnt.v_free_min, 0, ""); -SYSCTL_INT(_vm, VM_V_FREE_TARGET, v_free_target, +SYSCTL_UINT(_vm, VM_V_FREE_TARGET, v_free_target, CTLFLAG_RW, &cnt.v_free_target, 0, ""); -SYSCTL_INT(_vm, VM_V_FREE_RESERVED, v_free_reserved, +SYSCTL_UINT(_vm, VM_V_FREE_RESERVED, v_free_reserved, CTLFLAG_RW, &cnt.v_free_reserved, 0, ""); -SYSCTL_INT(_vm, VM_V_INACTIVE_TARGET, v_inactive_target, +SYSCTL_UINT(_vm, VM_V_INACTIVE_TARGET, v_inactive_target, CTLFLAG_RW, &cnt.v_inactive_target, 0, ""); -SYSCTL_INT(_vm, VM_V_CACHE_MIN, v_cache_min, +SYSCTL_UINT(_vm, VM_V_CACHE_MIN, v_cache_min, CTLFLAG_RW, &cnt.v_cache_min, 0, ""); -SYSCTL_INT(_vm, VM_V_CACHE_MAX, v_cache_max, +SYSCTL_UINT(_vm, VM_V_CACHE_MAX, v_cache_max, CTLFLAG_RW, &cnt.v_cache_max, 0, ""); -SYSCTL_INT(_vm, VM_V_PAGEOUT_FREE_MIN, v_pageout_free_min, +SYSCTL_UINT(_vm, VM_V_PAGEOUT_FREE_MIN, v_pageout_free_min, CTLFLAG_RW, &cnt.v_pageout_free_min, 0, ""); SYSCTL_STRUCT(_vm, VM_LOADAVG, loadavg, CTLFLAG_RD, &averunnable, loadavg, ""); @@ -221,87 +221,87 @@ SYSCTL_NODE(_vm_stats, OID_AUTO, sys, CTLFLAG_RW, 0, "VM meter sys stats"); SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW, 0, "VM meter vm stats"); SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW, 0, "VM meter misc stats"); -SYSCTL_INT(_vm_stats_sys, OID_AUTO, +SYSCTL_UINT(_vm_stats_sys, OID_AUTO, v_swtch, CTLFLAG_RD, &cnt.v_swtch, 0, "Context switches"); -SYSCTL_INT(_vm_stats_sys, OID_AUTO, +SYSCTL_UINT(_vm_stats_sys, OID_AUTO, v_trap, CTLFLAG_RD, &cnt.v_trap, 0, "Traps"); -SYSCTL_INT(_vm_stats_sys, OID_AUTO, +SYSCTL_UINT(_vm_stats_sys, OID_AUTO, v_syscall, CTLFLAG_RD, &cnt.v_syscall, 0, "Syscalls"); -SYSCTL_INT(_vm_stats_sys, OID_AUTO, +SYSCTL_UINT(_vm_stats_sys, OID_AUTO, v_intr, CTLFLAG_RD, &cnt.v_intr, 0, "HW intr"); -SYSCTL_INT(_vm_stats_sys, OID_AUTO, +SYSCTL_UINT(_vm_stats_sys, OID_AUTO, v_soft, CTLFLAG_RD, &cnt.v_soft, 0, "SW intr"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_vm_faults, CTLFLAG_RD, &cnt.v_vm_faults, 0, "VM faults"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_cow_faults, CTLFLAG_RD, &cnt.v_cow_faults, 0, "COW faults"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_cow_optim, CTLFLAG_RD, &cnt.v_cow_optim, 0, "Optimized COW faults"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_zfod, CTLFLAG_RD, &cnt.v_zfod, 0, "Zero fill"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_ozfod, CTLFLAG_RD, &cnt.v_ozfod, 0, "Optimized zero fill"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_swapin, CTLFLAG_RD, &cnt.v_swapin, 0, "Swapin operations"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_swapout, CTLFLAG_RD, &cnt.v_swapout, 0, "Swapout operations"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_swappgsin, CTLFLAG_RD, &cnt.v_swappgsin, 0, "Swapin pages"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_swappgsout, CTLFLAG_RD, &cnt.v_swappgsout, 0, "Swapout pages"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_vnodein, CTLFLAG_RD, &cnt.v_vnodein, 0, "Vnodein operations"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_vnodeout, CTLFLAG_RD, &cnt.v_vnodeout, 0, "Vnodeout operations"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_vnodepgsin, CTLFLAG_RD, &cnt.v_vnodepgsin, 0, "Vnodein pages"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_vnodepgsout, CTLFLAG_RD, &cnt.v_vnodepgsout, 0, "Vnodeout pages"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_intrans, CTLFLAG_RD, &cnt.v_intrans, 0, "In transit page blocking"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_reactivated, CTLFLAG_RD, &cnt.v_reactivated, 0, "Reactivated pages"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_pdwakeups, CTLFLAG_RD, &cnt.v_pdwakeups, 0, "Pagedaemon wakeups"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_pdpages, CTLFLAG_RD, &cnt.v_pdpages, 0, "Pagedaemon page scans"); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_dfree, CTLFLAG_RD, &cnt.v_dfree, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_pfree, CTLFLAG_RD, &cnt.v_pfree, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_tfree, CTLFLAG_RD, &cnt.v_tfree, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_page_size, CTLFLAG_RD, &cnt.v_page_size, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_page_count, CTLFLAG_RD, &cnt.v_page_count, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_free_reserved, CTLFLAG_RD, &cnt.v_free_reserved, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_free_target, CTLFLAG_RD, &cnt.v_free_target, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_free_min, CTLFLAG_RD, &cnt.v_free_min, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_free_count, CTLFLAG_RD, &cnt.v_free_count, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_wire_count, CTLFLAG_RD, &cnt.v_wire_count, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_active_count, CTLFLAG_RD, &cnt.v_active_count, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_inactive_target, CTLFLAG_RD, &cnt.v_inactive_target, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_inactive_count, CTLFLAG_RD, &cnt.v_inactive_count, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_cache_count, CTLFLAG_RD, &cnt.v_cache_count, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_cache_min, CTLFLAG_RD, &cnt.v_cache_min, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_cache_max, CTLFLAG_RD, &cnt.v_cache_max, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_pageout_free_min, CTLFLAG_RD, &cnt.v_pageout_free_min, 0, ""); -SYSCTL_INT(_vm_stats_vm, OID_AUTO, +SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_interrupt_free_min, CTLFLAG_RD, &cnt.v_interrupt_free_min, 0, ""); -SYSCTL_INT(_vm_stats_misc, OID_AUTO, +SYSCTL_UINT(_vm_stats_misc, OID_AUTO, zero_page_count, CTLFLAG_RD, &vm_page_zero_count, 0, ""); #if 0 SYSCTL_INT(_vm_stats_misc, OID_AUTO, --- sys/kern/kern_exec.c.orig Sat Dec 4 02:06:41 1999 +++ sys/kern/kern_exec.c Sat Dec 4 02:30:13 1999 @@ -66,11 +66,13 @@ static long *exec_copyout_strings __P((struct image_params *)); -static long ps_strings = PS_STRINGS; -SYSCTL_LONG(_kern, KERN_PS_STRINGS, ps_strings, CTLFLAG_RD, &ps_strings, ""); +/* XXX This should be vm_size_t. */ +static u_long ps_strings = PS_STRINGS; +SYSCTL_ULONG(_kern, KERN_PS_STRINGS, ps_strings, CTLFLAG_RD, &ps_strings, ""); -static long usrstack = USRSTACK; -SYSCTL_LONG(_kern, KERN_USRSTACK, usrstack, CTLFLAG_RD, &usrstack, ""); +/* XXX This should be vm_size_t. */ +static u_long usrstack = USRSTACK; +SYSCTL_ULONG(_kern, KERN_USRSTACK, usrstack, CTLFLAG_RD, &usrstack, ""); /* * Each of the items is a pointer to a `const struct execsw', hence the --- sys/sys/sysctl.h.orig Sat Dec 4 01:26:11 1999 +++ sys/sys/sysctl.h Sat Dec 4 01:32:15 1999 @@ -156,10 +156,20 @@ SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \ ptr, val, sysctl_handle_int, "I", descr) +/* Oid for an unsigned int. If ptr is NULL, val is returned. */ +#define SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \ + ptr, val, sysctl_handle_int, "IU", descr) + /* Oid for a long. The pointer must be non NULL. */ #define SYSCTL_LONG(parent, nbr, name, access, ptr, descr) \ SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \ ptr, 0, sysctl_handle_long, "L", descr) + +/* Oid for an unsigned long. The pointer must be non NULL. */ +#define SYSCTL_ULONG(parent, nbr, name, access, ptr, descr) \ + SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|access, \ + ptr, 0, sysctl_handle_long, "LU", descr) /* Oid for an opaque object. Specified by a pointer and a length. */ #define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \ --- sbin/sysctl/sysctl.c.orig Sat Dec 4 01:34:13 1999 +++ sbin/sysctl/sysctl.c Sat Dec 4 02:01:59 1999 @@ -270,7 +270,7 @@ dev_t *d = (dev_t *)p; if (l2 != sizeof *d) err(1, "T_dev_T %d != %d", l2, sizeof *d); - printf("{ major = %d, minor = %d }", + printf("{ major = %u, minor = %u }", major(*d), minor(*d)); return (0); } @@ -392,9 +392,13 @@ case 'I': if (!nflag) printf("%s: ", name); + fmt++; val = ""; while (len >= sizeof(int)) { - printf("%s%d", val, *(int *)p); + if(*fmt == 'U') + printf("%s%u", val, *(unsigned int *)p); + else + printf("%s%d", val, *(int *)p); val = " "; len -= sizeof (int); p += sizeof (int); @@ -404,7 +408,11 @@ case 'L': if (!nflag) printf("%s: ", name); - printf("%ld", *(long *)p); + fmt++; + if(*fmt == 'U') + printf("%lu", *(unsigned long *)p); + else + printf("%ld", *(long *)p); return (0); case 'P': >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message