delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/10/31/04:13:35

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Date: Fri, 31 Oct 2003 11:12:04 +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: New plan for 2.04
In-Reply-To: <3FA163F9.5AA2742C@phekda.freeserve.co.uk>
Message-ID: <Pine.OSF.4.58.0310311050480.32331@sirppi.helsinki.fi>
References: <3F9980BB DOT 9F366A48 AT phekda DOT freeserve DOT co DOT uk>
<Pine DOT OSF DOT 4 DOT 58 DOT 0310281115580 DOT 32687 AT sirppi DOT helsinki DOT fi>
<3F9ED98B DOT 75295116 AT phekda DOT freeserve DOT co DOT uk> <Pine DOT OSF DOT 4 DOT 58 DOT 0310291023480 DOT 32530 AT sirppi DOT helsinki DOT fi>
<3FA163F9 DOT 5AA2742C AT phekda DOT freeserve DOT co DOT uk>
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 Thu, 30 Oct 2003, Richard Dawe wrote:

> Patch == diff, or whatever you want to call it. Please could you post a diff
> that someone could apply to a CVS check-out, test with or review?

Okay, here's the diff of dpmiexcp.c (already committed in CVS):

Index: dpmiexcp.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/go32/dpmiexcp.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -c -r1.17 -r1.18
*** dpmiexcp.c	3 Sep 2003 09:27:27 -0000	1.17
--- dpmiexcp.c	3 Sep 2003 09:30:25 -0000	1.18
***************
*** 123,128 ****
--- 123,129 ----
    vbp = (unsigned *)__djgpp_exception_state->__ebp;
    err("Call frame traceback EIPs:\r\n  0x");
    itox(__djgpp_exception_state->__eip, 8);
+   max--;
    while (((unsigned)vbp >= __djgpp_exception_state->__esp) && (vbp >= &end) && (vbp < tos))
    {
      vbp_new = (unsigned *)*vbp;

Then the makefile diff:

Index: makefile
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/go32/makefile,v
retrieving revision 1.1
diff -c -r1.1 makefile
*** makefile	29 Mar 1995 10:08:14 -0000	1.1
--- makefile	31 Oct 2003 08:58:53 -0000
***************
*** 12,16 ****
--- 12,17 ----
  SRC += gormem.c
  SRC += gorvec.c
  SRC += infostrc.c
+ SRC += overflow.S

  include $(TOP)/../makefile.inc

And finally the file overflow.S (a new file, so not in diff format):

	.file	"overflow.S"
	.data
	.balign	8
	.comm	exception_stack, 8000
	.balign	8
overflow_state_buf:		/* jmp_buf */
	.long	0, 0, 0, 0	/* eax, ebx, ecx, edx */
	.long	0, 0, 0, 0	/* esi, edi, ebp, esp */
	.globl	___djgpp_stack_overflow_eip
___djgpp_stack_overflow_eip:
	.long	0, 0		/* eip, eflags */
	.word	0, 0, 0, 0, 0, 0/* cs, ds, es, fs, gs, ss */
	.long	0, 0, 0		/* sigmask, signum, exception_ptr */
	.text
errstring:
	.ascii	"Out of stack. \0"
	.balign	16,,7
	.globl	___djgpp_stack_overflow_exit
___djgpp_stack_overflow_exit:
	movl	%eax, overflow_state_buf
	movl	$overflow_state_buf, %eax

	/* change stack as soon as possible */
	movl	%esp, 28(%eax)
	movl	$exception_stack + 8000, %esp

	/* eax already stored */
	movl	%ebx, 4(%eax)
	movl	%ecx, 8(%eax)
	movl	%edx, 12(%eax)
	movl	%esi, 16(%eax)
	movl	%edi, 20(%eax)
	movl	%ebp, 24(%eax)
	/* esp already stored */
	/* eip stored before jumping here */
	pushfl
	popl	36(%eax)
	movw	%cs, 40(%eax)
	movw	%ds, 42(%eax)
	movw	%es, 44(%eax)
	movw	%fs, 46(%eax)
	movw	%gs, 48(%eax)
	movw	%ss, 50(%eax)

	/* fake exception number like in __djgpp_traceback_exit,
	   0x7e == 0x7a + 1 + SIGSEGV - SIGABRT */
	movl	$0x7e, 56(%eax)

	movl	$overflow_state_buf, ___djgpp_exception_state_ptr

	/* print error message */
	pushl	$14
	pushl	$errstring
	pushl	$2
	call	__write

	/* 291 == SIGSEGV */
	pushl	$291

	/* this does not return */
	call	___djgpp_traceback_exit

Simplest test program could be something like this:

extern unsigned int __djgpp_stack_overflow_eip;
extern void __djgpp_stack_overflow_exit(void) __attribute__((noreturn));
int main(void)
{
  __djgpp_stack_overflow_eip = 0xdeafbead;
  __djgpp_stack_overflow_exit();
  return 0;
}

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