delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2001/10/22/22:14:46

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-developers-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-developers-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin-developers AT sources DOT redhat DOT com
Message-ID: <033701c15b68$f3684d70$0200a8c0@lifelesswks>
From: "Robert Collins" <robert DOT collins AT itdomain DOT com DOT au>
To: "Robert Collins" <robert DOT collins AT itdomain DOT com DOT au>,
<cygwin-developers AT cygwin DOT com>
References: <20011022193036 DOT 3609 DOT qmail AT lizard DOT curl DOT com> <20011022203136 DOT 5144 DOT qmail AT lizard DOT curl DOT com> <20011022203747 DOT 5162 DOT qmail AT lizard DOT curl DOT com> <02a201c15b5b$7910a4d0$0200a8c0 AT lifelesswks> <20011022204740 DOT B18754 AT redhat DOT com> <20011023005236 DOT 7136 DOT qmail AT lizard DOT curl DOT com> <20011022205828 DOT C18754 AT redhat DOT com> <02ea01c15b5f$7e673bc0$0200a8c0 AT lifelesswks> <20011022212759 DOT A19493 AT redhat DOT com> <032701c15b64$ea5523b0$0200a8c0 AT lifelesswks> <20011022215102 DOT A20341 AT redhat DOT com> <033101c15b66$24fc2260$0200a8c0 AT lifelesswks>
Subject: Re: 1.3.4 status?
Date: Tue, 23 Oct 2001 12:18:05 +1000
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-OriginalArrivalTime: 23 Oct 2001 02:22:46.0966 (UTC) FILETIME=[9AC94560:01C15B69]

----- Original Message -----
From: "Robert Collins" <robert DOT collins AT itdomain DOT com DOT au>
To: <cygwin-developers AT cygwin DOT com>
Sent: Tuesday, October 23, 2001 11:57 AM
Subject: Re: 1.3.4 status?


>
> ----- Original Message -----
> From: "Christopher Faylor" <cgf AT redhat DOT com>
> To: <cygwin-developers AT cygwin DOT com>
> Sent: Tuesday, October 23, 2001 11:51 AM
> Subject: Re: 1.3.4 status?
>
>
> > On Tue, Oct 23, 2001 at 11:49:11AM +1000, Robert Collins wrote:
> > >----- Original Message -----
> > >From: "Christopher Faylor" <cgf AT redhat DOT com>
> > >To: <cygwin-developers AT cygwin DOT com>
> > >Sent: Tuesday, October 23, 2001 11:27 AM
> > >Subject: Re: 1.3.4 status?
> > >
> > >
> > >> On Tue, Oct 23, 2001 at 11:10:23AM +1000, Robert Collins wrote:
> > >> >Can you mail me the disas for the fhandler_read (with the source
> line
> > >> >tags) ? I don't have time today to build a new dll, but I can
have
> a
> > >> >quick squint...
> > >>
> > >> It's below.
> > >>
> > >
> > >Maybe, I'm blind, but I cannot see the alloca call you mentioned
> > >before..
> >
> > "chkstk" == "alloca"
> >
> > Sorry, I should have mentioned that.  I just figured this out last
> week.
> >
> > It's possible that this is actually a stack boundary check, I guess.
> >
>
> Well it's in the function prolog, so I'd expect it to be that :}.

Ok, here's what alloca does:

on every call, it checks the stack depth. _everything_ allocated from a
call point deeper in the stack is reclaimed, and freed (alloca only uses
the stack to identify when to do stuff, not for storage).

If the size parameter is 0, alloca then returns, otherwise it mallocs a
memory item list header and storage, fills the header in, and returns
the user storage address.

So calling alloca in the prolog of each function is a mechanism to
prevent alloca _not_ freeing memory from a previous function for
extended time period - which will lead to heap fragmentation.

ie.
foo()
{
  bar ();
  bar ();
}
bar ()
{
  goo ();
}
goo ()
{
   ptr x = alloca (4);
}

would never free the two alloc'd blocks during foo() because alloca was
always called at the correct depth.

So gcc transforms that into:
foo ()
{
  alloca (0);
  bar ();
  bar ();
}
bar ()
{
  alloca (0);
  goo ();
}
goo ()
{
  alloca (0);
  ptr x = alloca (4);
}

which will on the second call to bar() free the allocated memory from
the 1st goo invocation.

Rob

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019