Subject: Re: sbrk(0) dumps a core??
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Emmanuel Dreyfus <p99dreyf@criens.u-psud.fr>
List: tech-userlevel
Date: 03/04/2001 04:03:04
> Whoa Nelly!  You've just set the break to 0x4000; if you have any data
> segment above that, it just went poof.

Ok, I see the problem, I went confused between brk() and sbrk(). But
this still crashes, why?

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main (int argc, char** argv) {
        void *end;
        int res;
        void *newend;

        end = sbrk (0);
        printf ("end=0x%lx\n", (long)end);      

        if (argc >= 2) 
                newend = (void*)((long)end + atoi (argv[1]));
        else
                newend = (void*)((long)end + 4000);
        printf ("newend=0x%lx\n", (long)newend);

        end = sbrk (0);
        printf ("end=0x%lx\n", (long)end);      

        res = brk (newend);
        printf ("brk(0x%lx) returned %d\n", (long)newend, res);

        end = sbrk (0);
        printf ("end=0x%lx\n", (long)end);      

        return 0;
}

Ouput:
end=0x1840e68
new_end=0x1841e08
end=0x1852000
Memory fault (core dumped) 

Is it that printf caused some allocation, hence a end move, and that I'm
calling brk with and adress which is lower than end?

-- 
Emmanuel Dreyfus
- Quel est le meilleur moyen d'accelerer un PC?
- 9,81 m/s^2
p99dreyf@criens.u-psud.fr