[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] Re: alloca

From: James Youngman
Subject: Re: [Bug-gnulib] Re: alloca
Date: Thu, 13 Nov 2003 10:39:04 +0000
User-agent: Mutt/1.3.28i

On Wed, Nov 12, 2003 at 10:22:46PM +0100, Simon Josefsson wrote:

> Yes, I'm aware of this, but considering the alternatives it seems like
> the best solution, at least for me.  I tried to think of a better
> approach than guessing the stack depth, but even guessing the stack
> depth seemed like a quite ingenious solution, so I haven't come up
> with anything better.

In the specific case of Linux, you should be able to get around the
problem by ensuring that you fill your arrays backwards.  Linux will
extend the stack as long as the page you haven't touched isn't "too
far" below the current stack.  This means touching the high-address
end of arrays first.  You don't even need to touch every address -
every N megabytes is often enough (from memory, N=7 is OK, N=8 might
be OK).    

I have no idea how many of the several architectures Linux supports
this actually applies to, but it does apply to x86.  Not sure what
happens on machines where the stack grows upward.   

Of course, the above mechanism is highly non-portable, but while the
application shouldn't do that kind of non-portable thing, it's a
vaguely reasonable thing for alloca() itself to do.

James Youngman.
CSSC Bug reporting page:       http://sf.net/tracker/?group_id=8064&atid=108064
GNU Findutils bug reporting page: http://savannah.gnu.org/bugs/?group=findutils

reply via email to

[Prev in Thread] Current Thread [Next in Thread]