Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Jul 2000 17:11:35 -0700 (PDT)
From:      kbyanc@posi.net
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/19720: more sysctl signed-ness patches
Message-ID:  <200007060011.RAA83029@kbyanc.corp.ONElist.com>

next in thread | raw e-mail | index | archive | help

>Number:         19720
>Category:       kern
>Synopsis:       more sysctl signed-ness patches
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 05 17:20:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Kelly Yancey
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
>Environment:

FreeBSD backroom.corp.ONElist.com 5.0-CURRENT FreeBSD 5.0-CURRENT #5: Wed
Jul  5 16:37:47 PDT 2000
root@backroom.corp.ONElist.com:/usr/src/sys/compile/BACKROOM  i386
 
>Description:

  Now that John has so graciously committed my unsigned sysctl patches,
here is a wave of patches to make more oids utilitize them. While scanning
for candidates, I also found several cases where ints should have been
u_ints in the code, so I fixed those while I was in there:

	hw.physmem	- you can surely put more than 2G of RAM in
	hw.usermem	  and x86 server which caused these to wrap.

	vm.stats.misc.cnt_prezero - a long-running server will
				    eventually pre-zero more than 2
				    billion pages...eventually

	kern.nselcoll	- again, left running long enough, the number of
			  select collisions can wrap to negative. However,
			  this was changed more for 'logistics'...you'll
			  never have a negative count, so why let it.

	debug.boothowto	- signed bitmask looked negative to sysctl

  This patch also includes a 'fix' for the alpha to print the memory stats
on boot as unsigned values. I was just being anal. You won't have negative
memory, on the other hand, it is unlikely you'll have more than 2^63 bytes
of RAM either.

  But the jist of the patch is making values that printed non-sensical
values in sysctl because of integer wrapping use the new unsigned sysctl
feature. Really, it's a simple patch, it just touches a lot of files.

  Kelly

>How-To-Repeat:

  Run `sysctl -a | grep boothowto`
  Put more than 2G of RAM in an x86 machine and run `sysctl -a | grep mem`.

>Fix:

Index: alpha/alpha/machdep.c
===================================================================
RCS file: /home/cvs/src/sys/alpha/alpha/machdep.c,v
retrieving revision 1.86
diff -u -r1.86 machdep.c
--- alpha/alpha/machdep.c	2000/07/04 11:24:59	1.86
+++ alpha/alpha/machdep.c	2000/07/05 23:23:09
@@ -186,11 +186,12 @@
 
 struct msgbuf *msgbufp=0;
 
-int bootverbose = 0, Maxmem = 0;
+int bootverbose = 0;
+u_int Maxmem = 0;
 long dumplo;
 
-int	totalphysmem;		/* total amount of physical memory in system */
-int	physmem;		/* physical memory used by NetBSD + some rsvd */
+u_int	totalphysmem;		/* total amount of physical memory in system */
+u_int	physmem;		/* physical memory used by NetBSD + some rsvd */
 int	resvmem;		/* amount of memory reserved for PROM */
 int	unusedmem;		/* amount of memory for OS that we don't use */
 int	unknownmem;		/* amount of memory with an unknown use */
@@ -206,7 +207,7 @@
 }
 
 SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_INT|CTLFLAG_RD,
-	0, 0, sysctl_hw_physmem, "I", "");
+	0, 0, sysctl_hw_physmem, "IU", "");
 
 static int
 sysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
@@ -219,7 +220,7 @@
 SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_INT|CTLFLAG_RD,
 	0, 0, sysctl_hw_usermem, "I", "");
 
-SYSCTL_INT(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "");
+SYSCTL_UINT(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "");
 
 /* must be 2 less so 0 0 can signal end of chunks */
 #define PHYS_AVAIL_ARRAY_END ((sizeof(phys_avail) / sizeof(vm_offset_t)) - 2)
@@ -267,7 +268,7 @@
 #ifdef PERFMON
 	perfmon_init();
 #endif
