[MLton] Crash with 4GB ram

Alain Deutsch deutsch@PolySpace.com
Wed, 17 Dec 2003 14:44:08 +0100

We have a crash of an mlton-20030716 generated executable when run on a 
Sun with 4Gb RAM.
One of our engineers suspects it is due to an overflow in the following 

static void setMemInfo (GC_state s) {
        struct anoninfo anon;

        s->totalRam = sysconf (_SC_PHYS_PAGES) * s->pageSize;
        if (-1 == swapctl (SC_AINFO, &anon))
                /* Couldn't get swap, so assume that there's as much swap as
                 * there is RAM.
                s->totalSwap = s->totalRam;
                s->totalSwap = anon.ani_max * s->pageSize;

If totalRAM is equal to 4Gb, the above multiplication result will indeed 
wrap around to zero.
I suspect the same problem can occur with totalSwap, and in various 
places in the code where totalRam+totalSwap is computed without 
promotion to 64bits.

Would it be worthwhile to change the type of totalRam and totalSwap to 
unsigned long long, as well as to promote various computations in gc.c 
to 64 bits ?

Alain Deutsch, CTO              tel.: +33 (0)1 49 65 32 64
PolySpace Technologies          fax.: +33 (0)1 49 65 05 77
mailto:deutsch@POLYSPACE.COM    http://www.polyspace.com