delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/05/09:20:50

Date: Wed, 5 Jan 2000 10:43:25 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Martin Str|mberg <ams AT ludd DOT luth DOT se>
cc: djgpp AT delorie DOT com
Subject: Re: The endless int31 hooking debugging continued
In-Reply-To: <84sife$ral$1@news.luth.se>
Message-ID: <Pine.SUN.3.91.1000105104225.7920K-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On 4 Jan 2000, Martin Str|mberg wrote:

> When I run the program last in this mail in plain DOZE I get this
> crash dump (yes, it's all of it, only three lines):
> F:\HACKERY\DPMI_SEL>simple6
> got interrupt vector
> General Protection Fault at eip=2407; flags=3016
> eax=0000000d ebx=000000af ecx=0001465e edx=00014418 esi=00002548 edi=00002540
> ebp=0000000d esp=0001ae14 cs=a7 ds=af es=af fs=8f gs=bf ss=af error=0000

This message comes from CWSDPMI (see the telltale flags= string?), in
which case it is normal to have only 3 lines.

> When I disassemble the code around EIP 2407 (with "objdump -D
> simple6.exe") I find this:
> 000023cb <stack_ok>:
>     23cb:       66 8e c0        movw   %ax,%es

This crash is inside the DJGPP exception-processing code (you can find
it in exceptn.S).  It is quite normal to have the EIP point here when
the crash message comes from CWSDPMI: both indicate that you have
severely botched the execution environment, and the DPMI server is
bailing out by the skin of its teeth...

> __asm__ (".globl _handler
> _handler:
> 
> /* Jump to previous handler. */
> chain:
>         pushl %eax
>         pushl %ecx
>         pushl %edx
>         pushl $_chain_str
>         call _cputs
>         addl $4, %esp
>         popl %edx
>         popl %ecx
>         popl %eax
> 
>         ljmp _old_addr

I see two immediate problems with this hook:

  1) it calls a library function `cputs' without setting up the
     run-time environment expected by code generated by GCC (a valid
     DJGPP selector in DS, DS=ES=SS);

  2) it calls _old_addr without the CS: override, which won't work
     because DS is not guaranteed to be loaded with DJGPP's data
     selector (if you set up the registers as `cputs' requires, this
     problem will go away as well).

Btw, whenever you have such problems, it is useful to browse library
sources that do similar tricks, looking for ideas.  For example,
dbgcom.c hooks Int 31h, so you can compare your code with what's
there.

> /*
>    Local Variables:
>    compile-command: "gcc -g -O2 -Wall -o simple6 simple6.c"
>    End:
>    */

Oh, we have an Emacs user here ;-)

- Raw text -


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