Subject: install/17551: sysinst problems on >= 2GB machines
To: None <>
From: J.T. Conklin <>
List: netbsd-bugs
Date: 07/10/2002 16:16:45
>Number:         17551
>Category:       install
>Synopsis:       sysinst problems on >= 2GB machines
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    install-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 10 16:17:01 PDT 2002
>Originator:     J.T. Conklin
>Release:        netbsd-1-6 branch, 20020710
J.T. Conklin
System: NetBSD orac 1.5ZA NetBSD 1.5ZA (GENERIC.MP) #4: Fri May 31 21:31:21 PDT 2002 root@orac:/home/jtc/netbsd/NetBSD-current/syssrc/sys/arch/i386/compile/GENERIC.MP i386
Architecture: i386
Machine: i386
The sysinst program does not correctly compute the size of memory on
systems with 2 or more GB of RAM.  This causes all sorts of fun when
the value is used to derrive partition sizes, etc.

The enclosed patch casts the variable "ramsize" obtained from sysctl()
to an unsigned long.  It is my understanding (of the C Standard) that
once the int overflowed in ctob(physmem) in kern_sysctl.c:hw_sysctl()
we entered the land of undefined behavior.  But as a practical matter,
this tends to work.  It is perfectly OK in those situations (like one
of my systems) where physmem is not quite 2GB, where it's the the
computation of rammb in util.c itself that overflows the int.

As Perry Metzger pointed out when I mentioned this on tech-install,
the root cause of this is that sysctl() only supports a generic signed
"integer" type.  Even if we augmented that API to support an unsigned
integer types, we may run into the same problem if 32-bit machines
with more than 4GB memory become common.  I believe solving that
problem is beyond the scope of this PR.

Attempt to install netbsd 1.6 snapshot on a machine with >= 2GB memory

Index: util.c
RCS file: /cvsroot/basesrc/distrib/utils/sysinst/util.c,v
retrieving revision
diff -c -r1.67.2.3 util.c
*** util.c	2002/06/29 23:26:02
--- util.c	2002/07/10 22:41:27
*** 123,129 ****
  	sysctl(mib, 2, (void *)&ramsize, (size_t *)&len, NULL, 0);
  	/* Find out how many Megs ... round up. */
! 	rammb = (ramsize + MEG - 1) / MEG;
  static int asked = 0;
--- 123,129 ----
  	sysctl(mib, 2, (void *)&ramsize, (size_t *)&len, NULL, 0);
  	/* Find out how many Megs ... round up. */
! 	rammb = ((unsigned long) ramsize + MEG - 1) / MEG;
  static int asked = 0;