static char *ReadInTrap( tiny_handle_t fh ) { dos_exe_header hdr; memptr relocbuff[NUM_BUFF_RELOCS]; unsigned relocnb; unsigned imagesize; unsigned hdrsize; rm_call_struct read; unsigned offset; if( TINY_ERROR( TinyRead( fh, &hdr, sizeof( hdr ) ) ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } if( hdr.signature != DOS_SIGNATURE ) { return( TC_ERR_BAD_TRAP_FILE ); } hdrsize = hdr.hdr_size * 16; imagesize = ( hdr.file_size * 0x200 ) - (-hdr.mod_size & 0x1ff) - hdrsize; TrapMem.dpmi_adr = DPMIAllocateDOSMemoryBlock( _NBPARAS( imagesize ) + hdr.min_16 ); if( TrapMem.segm.pm == 0 ) { return( TC_ERR_OUT_OF_DOS_MEMORY ); } TinySeek( fh, hdrsize, TIO_SEEK_SET ); memset( &read, 0, sizeof( read ) ); for( offset = 0; offset < imagesize; offset += (unsigned_16)read.eax ) { read.ss = RMData.segm.rm; read.sp = offsetof( rm_data, stack ) + STACK_SIZE; read.edx = offset; read.ebx = fh; read.ds = TrapMem.segm.rm; read.ecx = imagesize - offset; read.eax = 0x3f00; #if 1 relocnb = DPMISimulateRealModeInterrupt( 0x21, 0, 0, &read ); if( (read.flags & 1) || (unsigned_16)read.eax == 0 ) { return( TC_ERR_CANT_LOAD_TRAP ); } #else read.eax = TinyRead( fh, (void *)((TrapMem.segm.rm << 4) + offset), imagesize - offset ); if( (signed_32)read.eax < 0 ) { return( TC_ERR_CANT_LOAD_TRAP ); } #endif } TinySeek( fh, hdr.reloc_offset, TIO_SEEK_SET ); for( relocnb = NUM_BUFF_RELOCS; hdr.num_relocs > 0; --hdr.num_relocs, ++relocnb ) { if( relocnb >= NUM_BUFF_RELOCS ) { if( TINY_ERROR( TinyRead( fh, relocbuff, sizeof( memptr ) * NUM_BUFF_RELOCS ) ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } relocnb = 0; } *(addr_seg __far *)MK_PM( TrapMem.segm.rm + relocbuff[relocnb].s.segment, relocbuff[relocnb].s.offset ) += TrapMem.segm.rm; } return( NULL ); }
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver ) { char *err; char *parm; char *end; dig_fhandle dh; trap_file_header __far *head; if( trapbuff == NULL ) { trapbuff = DEFAULT_TRP_NAME; } end = strchr( trapbuff, PARM_SEPARATOR ); if( end == NULL ) { end = &trapbuff[strlen( trapbuff )]; parm = end; } else { parm = end + 1; } dh = DIGPathOpen( trapbuff, end - trapbuff, DEFAULT_TRP_EXT, NULL, 0 ); if( dh == DIG_NIL_HANDLE ) { sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff ); return( buff ); } err = ReadInTrap( DIGGetSystemHandle( dh ) ); DIGPathClose( dh ); sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff ); if( err == NULL ) { if( (err = SetTrapHandler()) != NULL || (err = CopyEnv()) != NULL ) { strcpy( buff, err ); } else { strcpy( buff, TC_ERR_WRONG_TRAP_VERSION ); head = MK_PM( TrapMem.segm.rm, 0 ); if( head->sig == TRAP_SIGNATURE ) { PMData->initfunc.s.offset = head->init; PMData->reqfunc.s.offset = head->req; PMData->finifunc.s.offset = head->fini; PMData->initfunc.s.segment = TrapMem.segm.rm; PMData->reqfunc.s.segment = TrapMem.segm.rm; PMData->finifunc.s.segment = TrapMem.segm.rm; if( CallTrapInit( parm, buff, trap_ver ) ) { if( TrapVersionOK( *trap_ver ) ) { TrapVer = *trap_ver; ReqFunc = DoTrapAccess; return( NULL ); } strcpy( buff, TC_ERR_WRONG_TRAP_VERSION ); } } } } KillTrap(); return( buff ); }
static char *ReadInTrap( dig_ldhandle ldfh ) { dos_exe_header hdr; memptr relocbuff[NUM_BUFF_RELOCS]; unsigned relocnb; unsigned imagesize; unsigned hdrsize; rm_call_struct rm_dos_read; unsigned offset; if( DIGLoader( Read )( ldfh, &hdr, sizeof( hdr ) ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } if( hdr.signature != DOS_SIGNATURE ) { return( TC_ERR_BAD_TRAP_FILE ); } hdrsize = hdr.hdr_size * 16; imagesize = ( hdr.file_size * 0x200 ) - (-hdr.mod_size & 0x1ff) - hdrsize; TrapMem.dpmi_adr = DPMIAllocateDOSMemoryBlock( _NBPARAS( imagesize ) + hdr.min_16 ); if( TrapMem.segm.pm == 0 ) { return( TC_ERR_OUT_OF_DOS_MEMORY ); } DIGLoader( Seek )( ldfh, hdrsize, DIG_ORG ); // DPMI file read to real mode memory memset( &rm_dos_read, 0, sizeof( rm_dos_read ) ); for( offset = 0; offset < imagesize; offset += (unsigned_16)rm_dos_read.eax ) { rm_dos_read.ss = RMData.segm.rm; rm_dos_read.sp = offsetof( rm_data, stack ) + STACK_SIZE; rm_dos_read.edx = offset; rm_dos_read.ebx = ldfh; rm_dos_read.ds = TrapMem.segm.rm; rm_dos_read.ecx = imagesize - offset; rm_dos_read.eax = 0x3f00; relocnb = DPMISimulateRealModeInterrupt( 0x21, 0, 0, &rm_dos_read ); if( (rm_dos_read.flags & 1) || (unsigned_16)rm_dos_read.eax == 0 ) { return( TC_ERR_CANT_LOAD_TRAP ); } } DIGLoader( Seek )( ldfh, hdr.reloc_offset, DIG_ORG ); for( relocnb = NUM_BUFF_RELOCS; hdr.num_relocs > 0; --hdr.num_relocs, ++relocnb ) { if( relocnb >= NUM_BUFF_RELOCS ) { if( DIGLoader( Read )( ldfh, relocbuff, sizeof( memptr ) * NUM_BUFF_RELOCS ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } relocnb = 0; } *(addr_seg __far *)MK_PM( TrapMem.segm.rm + relocbuff[relocnb].s.segment, relocbuff[relocnb].s.offset ) += TrapMem.segm.rm; } return( NULL ); }
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver ) { char *err; const char *end; dig_fhandle dh; trap_file_header __far *head; if( parms == NULL || *parms == '\0' ) { parms = DEFAULT_TRP_NAME; } for( end = parms; *end != '\0' && *end != TRAP_PARM_SEPARATOR; ++end ) ; dh = DIGPathOpen( parms, end - parms, DEFAULT_TRP_EXT, NULL, 0 ); if( dh == DIG_NIL_HANDLE ) { sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms ); return( buff ); } err = ReadInTrap( DIGGetSystemHandle( dh ) ); DIGPathClose( dh ); sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms ); if( err == NULL ) { if( (err = SetTrapHandler()) != NULL || (err = CopyEnv()) != NULL ) { strcpy( buff, err ); } else { strcpy( buff, TC_ERR_WRONG_TRAP_VERSION ); head = MK_PM( TrapMem.segm.rm, 0 ); if( head->sig == TRAP_SIGNATURE ) { PMData->initfunc.s.offset = head->init; PMData->reqfunc.s.offset = head->req; PMData->finifunc.s.offset = head->fini; PMData->initfunc.s.segment = TrapMem.segm.rm; PMData->reqfunc.s.segment = TrapMem.segm.rm; PMData->finifunc.s.segment = TrapMem.segm.rm; parms = end; if( *parms != '\0' ) ++parms; if( CallTrapInit( parms, buff, trap_ver ) ) { if( TrapVersionOK( *trap_ver ) ) { TrapVer = *trap_ver; ReqFunc = DoTrapAccess; return( NULL ); } strcpy( buff, TC_ERR_WRONG_TRAP_VERSION ); } } } } KillTrap(); return( buff ); }
static char *CopyEnv( void ) { char __far *envarea; uint_16 envsize; #ifdef __OSI__ { extern char *_EnvPtr; envarea = _EnvPtr; } #else envarea = MK_FP( *(addr_seg __far *)MK_FP( _psp, PSP_ENVSEG_OFF ), 0 ); #endif envsize = EnvAreaSize( envarea ); PMData->envseg.dpmi_adr = DPMIAllocateDOSMemoryBlock( _NBPARAS( envsize ) ); if( PMData->envseg.segm.pm == 0 ) { return( TC_ERR_OUT_OF_DOS_MEMORY ); } _fmemcpy( MK_PM( PMData->envseg.segm.rm, 0 ), envarea, envsize ); return( NULL ); }
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver ) { char *err; const char *ptr; dig_ldhandle ldfh; trap_file_header __far *head; #ifdef USE_FILENAME_VERSION char filename[256]; char *p; #endif if( parms == NULL || *parms == '\0' ) { parms = DEFAULT_TRP_NAME; } #ifdef USE_FILENAME_VERSION for( ptr = parms, p = filename; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) { *p++ = *ptr; } *p++ = ( USE_FILENAME_VERSION / 10 ) + '0'; *p++ = ( USE_FILENAME_VERSION % 10 ) + '0'; *p = '\0'; ldfh = DIGLoader( Open )( filename, p - filename, DEFAULT_TRP_EXT, NULL, 0 ); #else for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) { ; } ldfh = DIGLoader( Open )( parms, ptr - parms, DEFAULT_TRP_EXT, NULL, 0 ); #endif if( ldfh == DIGLD_NIL_HANDLE ) { sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms ); return( buff ); } err = ReadInTrap( ldfh ); DIGLoader( Close )( ldfh ); sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms ); if( err == NULL ) { if( (err = SetTrapHandler()) != NULL || (err = CopyEnv()) != NULL ) { strcpy( buff, err ); } else { strcpy( buff, TC_ERR_WRONG_TRAP_VERSION ); head = MK_PM( TrapMem.segm.rm, 0 ); if( head->sig == TRAP_SIGNATURE ) { PMData->initfunc.s.offset = head->init; PMData->reqfunc.s.offset = head->req; PMData->finifunc.s.offset = head->fini; PMData->initfunc.s.segment = TrapMem.segm.rm; PMData->reqfunc.s.segment = TrapMem.segm.rm; PMData->finifunc.s.segment = TrapMem.segm.rm; parms = ptr; if( *parms != '\0' ) ++parms; if( CallTrapInit( parms, buff, trap_ver ) ) { if( TrapVersionOK( *trap_ver ) ) { TrapVer = *trap_ver; ReqFunc = DoTrapAccess; return( NULL ); } strcpy( buff, TC_ERR_WRONG_TRAP_VERSION ); } } } } KillTrap(); return( buff ); }
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver ) { char *err; char *parm; char *end; handle dh; trap_file_header __far *head; char init_error[256]; if( trapbuff == NULL ) { trapbuff = DEFAULT_TRP_NAME; } end = strchr( trapbuff, PARM_SEPARATOR ); if( end == NULL ) { end = &trapbuff[ strlen( trapbuff ) ]; parm = end; } else { parm = end + 1; } dh = PathOpen( trapbuff, end - trapbuff, DEFAULT_TRP_EXT ); if( dh == NIL_HANDLE ) { sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff ); return( buff ); } err = ReadInTrap( GetSystemHandle( dh ) ); FileClose( dh ); if( err != NULL ) { sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff ); KillTrap(); return( buff ); } err = SetTrapHandler(); if( err != NULL ) { KillTrap(); return( err ); } err = CopyEnv(); if( err != NULL ) { KillTrap(); return( err ); } head = MK_PM( TrapMem.s.rm, 0 ); if( head->sig != TRAP_SIGNATURE ) { KillTrap(); strcpy( buff, TC_ERR_WRONG_TRAP_VERSION ); return( buff ); } PMData->initfunc.s.offset = head->init; PMData->reqfunc.s.offset = head->req; PMData->finifunc.s.offset = head->fini; PMData->initfunc.s.segment = TrapMem.s.rm; PMData->reqfunc.s.segment = TrapMem.s.rm; PMData->finifunc.s.segment = TrapMem.s.rm; if( !CallTrapInit( parm, init_error, trap_ver ) ) { KillTrap(); strcpy( buff, init_error ); return( buff ); } if( !TrapVersionOK( *trap_ver ) ) { KillTrap(); strcpy( buff, TC_ERR_WRONG_TRAP_VERSION ); return( buff ); } TrapVer = *trap_ver; ReqFunc = DoTrapAccess; return( NULL ); }