-	printf("real memory  = %ld (%ldK bytes)\n", alpha_ptob(Maxmem), alpha_ptob(Maxmem) / 1024);
+	printf("real memory  = %lu (%luK bytes)\n", alpha_ptob(Maxmem), alpha_ptob(Maxmem) / 1024);
 
 	/*
 	 * Display any holes after the first chunk of extended memory.
Index: alpha/alpha/vm_machdep.c
===================================================================
RCS file: /home/cvs/src/sys/alpha/alpha/vm_machdep.c,v
retrieving revision 1.32
diff -u -r1.32 vm_machdep.c
--- alpha/alpha/vm_machdep.c	2000/06/19 18:41:27	1.32
+++ alpha/alpha/vm_machdep.c	2000/07/05 20:45:22
@@ -381,9 +381,9 @@
 }
 
 
-static int cnt_prezero;
+static u_int cnt_prezero;
 
-SYSCTL_INT(_machdep, OID_AUTO, cnt_prezero, CTLFLAG_RD, &cnt_prezero, 0, "");
+SYSCTL_UINT(_machdep, OID_AUTO, cnt_prezero, CTLFLAG_RD, &cnt_prezero, 0, "");
 
 /*
  * Implement the pre-zeroed page mechanism.
Index: i386/i386/machdep.c
===================================================================
RCS file: /home/cvs/src/sys/i386/i386/machdep.c,v
retrieving revision 1.398
diff -u -r1.398 machdep.c
--- i386/i386/machdep.c	2000/07/04 11:25:17	1.398
+++ i386/i386/machdep.c	2000/07/05 23:26:04
@@ -150,7 +150,7 @@
 #endif
 SYSCTL_INT(_machdep, OID_AUTO, ispc98, CTLFLAG_RD, &ispc98, 0, "");
 
-int physmem = 0;
+u_int physmem = 0;
 int cold = 1;
 
 static void osendsig __P((sig_t catcher, int sig, sigset_t *mask, u_long code));
@@ -163,7 +163,7 @@
 }
 
 SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_INT|CTLFLAG_RD,
-	0, 0, sysctl_hw_physmem, "I", "");
+	0, 0, sysctl_hw_physmem, "IU", "");
 
 static int
 sysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
@@ -174,7 +174,7 @@
 }
 
 SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_INT|CTLFLAG_RD,
-	0, 0, sysctl_hw_usermem, "I", "");
+	0, 0, sysctl_hw_usermem, "IU", "");
 
 static int
 sysctl_hw_availpages(SYSCTL_HANDLER_ARGS)
Index: i386/i386/vm_machdep.c
===================================================================
RCS file: /home/cvs/src/sys/i386/i386/vm_machdep.c,v
retrieving revision 1.136
diff -u -r1.136 vm_machdep.c
--- i386/i386/vm_machdep.c	2000/06/10 02:05:57	1.136
+++ i386/i386/vm_machdep.c	2000/07/05 20:45:06
@@ -533,9 +533,9 @@
 
 SYSCTL_DECL(_vm_stats_misc);
 
-static int cnt_prezero;
+static u_int cnt_prezero;
 
-SYSCTL_INT(_vm_stats_misc, OID_AUTO,
+SYSCTL_UINT(_vm_stats_misc, OID_AUTO,
 	cnt_prezero, CTLFLAG_RD, &cnt_prezero, 0, "");
 
 /*
Index: kern/init_main.c
===================================================================
RCS file: /home/cvs/src/sys/kern/init_main.c,v
retrieving revision 1.136
diff -u -r1.136 init_main.c
--- kern/init_main.c	2000/06/25 10:14:06	1.136
+++ kern/init_main.c	2000/07/05 22:54:01
@@ -91,8 +91,8 @@
 extern	struct user *proc0paddr;
 
 struct	vnode *rootvp;
-int	boothowto = 0;		/* initialized so that it can be patched */
-SYSCTL_INT(_debug, OID_AUTO, boothowto, CTLFLAG_RD, &boothowto, 0, "");
+u_int	boothowto = 0;		/* initialized so that it can be patched */
+SYSCTL_UINT(_debug, OID_AUTO, boothowto, CTLFLAG_RD, &boothowto, 0, "");
 
 /*
  * Promiscuous argument pass for start_init()
Index: kern/kern_mib.c
===================================================================
RCS file: /home/cvs/src/sys/kern/kern_mib.c,v
retrieving revision 1.37
diff -u -r1.37 kern_mib.c
--- kern/kern_mib.c	2000/07/04 11:25:22	1.37
+++ kern/kern_mib.c	2000/07/05 20:50:20
@@ -187,8 +187,7 @@
     &domainname, sizeof(domainname), "Name of the current YP/NIS domain");
 
 long hostid;
-/* Some trouble here, if sizeof (int) != sizeof (long) */
-SYSCTL_INT(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID");
+SYSCTL_LONG(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID");
 
 /*
  * This is really cheating.  These actually live in the libc, something
Index: kern/kern_tc.c
===================================================================
RCS file: /home/cvs/src/sys/kern/kern_tc.c,v
retrieving revision 1.108
diff -u -r1.108 kern_tc.c
--- kern/kern_tc.c	2000/07/04 11:25:23	1.108
+++ kern/kern_tc.c	2000/07/05 20:52:19
@@ -49,14 +49,14 @@
 static unsigned nnanouptime;
 static unsigned ngetmicrouptime;
 static unsigned ngetnanouptime;
-SYSCTL_INT(_kern_timecounter, OID_AUTO, nmicrotime, CTLFLAG_RD, &nmicrotime, 0, "");
-SYSCTL_INT(_kern_timecounter, OID_AUTO, nnanotime, CTLFLAG_RD, &nnanotime, 0, "");
-SYSCTL_INT(_kern_timecounter, OID_AUTO, nmicrouptime, CTLFLAG_RD, &nmicrouptime, 0, "");
-SYSCTL_INT(_kern_timecounter, OID_AUTO, nnanouptime, CTLFLAG_RD, &nnanouptime, 0, "");
-SYSCTL_INT(_kern_timecounter, OID_AUTO, ngetmicrotime, CTLFLAG_RD, &ngetmicrotime, 0, "");
-SYSCTL_INT(_kern_timecounter, OID_AUTO, ngetnanotime, CTLFLAG_RD, &ngetnanotime, 0, "");
-SYSCTL_INT(_kern_timecounter, OID_AUTO, ngetmicrouptime, CTLFLAG_RD, &ngetmicrouptime, 0, "");
-SYSCTL_INT(_kern_timecounter, OID_AUTO, ngetnanouptime, CTLFLAG_RD, &ngetnanouptime, 0, "");
+SYSCTL_UINT(_kern_timecounter, OID_AUTO, nmicrotime, CTLFLAG_RD, &nmicrotime, 0, "");
+SYSCTL_UINT(_kern_timecounter, OID_AUTO, nnanotime, CTLFLAG_RD, &nnanotime, 0, "");
+SYSCTL_UINT(_kern_timecounter, OID_AUTO, nmicrouptime, CTLFLAG_RD, &nmicrouptime, 0, "");
+SYSCTL_UINT(_kern_timecounter, OID_AUTO, nnanouptime, CTLFLAG_RD, &nnanouptime, 0, "");
+SYSCTL_UINT(_kern_timecounter, OID_AUTO, ngetmicrotime, CTLFLAG_RD, &ngetmicrotime, 0, "");
+SYSCTL_UINT(_kern_timecounter, OID_AUTO, ngetnanotime, CTLFLAG_RD, &ngetnanotime, 0, "");
+SYSCTL_UINT(_kern_timecounter, OID_AUTO, ngetmicrouptime, CTLFLAG_RD, &ngetmicrouptime, 0, "");
+SYSCTL_UINT(_kern_timecounter, OID_AUTO, ngetnanouptime, CTLFLAG_RD, &ngetnanouptime, 0, "");
 
 /*
  * Implement a dummy timecounter which we can use until we get a real one
Index: kern/subr_kobj.c
===================================================================
RCS file: /home/cvs/src/sys/kern/subr_kobj.c,v
retrieving revision 1.2
diff -u -r1.2 subr_kobj.c
--- kern/subr_kobj.c	2000/05/01 10:45:15	1.2
+++ kern/subr_kobj.c	2000/07/05 20:56:49
@@ -47,12 +47,12 @@
 
 #include <sys/sysctl.h>
 
-int kobj_lookup_hits;
-int kobj_lookup_misses;
+u_int kobj_lookup_hits;
+u_int kobj_lookup_misses;
 
-SYSCTL_INT(_kern, OID_AUTO, kobj_hits, CTLFLAG_RD,
+SYSCTL_UINT(_kern, OID_AUTO, kobj_hits, CTLFLAG_RD,
 	   &kobj_lookup_hits, 0, "")
-SYSCTL_INT(_kern, OID_AUTO, kobj_misses, CTLFLAG_RD,
+SYSCTL_UINT(_kern, OID_AUTO, kobj_misses, CTLFLAG_RD,
 	   &kobj_lookup_misses, 0, "")
 
 #endif
Index: kern/sys_generic.c
===================================================================
RCS file: /home/cvs/src/sys/kern/sys_generic.c,v
retrieving revision 1.58
diff -u -r1.58 sys_generic.c
--- kern/sys_generic.c	2000/07/02 08:08:00	1.58
+++ kern/sys_generic.c	2000/07/05 20:57:59
@@ -603,9 +603,9 @@
 	return (error);
 }
 
-static int	nselcoll;	/* Select collisions since boot */
-int	selwait;
-SYSCTL_INT(_kern, OID_AUTO, nselcoll, CTLFLAG_RD, &nselcoll, 0, "");
+static u_int	nselcoll;	/* Select collisions since boot */
+u_int	selwait;
+SYSCTL_UINT(_kern, OID_AUTO, nselcoll, CTLFLAG_RD, &nselcoll, 0, "");
 
 /*
  * Select system call.
Index: kern/vfs_subr.c
===================================================================
RCS file: /home/cvs/src/sys/kern/vfs_subr.c,v
retrieving revision 1.264
diff -u -r1.264 vfs_subr.c
--- kern/vfs_subr.c	2000/07/04 11:25:23	1.264
+++ kern/vfs_subr.c	2000/07/05 21:18:43
@@ -138,6 +138,7 @@
 static int syncer_maxdelay = SYNCER_MAXDELAY;	/* maximum delay time */
 time_t syncdelay = 30;		/* max time to delay syncing data */
 time_t filedelay = 30;		/* time to delay syncing files */
+/* XXX time_t != int on all archetectures. */
 SYSCTL_INT(_kern, OID_AUTO, filedelay, CTLFLAG_RW, &filedelay, 0, "");
 time_t dirdelay = 29;		/* time to delay syncing directories */
 SYSCTL_INT(_kern, OID_AUTO, dirdelay, CTLFLAG_RW, &dirdelay, 0, "");
Index: pc98/i386/machdep.c
===================================================================
RCS file: /home/cvs/src/sys/pc98/i386/machdep.c,v
retrieving revision 1.166
diff -u -r1.166 machdep.c
--- pc98/i386/machdep.c	2000/07/04 11:25:33	1.166
+++ pc98/i386/machdep.c	2000/07/05 23:28:07
@@ -160,7 +160,7 @@
 #endif
 SYSCTL_INT(_machdep, OID_AUTO, ispc98, CTLFLAG_RD, &ispc98, 0, "");
 
-int physmem = 0;
+u_int physmem = 0;
 int cold = 1;
 
 static void osendsig __P((sig_t catcher, int sig, sigset_t *mask, u_long code));
@@ -173,7 +173,7 @@
 }
 
 SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_INT|CTLFLAG_RD,
-	0, 0, sysctl_hw_physmem, "I", "");
+	0, 0, sysctl_hw_physmem, "IU", "");
 
 static int
 sysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
