Subject: Re: reproduceable "integer divide fault trap"
To: Jonathan A. Kollasch <jakllsch@kollasch.net>
From: Christos Zoulas <christos@zoulas.com>
List: netbsd-help
Date: 11/27/2005 00:47:52
On Nov 26, 10:08pm, jakllsch@kollasch.net ("Jonathan A. Kollasch") wrote:
-- Subject: Re: reproduceable "integer divide fault trap"

| 
| --MIMEStream=_0+206302_2859488105_279768691225
| Content-Type: multipart/signed; micalg=pgp-sha1;
| 	protocol="application/pgp-signature"; boundary="liOOAslEiF7prFVr"
| Content-Disposition: inline
| 
| 
| --liOOAslEiF7prFVr
| Content-Type: text/plain; charset=us-ascii
| Content-Disposition: inline
| 
| On Sun, Nov 27, 2005 at 01:32:43AM +0000, Christos Zoulas wrote:
| > Add some printf's in ffs_alloc.c:ffs_dirpref to see what causes the
| > zerodivide.
| 
| It's the line 'maxcontigdirs = min(cgsize / dirsize, 255);'.
| 
| fs->fs_avgfilesize and fs->fs_avgfpdir are non-zero; one is
| 0x40000000 the other is 0x20 (I set both of those values in newfs).
| However by the time it gets to the trouble line dirsize is zero.
| 
| 
|         cgsize = fs->fs_fsize * fs->fs_fpg;
|         dirsize = fs->fs_avgfilesize * fs->fs_avgfpdir;
| # fs->fs_avgfilesize == 0x40000000, fs->fs_avgfpdir == 0x20
| # avgndir == 0, cgsize == 0xFFFFFFFFEF620000, avgbfree == 0x30B59
| # fs->fs_bsize == 0x10000
|         curdirsize = avgndir ? (cgsize - avgbfree * fs->fs_bsize) / avgndir : 0;
| # curdirsize == 0
|         if (dirsize < curdirsize)
|                 dirsize = curdirsize;
| # dirsize == 0
|         maxcontigdirs = min(cgsize / dirsize, 255);
| 
| I'm just guessing but it looks like the the "if x < y" line is getting executed
| wrong. It's a compare between a 64-bit and 32-bit quantity but that shouldn't
| matter. If I executed it in my head right it should work fine on the CPU,
| assuming gcc works properly. I hope you can make sense of this.
| 
| 	Jonathan Kollasch

Good catch. I think that is a gcc bug. Can you try changing the code
so that the comparison is between 2 64 bit quantities?

christos