int Driver_Restore_Mode() { union REGS regs; reg_ax = 0x3; int86( 0x10, ®s, ®s ); #ifdef DOSX286 DosFreeSeg( FP_SEG( Vio ) ); #endif return 1; /* success */ }
VOID main(VOID) { USHORT usReturn_Code; /* Dos function Return Code */ PSZ pszName = SHARENAME; /* Shareable memory block name */ SEL selMem_Selector; /* Receive Segment selector */ PSZ pszSemName = SEMNAME; /* System semaphore name */ HSEM hsemSemHandle; /* System semaphore Handle */ WATCH FAR * Watch_Ptr; /* WATCH pointer */ /* Get Access to Shareable memory Block */ usReturn_Code = DosGetShrSeg(pszName, & selMem_Selector); if (usReturn_Code == 0) { Watch_Ptr = (WATCH FAR *) MAKEP(selMem_Selector,0); DosOpenSem( & hsemSemHandle, /* Open System semaphore */ pszSemName); DosSemRequest(hsemSemHandle, /* Waits for shared resources */ SEM_INDEFINITE_WAIT); /* Restore Init value count if WATCHDOG enabled */ if (Watch_Ptr->Flag & ENABLE_MASK) Watch_Ptr->Counter = Watch_Ptr->Counter_Init_Value ; DosSemClear(hsemSemHandle); /* Release shared resources */ DosFreeSeg(selMem_Selector); /* Freeing Shared memory */ } else { DosBeep(262,250);DosBeep(330,250);DosBeep(392,250);DosBeep(494,250); DosBeep(392,250);DosBeep(330,250);DosBeep(262,250); #ifdef DEBUG printf("\n -*-*- STARTTPS Error Code %04x -*-*-\n",usReturn_Code); printf(" -*- WatchDog not Started -*-\n"); #endif } /* endif */ DosExit((USHORT) 0,usReturn_Code); /* Exit Process */ } /* end of main program */
static int DoFreeSeg( __segment seg ) { #if defined(__WINDOWS_286__) HANDLE hmem; hmem = (HANDLE)GlobalHandle( seg ); if( hmem == NULL ) { return( -1 ); } GlobalUnlock( hmem ); if( GlobalFree( hmem ) == hmem ) { return( -1 ); } return( 0 ); #else return( DosFreeSeg( seg ) ); #endif }
// // Free the GetInfo buffer VOID NetApiBufferFree(PCHAR pBufPtr) { // #if defined(PMEMTRACE) usNumFrees++; #endif /* defined(PMEMTRACE) */ if (pBufPtr == pFirstBuffer) { #if defined(PMEMTRACE) usNumStaticFrees++; #endif /* defined(PMEMTRACE) */ bBigBufferInUse = FALSE; } else { #if defined(PMEMTRACE) usNumDynamicFrees++; #endif /* defined(PMEMTRACE) */ DosFreeSeg(SELECTOROF(pBufPtr)); } return; }
VOID Freeseg(PVOID pv) { printf("Freeing %p\n", pv); DosFreeSeg(SELECTOROF(pv)); }
USHORT MFreeMem(CHAR FAR *pBuffer) { return(DosFreeSeg(SELECTOROF(pBuffer))); }
static int executeAsync( const char *command, const char *parameters, const KWBoolean synchronous, const KWBoolean foreground ) { STARTDATA sd; PID childPID; static int instance = 0; /* Number of program we've invoke */ char queueName[FILENAME_MAX]; PVOID queueDataAddress; BYTE queueElementPriority; HQUEUE queueHandle; #ifdef __OS2__ APIRET rc; REQUESTDATA queueRequest; ULONG sessID; ULONG queueDataLength; #else USHORT rc; QUEUERESULT queueRequest; USHORT sessID; USHORT queueDataLength; #ifndef SSF_RELATED_CHILD #define SSF_RELATED_INDEPENDENT 0 #define SSF_RELATED_CHILD 1 #define SSF_FGBG_FORE 0 #define SSF_FGBG_BACK 1 #define SSF_TRACEOPT_NONE 0 #define SSF_INHERTOPT_PARENT 1 #define SSF_TYPE_DEFAULT 0 #define SSF_CONTROL_MAXIMIZE 0x0002 #define SSF_CONTROL_MINIMIZE 0x0004 #endif /* SSF_RELATED_CHILD */ #endif /*--------------------------------------------------------------------*/ /* Special case foreground synchronous commands; this */ /* insures redirected input is processed properly. */ /*--------------------------------------------------------------------*/ if ( synchronous ) { int result = spawnl( P_WAIT, (char *) command, (char *) command, (char *) parameters, NULL); if (result == -1) /* Did spawn fail? */ printerr(command); /* Yes --> Report error */ return result; } /* */ /*--------------------------------------------------------------------*/ /* Initialize the start session parameters */ /*--------------------------------------------------------------------*/ memset( (void *) &sd, 0, sizeof sd ); sd.Length = 32; /* Just basic info + InheritOpt */ sd.FgBg = (USHORT) (foreground ? SSF_FGBG_FORE : SSF_FGBG_BACK); sd.TraceOpt = SSF_TRACEOPT_NONE; sd.PgmName = (PSZ) command; sd.PgmInputs = (PSZ) parameters; sd.Environment = 0; /* Just use our own envionment */ sd.InheritOpt = SSF_INHERTOPT_PARENT; /* Pass it to child */ sd.SessionType = SSF_TYPE_DEFAULT; /* Let the system pick session type */ sd.PgmControl = (USHORT) (foreground ? SSF_CONTROL_MAXIMIZE : SSF_CONTROL_MINIMIZE); /*--------------------------------------------------------------------*/ /* Build the queue to listen for the subtask ending. This */ /* code is actually correct, but ignored since we returned */ /* after spawn() above. */ /*--------------------------------------------------------------------*/ if ( synchronous ) { sprintf(queueName, "\\queues\\pid%d\\pgm%d", (int) getpid(), instance++); rc = DosCreateQueue( &queueHandle, #ifdef __OS2__ QUE_FIFO | QUE_CONVERT_ADDRESS, #else QUE_FIFO, #endif (PSZ) queueName ); if ( rc ) { printOS2error( queueName, rc ); return -4; /* Report command never was run */ } sd.TermQ = (PSZ) queueName; sd.Related = SSF_RELATED_CHILD; /* Child session */ } /* if ( synchronous ) */ else { sd.TermQ = (PSZ) 0; /* Don't wait for session end */ sd.Related = SSF_RELATED_INDEPENDENT; /* Not a child session */ } /* else */ rc = DosStartSession( &sd, &sessID, &childPID ); if ( rc ) { printOS2error( command ? command : parameters, rc ); return -5; } /*--------------------------------------------------------------------*/ /* If the command is running asynchonously return to caller */ /*--------------------------------------------------------------------*/ if ( ! synchronous ) return 0; /*--------------------------------------------------------------------*/ /* Wait for the child to complete */ /*--------------------------------------------------------------------*/ memset( (void *) &queueRequest, 0, sizeof queueRequest ); rc = DosReadQueue( queueHandle, &queueRequest, &queueDataLength, &queueDataAddress, 0, /* First element in the queue */ 0, /* Wait for queue to be ready */ &queueElementPriority, 0); /* Semaphore handle -- not used */ if ( rc ) { printOS2error( queueName, rc ); panic(); } rc = ((unsigned short FAR*) queueDataAddress)[1]; #ifdef __OS2__ DosFreeMem( queueDataAddress ); #else DosFreeSeg( SELECTOROF(queueDataAddress) ); #endif return (int) rc; } /* executeAsync */
AFILE *makefp(DEBFILE *pdf, ULONG mid, ULONG instaddr, UCHAR *fname) { uchar *cp = NULL; uint segbase; uchar *srcbuf; uint Nlines; uint Tlines; SEL srcsel; SEL offsel; ushort srcseglen; ushort *offtab; AFILE *fp; int ftype; int OffsetTableBufSize; char FileNameBuffer[CCHMAXPATH]; char FileSpecBuffer[CCHMAXPATH]; UCHAR FileNameLength; LNOTAB *pLnoTabEntry; int sfi; MODULE *pModule; CSECT *pCsect; UCHAR *pFileName; UCHAR *fn; BOOL found; ULONG junk; int lno; if( fname ) { /***************************************************************************/ /* - if fname is specified, then the view is to be build using the source */ /* file name supplied by the user as in the case of getfile. */ /* - we need to find an sfi to associate with the file. */ /* - build a length-prefixed z-string from the supplied name. */ /***************************************************************************/ fn = strrchr(fname, '\\'); fn = (fn) ? (fn + 1) : fname ; pFileName = Talloc( strlen(fn) + 2 ); *pFileName = (UCHAR)strlen(fn); strcpy( pFileName+1, fn ); found = FALSE; for( sfi=mid=0, pdf = pnode->ExeStruct; pdf != NULL; pdf=pdf->next ) { mid = MapSourceFileToMidSfi( pFileName, &sfi, pdf ); if( mid && sfi ) { found = TRUE; memset(FileNameBuffer, 0, sizeof(FileNameBuffer) ); strcpy(FileNameBuffer+1, fname ); FileNameBuffer[0] = (UCHAR)strlen(fname); break; } } Tfree( pFileName ); if( found == FALSE ) return(NULL); instaddr = DBMapLno(mid, 0, sfi, &junk , pdf ); DBMapInstAddr(instaddr, &pLnoTabEntry, pdf); lno = 0; if( pLnoTabEntry ) lno = pLnoTabEntry->lno; } else { /***************************************************************************/ /* - we're going to build the view from an instruction address. */ /***************************************************************************/ if ( pdf->SrcOrAsm == SOURCE_LEVEL ) { mid = DBMapInstAddr(instaddr, &pLnoTabEntry, pdf); lno = sfi = 0; if( pLnoTabEntry ) { lno = pLnoTabEntry->lno; sfi = pLnoTabEntry->sfi; } if( (pLnoTabEntry != NULL) && (sfi != 0) ) { memset(FileNameBuffer, 0, sizeof(FileNameBuffer) ); cp = GetFileName( mid, sfi ); if( cp ) strcpy(FileNameBuffer, cp); } } } if(ftype) { findsrc(FileNameBuffer+1,FileSpecBuffer+1,sizeof(FileSpecBuffer) ); FileSpecBuffer[0] = (UCHAR)strlen(FileSpecBuffer+1); memcpy(FileNameBuffer,FileSpecBuffer,sizeof(FileSpecBuffer)); } FileNameLength = FileNameBuffer[0]; fp = (AFILE*) Talloc(SizeOfAFILE(FileNameLength)); memcpy( fp->filename, FileNameBuffer, FileNameLength+1); /****************************************************************************/ /* - allocate 64k for the source buffer. */ /* - allocate 20k for the offset buffer. */ /* - load source file into a buffer and define: */ /* - srcsel = source buffer selector. */ /* - offsel = offset buffer selector. */ /* - 0 = number of lines to skip at the beginning of the file. */ /* - srcseglen = source buffer bytes actually used by the load. */ /* - Nlines = number of source lines in the buffer. */ /* - Tlines = number of source lines in the entire file. */ /* - reallocate the source buffer to size really needed. */ /****************************************************************************/ Nlines = srcsel = offsel = 0; if( !DosAllocSeg(0,(PSEL)&srcsel,0) && !DosAllocSeg(20*1024,(PSEL)&offsel, 0) ) { LoadSource( fp->filename+1, (UCHAR *)Sel2Flat(srcsel), (USHORT *)Sel2Flat(offsel), 0, &srcseglen, &Nlines, &Tlines); if( Nlines ) DosReallocSeg(srcseglen, srcsel); } /****************************************************************************/ /* - now, define the view structure. */ /****************************************************************************/ fp->shower = showA; fp->pdf = pdf; fp->mid = mid; fp->sfi = sfi; fp->mseg = segbase; fp->Tlines = Tlines; /* number of lines in file. */ fp->Nlines = Nlines; /* number of lines in source buffer. */ fp->Nbias = 0; /* number of lines skipped in source.*/ fp->topline = 1; /* init to 1st line in the file. */ fp->csrline = lno; /* " " */ fp->hotline = lno; /* " " */ fp->hotaddr = instaddr; fp->skipcols = 0; /* columns skipped on left. */ fp->Nshown = 0; fp->topoff = instaddr; fp->csr.row = 0; fp->csr.col = 0; fp->csr.mode = CSR_NORMAL; fp->sview = NOSRC; /* assume no source disassembler view*/ fp->flags = ASM_VIEW_NEW; if( Nlines ) { srcbuf = (uchar*)Sel2Flat(srcsel); fp->source = srcbuf; /**************************************************************************/ /* Allocate the offtab[] buffer to hold Nlines + 1 offsets. We add the 1 */ /* so that we can make the offset table indices line up with the */ /* source line numbers. */ /**************************************************************************/ OffsetTableBufSize = (Nlines+1)*sizeof(USHORT); offtab = (USHORT*) Talloc(OffsetTableBufSize); memcpy(offtab + 1, (uchar*)Sel2Flat(offsel), Nlines*sizeof(USHORT) ); fp->offtab = offtab; fp->flags = 0; /* clear asm flag. */ if( Tlines > Nlines ) /* does compressed source exceed 64k?*/ fp->flags |= AF_HUGE; /* mark afile with huge file flag */ fp->shower = showC; /* display source */ fp->sview = MIXEDN; /* assume no source disassembler view*/ /* Flag all text lines for which a (line #, offset) pair exists. */ pModule = GetModuleWithAddr( instaddr, pdf ); if( pModule ) { for(pCsect = pModule->pCsects; pCsect != NULL; pCsect=pCsect->next ) { int NumEntries; NumEntries = pCsect->NumEntries; pLnoTabEntry = pCsect->pLnoTab; if( (pLnoTabEntry != NULL) && ( NumEntries > 0 ) ) { for( ; NumEntries; pLnoTabEntry++, NumEntries-- ) { if( pLnoTabEntry->sfi == sfi ) { int lno; lno = pLnoTabEntry->lno; if( (lno != 0) && (lno <= Nlines) ) { *(srcbuf + offtab[lno] - 1) |= LINE_OK; } } } } } } MarkLineBRKs( fp ); /* mark the active breakpoints */ } if( offsel ) /* if there was an offset segment */ DosFreeSeg(offsel); /* allocated then free it up */ if( !Nlines && srcsel ) /* if there was no source then */ DosFreeSeg(srcsel); /* free up the temp source buffer */ return( fp ); }
int set_ea(char FAR *i_eas, char *name) { #ifdef HAVE_EAS int rc=0; char FAR *eas; unsigned int i, total; #if TARGET==OS2 #ifdef __32BIT__ FILESTATUS4 fs; EAOP2 eaop; char FAR *real_pfeal; PFEA2LIST pfeal; PFEA2 pf, opf; #else EAOP eaop; PFEALIST pfeal; PFEA pf; FILESTATUS2 fs; SEL selector; #endif #elif TARGET==WIN32 PFEALIST pfeal0, pfeal; PFEA pf; struct nt_sid *sid; unsigned char *pstreambuf, *streambuf; WIN32_STREAM_ID w32sid; unsigned long stream_len; #endif eas=i_eas; if(discard_ea(name)) return(-1); if((total=mget_word(eas))==0) return(0); #if TARGET==OS2 #ifdef __32BIT__ /* This takes the 4-byte prefixes into account (are the V1.2 EAs still valid if they flow beyond 64K when the oNextEntryOffset is applied?). Also, we ensure that it is aligned properly. In theory, there may be a way to crash this (72K doesn't consider the multitude of EAs) but we don't know/care about it -- ASR 17/10/2000 */ real_pfeal=(char FAR *)farmalloc_msg(73728); pfeal=(PFEA2LIST)align_dword(real_pfeal); eaop.fpFEA2List=pfeal; #else if(DosAllocSeg(65535U, &selector, SEG_NONSHARED)) return(-1); pfeal=(PFEALIST)MAKEP(selector, 0); eaop.fpFEAList=pfeal; #endif #elif TARGET==WIN32 pstreambuf=(char *)farmalloc_msg(65536+260*total); pfeal=pfeal0=(PFEALIST)(streambuf=align_dword(pstreambuf)); #endif eas+=2; pf=&pfeal->list[0]; for(i=0; i<total; i++) { #if TARGET==OS2&&defined(__32BIT__) opf=pf; #endif #if TARGET==WIN32 pf=&pfeal->list[0]; #endif pf->fEA=mget_byte(eas++); pf->cbName=mget_byte(eas++); pf->cbValue=mget_word(eas); eas+=2; #if TARGET==OS2&&defined(__32BIT__) far_memmove((char FAR *)pf+sizeof(FEA2)-1, eas, pf->cbName); *((char FAR *)pf+sizeof(FEA2)-1+pf->cbName)='\0'; #else /* Win32 or OS/2-16 */ far_memmove((char FAR *)pf+sizeof(FEA), eas, pf->cbName); *((char FAR *)pf+sizeof(FEA)+pf->cbName)='\0'; #endif eas+=pf->cbName; #if TARGET==OS2&&defined(__32BIT__) far_memmove((char FAR *)pf+sizeof(FEA2)+pf->cbName, eas, pf->cbValue); #else /* Win32 or OS/2-16 */ far_memmove((char FAR *)pf+sizeof(FEA)+pf->cbName+1, eas, pf->cbValue); #endif eas+=pf->cbValue; #if SFX_LEVEL>=ARJ #if TARGET==OS2&&defined(__32BIT__) if(ea_filter((char FAR *)pf+sizeof(FEA2), 0)&&((pf->fEA&FEA_NEEDEA)||!crit_eas)) #else /* Win32 or OS/2-16 */ if(ea_filter((char FAR *)pf+sizeof(FEA), 0)&&((pf->fEA&FEA_NEEDEA)||!crit_eas)) #endif #endif /* Update the offsets */ #if TARGET==OS2 #ifdef __32BIT__ pf=(PFEA2)((char FAR *)pf+sizeof(FEA2)+pf->cbName+pf->cbValue); #else pf=(PFEA)((char FAR *)pf+sizeof(FEA)+pf->cbName+1+pf->cbValue); #endif /* Align at DWORD boundary and issue the list fixups */ #ifdef __32BIT__ pf=(PFEA2)align_dword((char FAR *)pf); opf->oNextEntryOffset=(i+1==total)?0:(char FAR *)pf-(char FAR *)opf; #endif #elif TARGET==WIN32 pfeal=(PFEALIST)((char FAR *)pfeal+sizeof(FEALIST)+pf->cbName+1+pf->cbValue); if(i<total-1) pfeal=(PFEALIST)align_dword((char FAR*)pfeal); pfeal0->cbList=(i==total-1)? 0: (((char FAR *)pfeal)-((char FAR *)pfeal0)); pfeal0=pfeal; #endif } #if TARGET==OS2 pfeal->cbList=(char FAR *)pf-(char FAR *)pfeal; #ifdef __32BIT__ rc=DosSetPathInfo((PSZ)name, FIL_QUERYEASIZE, (PBYTE)&eaop, sizeof(eaop), 0); farfree(real_pfeal); #else rc=DosSetPathInfo((PSZ)name, FIL_QUERYEASIZE, (PBYTE)&eaop, sizeof(eaop), 0, 0L); DosFreeSeg(selector); #endif if(!rc) { #ifdef __32BIT__ if(DosQueryPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs))) #else if(DosQPathInfo(name, FIL_QUERYEASIZE, (PVOID)&fs, sizeof(fs), 0L)) #endif rc=-1; else if(fs.cbList<=4) rc=-1; } #elif TARGET==WIN32 if((sid=open_streams(name, 1))==NULL) rc=-1; else { memset(&w32sid, 0, sizeof(w32sid)); w32sid.dwStreamId=BACKUP_EA_DATA; w32sid.Size.LowPart=stream_len=(((char FAR *)pfeal)-streambuf); if(create_stream(&w32sid, sid)||write_stream(streambuf, stream_len, sid)<stream_len) rc=-1; close_streams(sid); } free(pstreambuf); #endif return(rc); #else return(-1); #endif }