Mail Archives: djgpp/1996/02/01/22:52:59
Xref: | news2.mv.net comp.os.msdos.djgpp:722
|
From: | rho AT hrz DOT tu-chemnitz DOT de (Robert Hoehne)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Q: Why does my handler of int 0x21 not work?
|
Date: | 1 Feb 96 15:07:48 GMT
|
Organization: | University of Technology Chemnitz, FRG
|
Lines: | 91
|
Message-ID: | <4eql1u$2lm@pyrrhus-f.hrz.tu-chemnitz.de>
|
NNTP-Posting-Host: | ram.hrz.tu-chemnitz.de
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
/*
I want to write a handler for int 0x21 and call then external programs.
Every thing in my program work well with this handler, but if I call
an external program (like gcc), computer crashs. Where is the Error or
the problem, which I have to solve? (I'm using DJGPP V2Beta4 GCC V2.7.0
and the patched file gormcb.c). Program was comiled with
gcc -o test21 test21.cc
Robert
/* start of file test21.cc */
#include <stdio.h>
#include <stdlib.h>
#include <dpmi.h>
#include <go32.h>
#include <unistd.h>
#include <process.h>
#include <sys/farptr.h>
_go32_dpmi_seginfo oldint21,newint21;
__dpmi_regs regs;
int is_set = 0;
#define call_oldint(info,r)\
r->x.cs = info.rm_segment;\
r->x.ip = info.rm_offset;\
_go32_dpmi_simulate_fcall_iret(r)
void _new_int21(__dpmi_regs *r,int origstack,int _sp,int _ss)
{
int _es;
call_oldint(oldint21,r);
/*
save flags on caller's stack, because the iret-wrapper restores
them from this location and not from *r
*/
#if 1
/* after analysing the wrapper I got this code to access the callers stack */
_es = _farpeekw(_ss,_sp);
_farpokew(_es,origstack+4,r->x.flags);
#else /* this shoul'd also work
_farpokew(_dos_ds,(_ss << 4) + _sp + 4,r->x.flags);
#endif
}
void exit_func(void)
{
int i;
if (!is_set) return;
_go32_dpmi_set_real_mode_interrupt_vector(0x21,&oldint21);
_go32_dpmi_free_real_mode_callback(&newint21);
is_set = 0;
}
void InitHook21()
{
newint21.pm_offset = (int)_new_int21;
_go32_dpmi_lock_code(_new_int21,
(unsigned long)exit_func - (unsigned long)_new_int21);
_go32_dpmi_lock_data(&oldint21,sizeof(oldint21));
_go32_dpmi_get_real_mode_interrupt_vector(0x21,&oldint21);
_go32_dpmi_allocate_real_mode_callback_iret(&newint21,®s);
atexit(exit_func);
_go32_dpmi_set_real_mode_interrupt_vector(0x21,&newint21);
is_set = 1;
}
void DoneHook21()
{
exit_func();
}
int main(int argc,char *argv[])
{
fprintf(stderr,"before calling external program\n");
spawnlp(P_WAIT,"gcc.exe","gcc.exe","-v",0);
fprintf(stderr,"after calling external program\n");
InitHook21();
fprintf(stderr,"before calling external program\n");
spawnlp(P_WAIT,"gcc.exe","gcc.exe","-v",0);
/*
At this point the computer hangs. => Ctrl-Alt-Del
*/
fprintf(stderr,"after calling external program\n");
DoneHook21();
}
/* end of file test21.cc */
- Raw text -