delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/02/11/05:19:30

X-Sybari-Trust: ff0670d7 9ffcebbb 7a95d2f4 00000138
From: Martin Stromberg <eplmst AT epl DOT ericsson DOT se>
Message-Id: <200302111016.LAA24287@lws256.lu.erisoft.se>
Subject: Re: Checking for stack overflow
To: djgpp-workers AT delorie DOT com
Date: Tue, 11 Feb 2003 11:16:53 +0100 (MET)
In-Reply-To: <Pine.OSF.4.51.0302101329270.31820@sirppi.helsinki.fi> from "Esa A E Peuha" at Feb 10, 2003 02:08:25 PM
X-Mailer: ELM [version 2.5 PL3]
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

Esa said:
> OK.  Here's what I wrote during the weekend.  Assuming that esp has
> already decremented to point to the newly allocated space, the possible
> overflow is detected thus:
> 
> 	cmpl	___djgpp_stack_limit, %esp
> 	jge	0f
> 	movl	$0f, ___djgpp_stack_overflow_eip
> 	jmp	___djgpp_stack_overflow_exit
> 0:

If we add __stklen into the formula (untested):

	pushl	%eax
	movl	___djgpp_stack_limit, %eax
	cmpl	%eax, %esp
	jb	0f
	add	__stklen, %eax	; Ooooh, we do actually add __stklen!
	cmpl	%eax, %esp
	jb	1f
0:
	popl	%eax
	movl	$0f, ___djgpp_stack_flowing_wild_eip
	jmp	___djgpp_stack_flowing_wild_exit
1:
	popl	%eax

we detect stack underflow or local variable of sizes > 2GiB as well.


Right,

						MartinS

- Raw text -


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