Mail Archives: djgpp-workers/2003/10/31/04:13:35
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 -