X-Sybari-Trust: ff0670d7 9ffcebbb 7a95d2f4 00000138 From: Martin Stromberg 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: from "Esa A E Peuha" at Feb 10, 2003 02:08:25 PM X-Mailer: ELM [version 2.5 PL3] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 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