Mail Archives: djgpp-workers/2002/02/25/06:54:14
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 -