@@ -184,7 +184,7 @@
 }
 
 SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_INT|CTLFLAG_RD,
-	0, 0, sysctl_hw_usermem, "I", "");
+	0, 0, sysctl_hw_usermem, "IU", "");
 
 static int
 sysctl_hw_availpages(SYSCTL_HANDLER_ARGS)
Index: sys/kobj.h
===================================================================
RCS file: /home/cvs/src/sys/sys/kobj.h,v
retrieving revision 1.4
diff -u -r1.4 kobj.h
--- sys/kobj.h	2000/05/11 17:10:22	1.4
+++ sys/kobj.h	2000/07/05 20:54:51
@@ -130,8 +130,8 @@
  * Maintain stats on hits/misses in lookup caches.
  */
 #ifdef KOBJ_STATS
-extern int kobj_lookup_hits;
-extern int kobj_lookup_misses;
+extern u_int kobj_lookup_hits;
+extern u_int kobj_lookup_misses;
 #define KOBJOPHIT	do { kobj_lookup_hits++; } while (0)
 #define KOBJOPMISS	do { kobj_lookup_misses++; } while (0)
 #else
Index: sys/sysctl.h
===================================================================
RCS file: /home/cvs/src/sys/sys/sysctl.h,v
retrieving revision 1.86
diff -u -r1.86 sysctl.h
--- sys/sysctl.h	2000/07/05 07:46:41	1.86
+++ sys/sysctl.h	2000/07/05 23:29:48
@@ -349,8 +349,8 @@
 #define	HW_MODEL	 2		/* string: specific machine model */
 #define	HW_NCPU		 3		/* int: number of cpus */
 #define	HW_BYTEORDER	 4		/* int: machine byte order */
