Date: Tue, 11 Feb 2003 14:06:09 +0200 (EET) From: Esa A E Peuha Sender: peuha AT sirppi DOT helsinki DOT fi To: djgpp-workers AT delorie DOT com Subject: Re: Checking for stack overflow In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 Precedence: bulk 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/