> < ^ Date: Mon, 09 Nov 1992 20:17:41 +0100
> < ^ From: Martin Schoenert <martin.schoenert@math.rwth-aachen.de >
< ^ Subject: Re: Corrupted heap.

Werner Nickel writes in his message of 06-Nov-92:

A while ago there was a bit of discussion about GAP's Error message

gap: panic 'SyGetmem' detected corrupted heap!

Martin Schoenert explained that GAP basically produces this error
message if it detects that some subroutine interferes with GAP's
storage management. I just got this error message from GAP. In
trying to understand why, I discovered that there is an implicit
assumption made about sbrk() in the routine SyGetmem(). This
assumption does not seem to be satisfied in SunOS 4.1.1.

SyGetmem() contains the following line of code:

if ( ret != (char*)-1 )  syHighmem = ret + size;

This line of code assumes that the new break value (assigned to
'syHighmem') is equal to the old break value (stored in 'ret')
plus 'size' (the argument to SyGetmem()). That means it assumes
that the alignment of 'size' is consistent with the alignment that
sbrk() enforces.
But on SunOS 4.1.1 it seems to be the case that sbrk() aligns the
additional memory to a multiple of 8 while 'size' is only
guaranteed to be divisible by 4. Therefore in the next call of
SyGetmem() there can be a discrepancy of 4 bytes between syHighmem
and the value returned by sbrk() in which case GAP believes that
the heap is corrupted. This was precisely the reason why GAP gave me
the error message above.

My suggestion is to remove this implicit assumption by replacing that
line of code by the following:

if ( ret != (char*)-1 )  syHighmem = sbrk(0);

Thanks for this patch Werner. I was under the impression that Gasman
(GAP's storage manager) would only try to allocate memory in increments
that are a multiple of 1024 bytes large. Since I assumed (and still do)
that this is consistent with the alignment restrictions on almost all
systems, it never occured to me that 'syHighmem = ret + size;' might
cause the problem. I will use your patch (and also change Gasman, so
that my original assumption holds).

Martin.

-- .- .-. - .. -.  .-.. --- ...- . ...  .- -. -. .. -.- .-
Martin Sch"onert,   Martin.Schoenert@Math.RWTH-Aachen.DE,  +49 241 804551
Lehrstuhl D f"ur Mathematik, Templergraben 64, RWTH, D 51 Aachen, Germany

> < [top]