Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Dec 1999 23:37:13 +0100
From:      Poul-Henning Kamp <phk@critter.freebsd.dk>
To:        Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc:        freebsd-bugs@FreeBSD.ORG
Subject:   Re: kern/15554: malloc fails in OMAGIC programs 
Message-ID:  <7706.945643033@critter.freebsd.dk>
In-Reply-To: Your message of "Sun, 19 Dec 1999 15:22:04 EST." <199912192022.PAA65483@khavrinen.lcs.mit.edu> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <199912192022.PAA65483@khavrinen.lcs.mit.edu>, Garrett Wollman write
s:
><<On Sun, 19 Dec 1999 04:50:02 -0800 (PST), Poul-Henning Kamp <phk@critter.freebsd.dk> said:
>
>>  I thought programs started out at 0x0 or at least close to zero ?
> 
>Not ELF programs.

I know, but I thought we tried to keep the start low still.

Anyway, the problem is obviously sbrk(2)/brk(2) failing:

syv# cat a.c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>

int
main (int argc, char **argv)
{
        char *p = malloc (8192);
        char buf[4096];
        int fd, i;

        fd = open("/proc/curproc/map", O_RDONLY);
        if (fd >= 0) {
                do {
                        i = read(fd, buf, sizeof buf);
                        if (i > 0)
                                write(1, buf, i);
                } while (i > 0);
                close(fd);
        }

        if (!p) {
                char badmalloc[] = "malloc failed\n";
                write (2, badmalloc, sizeof (badmalloc));
                write (2, strerror (errno), strlen (strerror (errno)));
                write (2, "\n", 1);
                exit (1);
        }
        exit (0);
}
syv# cc -static -N -o a a.c
syv# ktrace ./a
0x8048000 0x804a000 2 0 0xcdc0f180 rwx 1 0 0x0 COW NC vnode
0x804a000 0x804b000 1 0 0xc0279fe0 rwx 1 0 0x2180 NCOW NNC default
0x20000000 0x20001000 1 0 0xcdc324e0 rwx 1 0 0x2180 NCOW NNC default
0xbfbe0000 0xbfc00000 2 0 0xcdc60de0 rwx 1 0 0x2180 NCOW NNC default
malloc failed
Cannot allocate memory
syv# kdump
  3101 ktrace   RET   ktrace 0
  3101 ktrace   CALL  execve(0xbfbffd6f,0xbfbffcb0,0xbfbffcb8)
  3101 ktrace   NAMI  "./a"
  3101 a        RET   execve 0
  3101 a        CALL  readlink(0x804a7d4,0xbfbfeba4,0x3f)
  3101 a        NAMI  "/etc/malloc.conf"
  3101 a        RET   readlink -1 errno 2 No such file or directory
  3101 a        CALL  mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0,0)
  3101 a        RET   mmap 536870912/0x20000000
  3101 a        CALL  break(0x804c000)
  3101 a        RET   break -1 errno 12 Cannot allocate memory
  3101 a        CALL  break(0x804d000)
  3101 a        RET   break -1 errno 12 Cannot allocate memory
  3101 a        CALL  open(0x8049d01,0,0)
  3101 a        NAMI  "/proc/curproc/map"
  3101 a        RET   open 3
  3101 a        CALL  read(0x3,0xbfbfec60,0x1000)
  3101 a        GIO   fd 3 read 265 bytes
       "0x8048000 0x804a000 2 0 0xcdc0f180 rwx 1 0 0x0 COW NC vnode
        0x804a000 0x804b000 1 0 0xc0279fe0 rwx 1 0 0x2180 NCOW NNC default
        0x20000000 0x20001000 1 0 0xcdc324e0 rwx 1 0 0x2180 NCOW NNC default
        0xbfbe0000 0xbfc00000 2 0 0xcdc60de0 rwx 1 0 0x2180 NCOW NNC default
       "
  3101 a        RET   read 265/0x109
  3101 a        CALL  write(0x1,0xbfbfec60,0x109)
  3101 a        GIO   fd 1 wrote 265 bytes
       "0x8048000 0x804a000 2 0 0xcdc0f180 rwx 1 0 0x0 COW NC vnode
        0x804a000 0x804b000 1 0 0xc0279fe0 rwx 1 0 0x2180 NCOW NNC default
        0x20000000 0x20001000 1 0 0xcdc324e0 rwx 1 0 0x2180 NCOW NNC default
        0xbfbe0000 0xbfc00000 2 0 0xcdc60de0 rwx 1 0 0x2180 NCOW NNC default
       "
  3101 a        RET   write 265/0x109
  3101 a        CALL  read(0x3,0xbfbfec60,0x1000)
  3101 a        GIO   fd 3 read 0 bytes
       ""
  3101 a        RET   read 0
  3101 a        CALL  close(0x3)
  3101 a        RET   close 0
  3101 a        CALL  write(0x2,0xbfbfec48,0xf)
  3101 a        GIO   fd 2 wrote 15 bytes
       "malloc failed
        \0"
  3101 a        RET   write 15/0xf
  3101 a        CALL  write(0x2,0x804a680,0x16)
  3101 a        GIO   fd 2 wrote 22 bytes
       "Cannot allocate memory"
  3101 a        RET   write 22/0x16
  3101 a        CALL  write(0x2,0x8049d22,0x1)
  3101 a        GIO   fd 2 wrote 1 byte
       "
       "
  3101 a        RET   write 1
  3101 a        CALL  exit(0x1)


--
Poul-Henning Kamp             FreeBSD coreteam member
phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
FreeBSD -- It will take a long time before progress goes too far!


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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