From dm@punitive-surgery.lcs.mit.edu  Sat Dec 18 15:30:38 1999
Return-Path: <dm@punitive-surgery.lcs.mit.edu>
Received: from punitive-surgery.lcs.mit.edu (punitive-surgery.lcs.mit.edu [18.26.4.18])
	by hub.freebsd.org (Postfix) with ESMTP id DCA2214F56
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 18 Dec 1999 15:30:36 -0800 (PST)
	(envelope-from dm@punitive-surgery.lcs.mit.edu)
Received: (from dm@localhost)
	by punitive-surgery.lcs.mit.edu (8.9.3/8.9.3) id SAA38082;
	Sat, 18 Dec 1999 18:31:15 -0500 (EST)
	(envelope-from dm)
Message-Id: <199912182331.SAA38082@punitive-surgery.lcs.mit.edu>
Date: Sat, 18 Dec 1999 18:31:15 -0500 (EST)
From: dm@reeducation-labor.lcs.mit.edu
Sender: dm@punitive-surgery.lcs.mit.edu
Reply-To: dm@reeducation-labor.lcs.mit.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: malloc fails in OMAGIC programs
X-Send-Pr-Version: 3.2

>Number:         15554
>Category:       kern
>Synopsis:       malloc fails in OMAGIC programs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 18 15:40:00 PST 1999
>Closed-Date:    Wed Mar 28 11:16:13 PST 2001
>Last-Modified:  Wed Mar 28 11:16:23 PST 2001
>Originator:     David Mazieres
>Release:        FreeBSD 3.3-RELEASE i386
>Organization:
>Environment:

i386 machine running stock FreeBSD-3.3-RELEASE (including generic kernel)

>Description:

Memory allocation files in OMAGIC programs.

>How-To-Repeat:

Compile and run this program:

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

int
main (int argc, char **argv)
{
	char *p = malloc (8192);
	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);
}

/* --- end --- */

like this:

% cc -static -N -o badomagic badomagic.c
% ./badomagic 
malloc failed
Cannot allocate memory
% 

>Fix:
	
unknown

>Release-Note:
>Audit-Trail:

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: dm@reeducation-labor.lcs.mit.edu
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: kern/15554: malloc fails in OMAGIC programs
Date: Sat, 18 Dec 1999 20:48:34 -0500 (EST)

 <<On Sat, 18 Dec 1999 18:31:15 -0500 (EST), dm@reeducation-labor.lcs.mit.edu said:
 
 > % cc -static -N -o badomagic badomagic.c
 > % ./badomagic 
 > malloc failed
 > Cannot allocate memory
 
 It appears that either malloc or execve is getting confused by the
 fact that the entire program is in a single load segment.  Unless you
 demonstrate that this can cause a panic, I suspect the answer is
 ``don't do that, then''.  For comparison:
 
 wollman@khavrinen$ cc -static -N foo.c
 wollman@khavrinen$ ./a.out
 malloc failed
 \^@Cannot allocate memory
 wollman@khavrinen$ cc -static -N -aout foo.c
 wollman@khavrinen$ ./a.out
 bash: ./a.out: cannot execute binary file
 
 -GAWollman
 
 --
 Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
 wollman@lcs.mit.edu  | O Siem / The fires of freedom 
 Opinions not those of| Dance in the burning flame
 MIT, LCS, CRS, or NSA|                     - Susan Aglukark and Chad Irschick
 

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: dm@reeducation-labor.lcs.mit.edu
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/15554: malloc fails in OMAGIC programs 
Date: Sun, 19 Dec 1999 13:41:11 +0100

 This looks like a toolchain problem somehow:
 
    173 ktrace   RET   ktrace 0
    173 ktrace   CALL  execve(0xbfbffd6f,0xbfbffcb0,0xbfbffcb8)
    173 ktrace   NAMI  "./a"
    173 a        RET   execve 0
    173 a        CALL  readlink(0x804a6d4,0xbfbffbb4,0x3f)
    173 a        NAMI  "/etc/malloc.conf"
    173 a        RET   readlink -1 errno 2 No such file or directory
    173 a        CALL  mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0,0)
    173 a        RET   mmap 536870912/0x20000000
    173 a        CALL  break(0x804c000)
    173 a        RET   break -1 errno 12 Cannot allocate memory
 
 
     syv# !107
     cc -static -N -o a a.c
     syv# nm -n a | head
 	     U _DYNAMIC
     08048074 ? _init
     0804807c T _start
     08048160 t gcc2_compiled.
     08048160 T main
     08048234 T atexit
     080482e4 T strlen
     080482fc W __error
     080482fc T __error_unthreaded
     08048310 T _write
     [...]
 
 I thought programs started out at 0x0 or at least close to zero ?
 
 --
 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!
 
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Wed Mar 28 11:16:13 PST 2001 
State-Changed-Why:  
Antique PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=15554 
>Unformatted:
