delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/02/25/06:54:14

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-workers-bounces using -f
Message-ID: <3C7A0C9A.6D699A31@yahoo.com>
Date: Mon, 25 Feb 2002 05:06:18 -0500
From: CBFalconer <cbfalconer AT yahoo DOT com>
Organization: Ched Research
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: Malloc/free DJGPP code
References: <10202201713 DOT AA23034 AT clio DOT rice DOT edu> <3C7919F2 DOT 96FFA97D AT yahoo DOT com> <200202241740 DOT g1OHeOd19302 AT envy DOT delorie DOT com> <3C79833E DOT 7282AF8D AT yahoo DOT com>
Reply-To: djgpp-workers AT delorie DOT com

CBFalconer wrote:
> 
> DJ Delorie wrote:
> >
> > > This could all be cured by a semi-portable implementation of, say,
> > > "fakesbrk" which will return a repeatable set of addresses under
> > > the same circumstances.  It might actually malloc a large block
> > > which contains those addresses to be faked.  But how can it ensure
> > > that a certain range is available to any degree of certainty, or
> > > even of probability?
> >
> > Put a huge uninitialized static array in your program and use it for
> > sbrk.  It will always be in the same virtual address.
> 
> Do you see any problem with the following?  I was surprised to
> read that sbrk returns -1 for failure.  This way the test program
> can fool with it by making small silly allocations to foul the
> sequence.  I'll worry about going backwards later.
> 
> #include "fakesbrk.h"
> 
> enum {FAKESIZE = 1234567};
> 
> char fakearea[FAKESIZE];
> 
> /* 1------------------1 */
> 
> /* we can fool with this to generate test cases */
> void *fakesbrk(int delta)
> {
> static char *unused = fakearea;
> char        *next, *p;
> 
>    next = unused + delta;
>    if ((unsigned) next > FAKESIZE) return (void *)-1;
>    else {
>       p = unused;
>       unused = next;
>       return (void *)p;
>    }
> } /* fakesbrk */

Incidentally, I was surprised to learn (from info libc) that sbrk
returns -1 for failure rather than NULL.  Is this correct, or
possibly a documentation error?

-- 
Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT XXXXworldnet DOT att DOT net)
   Available for consulting/temporary embedded and systems.
   (Remove "XXXX" from reply address. yahoo works unmodified)
   mailto:uce AT ftc DOT gov  (for spambots to harvest)


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019