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

Date: Tue, 11 Feb 2003 14:19:18 +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: <200302111016.LAA24287@lws256.lu.erisoft.se>
Message-ID: <Pine.OSF.4.51.0302111407150.31931@sirppi.helsinki.fi>
References: <200302111016 DOT LAA24287 AT lws256 DOT lu DOT erisoft DOT se>
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, Martin Stromberg wrote:

> 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.

No, we shouldn't push anything to the stack, so we can't do the addition
here.  But if we put __djgpp_stack_limit + _stklen into another variable
(maybe call it __djgpp_heap_bottom) then it's quite possible to check
that too.  OK to commit?

Index: crt0.S
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/crt0/crt0.S,v
retrieving revision 1.9
diff -u -r1.9 crt0.S
--- crt0.S	21 Dec 2002 20:22:34 -0000	1.9
+++ crt0.S	11 Feb 2003 12:17:58 -0000
@@ -36,6 +36,7 @@
 	.comm	___djgpp_base_address, 4
 	.comm	___djgpp_selector_limit, 4
 	.comm	___djgpp_stack_limit, 4
+	.comm	___djgpp_heap_bottom, 4
 	.comm	__crt0_startup_flags, 4
 	.comm	___djgpp_ds_alias, 2
 	.lcomm	sel_buf, 8
@@ -314,6 +315,7 @@
 	movw	%dx, %ss
 	andb	$0xf8, %al		/* align to 8-byte boundary */
 	movl	%eax, %esp
+	movl	%eax, ___djgpp_heap_bottom

 	xorl	%ebp, %ebp
 	pushl	$_frame_struct


-- 
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