-#define	HW_PHYSMEM	 5		/* int: total memory */
-#define	HW_USERMEM	 6		/* int: non-kernel memory */
+#define	HW_PHYSMEM	 5		/* uint: total memory */
+#define	HW_USERMEM	 6		/* uint: non-kernel memory */
 #define	HW_PAGESIZE	 7		/* int: software page size */
 #define	HW_DISKNAMES	 8		/* strings: disk drive names */
 #define	HW_DISKSTATS	 9		/* struct: diskstats[] */
Index: sys/systm.h
===================================================================
RCS file: /home/cvs/src/sys/sys/systm.h,v
retrieving revision 1.116
diff -u -r1.116 systm.h
--- sys/systm.h	2000/06/05 18:30:55	1.116
+++ sys/systm.h	2000/07/05 23:16:10
@@ -56,11 +56,12 @@
 
 extern int nswap;		/* size of swap space */
 
-extern int selwait;		/* select timeout address */
+extern u_int selwait;		/* select timeout address */
 
 extern u_char curpriority;	/* priority of current process */
 
-extern int physmem;		/* physical memory */
+/* XXX Should be segsz_t. */
+extern u_int physmem;		/* physical memory */
 
 extern dev_t dumpdev;		/* dump device */
 extern long dumplo;		/* offset into dumpdev */
@@ -70,7 +71,7 @@
 extern char *rootdevnames[2];	/* names of possible root devices */
 extern struct vnode *rootvp;	/* vnode equivalent to above */
 
-extern int boothowto;		/* reboot flags, from console subsystem */
+extern u_int boothowto;		/* reboot flags, from console subsystem */
 extern int bootverbose;		/* nonzero to print verbose messages */
 
 #ifdef	INVARIANTS		/* The option is always available */
Index: vm/vm_meter.c
===================================================================
RCS file: /home/cvs/src/sys/vm/vm_meter.c,v
retrieving revision 1.39
diff -u -r1.39 vm_meter.c
--- vm/vm_meter.c	2000/07/05 07:46:41	1.39
+++ vm/vm_meter.c	2000/07/05 20:19:52
@@ -309,7 +309,7 @@
 	v_pageout_free_min, CTLFLAG_RD, &cnt.v_pageout_free_min, 0, "");
 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,

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200007060011.RAA83029>