Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Oct 2004 10:30:05 -0700
From:      "David O'Brien" <obrien@FreeBSD.org>
To:        Georgi Guninski <guninski@guninski.com>
Cc:        freebsd-amd64@FreeBSD.org
Subject:   Re: two 4GB mallocs => SEGV
Message-ID:  <20041026173005.GA2984@dragon.nuxi.com>
In-Reply-To: <20041026115041.GE2841@sivokote.iziade.m$>
References:  <20041026115041.GE2841@sivokote.iziade.m$>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Oct 26, 2004 at 02:50:41PM +0300, Georgi Guninski wrote:
> amdkotef64# cat test.c
> #include <stdlib.h>
> 
> int main(int ac, char **av)
> {
> char *a, *b;
> size_t siz;
> siz=4L*1024L*1024L*1024L;
> printf("%lx\n",siz);
> a=malloc(siz);
> printf("%lx\n",a);
> b=malloc(siz);
> printf("%lx\n",b);
> }
> amdkotef64# gcc test.c
> amdkotef64# ./a.out 
> 100000000
> 503000
> /: write failed, filesystem is full
> Segmentation fault

I don't know why you didn't take this to the next step to try to figure
out what was going on....

    # cc -g test.c
    # gdb a.out
    (gdb) run
    Starting program: /var/tmp/a.out 
    100000000
    503000

    Program received signal SIGSEGV, Segmentation fault.
    0x0000000200503002 in ?? () from /libexec/ld-elf.so.1
    (gdb) where

now the output you get isn't but so helpful because you wind up in the
middle of libc.  So if you build libc with -g and don't strip the lib
when installing it you get:

    (gdb) run
    Starting program: /var/tmp/a.out 
    4294967296
    5255168

    Program received signal SIGILL, Illegal instruction.
    0x0000000200503000 in ?? () from /libexec/ld-elf.so.1
    (gdb) where
    #0  0x0000000200503000 in ?? () from /libexec/ld-elf.so.1
    #1  0x000000020069579d in map_pages (pages=8595189760)
        at /usr/src/lib/libc/stdlib/malloc.c:338
    #2  0x0000000200695c19 in malloc_pages (size=1048576)
        at /usr/src/lib/libc/stdlib/malloc.c:572
    #3  0x0000000200695f77 in imalloc (size=4294967296)
        at /usr/src/lib/libc/stdlib/malloc.c:740
    #4  0x00000002006968ed in pubrealloc (ptr=0x0, size=4294967296, 
        func=0x2006f8c88 " in malloc():") at /usr/src/lib/libc/stdlib/malloc.c:1128
    #5  0x00000002006969d8 in malloc (size=8595189760)
        at /usr/src/lib/libc/stdlib/malloc.c:1152
    #6  0x00000000004007b4 in main (ac=1, av=0x7fffffffe900) at test.c:11

malloc.c:map_pages() calls brk(2) and this is where it goes to la-la land.

-- 
-- David  (obrien@FreeBSD.org)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041026173005.GA2984>