Microport and SCO Xenix Memory Managment Problems
Tim Smith
tim at ism780c.UUCP
Sat Oct 25 14:41:05 AEST 1986
sbrk has to behave funny because of program that assume a linear
address space. Many program that want N bytes do the following:
char * ptr;
ptr = sbrk(0);
brk(ptr+N);
To make these work correctly, sbrk(0) has to return the start of
the next segment.
For example, here is how brk and sbrk work on the AT&T pc6300+ (
which is a good indication of how AT&T thinks things should work
on 80286 based machines )
( all byte counts and addresses are rounded to a multiple
of 512 )
In small model, everything looks like a normal unix system
In large model,
sbrk(0) returns start of next data segment
sbrk(N) N > 0 allocates N bytes from next data segment
sbrk(N) N < 0 does this:
N = -N
while ( N >= size of last segment )
N = N - size of last segment
remove last segment
remove N bytes from last segment
brk(addr) ( where addr == byte N of segment S )
if addr in current last segment, then set
segment size to N
if addr in next segment, then same as sbrk(N)
if addr in an allocated part of a previous segment
then throw away everything above addr
else error
--
member, all HASA divisions POELOD ECBOMB
--------------
^-- Secret Satanic Message
Tim Smith USENET: sdcrdcf!ism780c!tim Compuserve: 72257,3706
Delphi or GEnie: mnementh
More information about the Comp.lang.c
mailing list