delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/02/11/07:08:42

Date: Tue, 11 Feb 2003 14:06:09 +0200 (EET)
From: Esa A E Peuha <peuha AT cc DOT helsinki DOT fi>
Sender: peuha AT sirppi DOT helsinki DOT fi
To: djgpp-workers AT delorie DOT com
Subject: Re: Checking for stack overflow
In-Reply-To: <Pine.SUN.3.91.1030211075706.25449B-100000@is>
Message-ID: <Pine.OSF.4.51.0302111341240.31931@sirppi.helsinki.fi>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1030211075706 DOT 25449B-100000 AT is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Tue, 11 Feb 2003, Eli Zaretskii wrote:

> On Mon, 10 Feb 2003, CBFalconer wrote:
>
> > > Assuming that esp
> > > has already decremented to point to the newly allocated space,
> > > the possible overflow is detected thus:
> >
> > I don't believe you should make any such assumption.  You cannot
> > assume that anything called has stack checking code.
>
> I think you misunderstood what Esa was saying (or else I misunderstood
> it ;-).  As I understand it, his code assumes to be called by GCC _after_
> each change in ESP.  There's no assumption that the calling code was
> compiled with stack checking.

It seems like it's time to explain what gcc does with -fstack-check (or
rather, what's relevant here; the full story is in the gcc manual).
There's a pattern called stack_check in the machine description file;
this could be a single machine instruction for all gcc cares, but it's
usually a block of instructions that will be placed in gcc's output to
the assembler.  This pattern takes one argument, which is the value of
esp after the allocation.  The code fragment that I wrote checks the
validity of this argument (assuming it is in esp already), and nothing
more.

-- 
Esa Peuha
student of mathematics at the University of Helsinki
http://www.helsinki.fi/~peuha/

- Raw text -


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