Catching DOS interrupt 24H (critical error handler)

Mark Freedman mdfreed at ziebmef.uucp
Sun Jan 22 08:55:06 AEST 1989


In article <336 at sunset.MATH.UCLA.EDU> tony at MATH.UCLA.EDU () writes:
>I'd like to replace the MS DOS critical error handler with one
>of my own in a C program I am writing but I can't seem to get it right.  
>
>I've been trying to use the intdosx() function in MSC 5.1 but after 
>numerous system hang-ups I've decided to ask for help.
>
>Can somebidy explain how I can go about doing this in C?  I have
>some code in assembly but I really would like to do it in C.


   This seems to work in Turbo C 2.0 (small model). Turbo Debugger seems
to have problems with it (fortunately, IBM didn't put a reset button on
the PC :-( ).
 
   According to Al Stevens' article on writing TSR's (Computer Language
March 1988), Quick C generates code for an interrupt function which 
trashes the ax register upon entry. This might cause some problems
(I don't have MSC). He also mentions a problem with _chain_intr.
 
   I haven't been able to chain to the old critical error handler without
crashing. I suspect that one must to restore everything (including the
stack) to its state upon entry. In consideration for my power switch, 
I'll leave further experimentation as "an excercise for the reader".
 
/********************************************************/
/* Turbo C 2.0 - replace critical error handler (0x24 ) */
 
#include "dos.h"
#include "stdio.h"
 
void interrupt newcrit(bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,flgs)
/* These parameters point to the values saved on the stack upon entry, */
/* and popped from the stack before a return-from-interrupt is issued  */
{
 
/*  an int24 handler can only use DOS functions 0x00 - 0x0c */
 
   do        /* display prompt. return key in ax register */
      {
      bdosptr (0x09, "\n\rEnter 0 (ignore), 1(retry), 2(abort): $", 0);
      bdosptr (0x01, NULL, 0);
      } while (_AL != '0' && _AL != '1' && _AL != '2');
 
   ax = (_AX & 0x000f);  /* al specifies DOS action upon return */
                         /* values are popped before returning  */
}
 
void main()
{
 
FILE *in;
 
   setvect (0x24, newcrit);
 
   fputs ("\n open door of drive a: to cause critical error\n", stderr);
   in = fopen ("a:zot", "rt");
   fputs ("\n back to main AFTER the critical-error handler\n", stderr);
}
 



More information about the Comp.lang.c mailing list