Subject: Re: reproduceable "integer divide fault trap"
To: Christos Zoulas <christos@astron.com>
From: Jonathan A. Kollasch <jakllsch@kollasch.net>
List: netbsd-help
Date: 11/26/2005 22:08:07
--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

--liOOAslEiF7prFVr
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (NetBSD)

iD8DBQFDiTEmOjx1ye3hmokRAv+sAJ400OrhiHuAxctc2KQB9xr9YXdQ5ACfSm4j
OF6EaIam5SB7avtjbMvmTVk=
=dU8Y
-----END PGP SIGNATURE-----

--liOOAslEiF7prFVr--