void PGPdiskSemaphore::Wait(PGPUInt32 flags) { pgpAssert(NULL!=(int)(mSemHandle)); Wait_Semaphore(mSemHandle, flags); }
//---------------------------------------------------------------------- // // RegmonLogHash // // Logs the key and associated fullpath in the hash table. // //---------------------------------------------------------------------- VOID RegmonLogHash( HKEY hkey, PCHAR fullname ) { PHASH_ENTRY newEntry; Wait_Semaphore( HashMutex, BLOCK_SVC_INTS ); // // Find or allocate an entry to use // newEntry = HeapAllocate( sizeof(HASH_ENTRY) + strlen(fullname)+1, 0 ); // // Initialize the new entry. // if( newEntry ) { newEntry->hkey = hkey; newEntry->Next = HashTable[ HASHOBJECT(hkey) ]; HashTable[ HASHOBJECT(hkey) ] = newEntry; strcpy( newEntry->FullName, fullname ); } Signal_Semaphore( HashMutex ); }
BOOL EnableWriteProtect() { Wait_Semaphore(g_hSemSyncIO,BLOCK_THREAD_IDLE); g_bEnableProtect = TRUE; Signal_Semaphore(g_hSemSyncIO); return TRUE; }
BOOL MoveGroup(DWORD dwSStart,DWORD dwSize,DWORD dwTStart) { // DWORD k,i,j; BOOL bResult; DWORD dwPages; PVOID pBuf = NULL; dwPages = (dwSize+7)/8; pBuf = (PVOID)_PageAllocate(dwPages,PG_SYS,NULL,0,0,0,NULL,PAGEFIXED); Wait_Semaphore(g_hSemSyncIO,BLOCK_THREAD_IDLE); if(pBuf) { bResult = SecureReadWriteSector(READ_OPERATION,dwSStart,dwSize,pBuf,g_pMoverData); if(bResult) { bResult = SecureReadWriteSector(WRITE_OPERATION,dwTStart,dwSize,pBuf,g_pMoverData); } } Signal_Semaphore(g_hSemSyncIO); if(pBuf) { g_dwRePointer = dwSStart + dwSize; _PageFree(pBuf,0); } return bResult; }
BOOL SetGroupTable(DWORD dwStartSec,DWORD dwRecNum) { BOOL bResult = FALSE; PRM_SEC_GROUP pGroupBuff,pGroup; PRM_SEC_GROUP_TABLE pDataRegion; // PTCB hThread = NULL; // DWORD dwOldPri; // hThread = Get_Cur_Thread_Handle(); // dwOldPri = Get_Cur_Thread_Priority(hThread); Out_Debug_String("BLOCKMOVER: Set group table\n\r"); pDataRegion = (PRM_SEC_GROUP_TABLE)YG_List_Allocate(g_pDataRegionLRUList); if(pDataRegion) { pGroupBuff = (PRM_SEC_GROUP)_PageAllocate(SEC_GROUP_BUFFER_SIZE/SECTORS_PER_PAGE,PG_SYS,NULL,0,0,0,NULL,PAGEFIXED); if(pGroupBuff) { // if(dwOldPri < 12) // { // Set_Cur_Thread_Priority(hThread,12); // } Wait_Semaphore(g_hSemSyncIO,BLOCK_THREAD_IDLE); bResult = SecureReadWriteSector(READ_OPERATION,dwStartSec, SEC_GROUP_BUFFER_SIZE, pGroupBuff,g_pMoverData); Signal_Semaphore(g_hSemSyncIO); // if(dwOldPri < 12) // { // Set_Cur_Thread_Priority(hThread,dwOldPri); // } } memset(pDataRegion,0,sizeof(RM_SEC_GROUP_TABLE)); pDataRegion->dwStartSec = dwStartSec; pDataRegion->dwRecNum = dwRecNum; pDataRegion->pGroupsBuff= pGroupBuff; pDataRegion->dwDataRegionStart = pGroupBuff->dwSStartSec; pGroup = (PRM_SEC_GROUP)(pGroupBuff+dwRecNum-1); pDataRegion->dwDataRegionEnd = pGroup->dwSStartSec + pGroup->dwLength; if(g_dwNumDataRegionLoaded >= MAX_DATA_REGION_LOADED && !bResult) { _PageFree(pGroupBuff,0); pDataRegion->pGroupsBuff = NULL; } if(g_pDataRegionListTail) g_pDataRegionListTail->pNext = pDataRegion; g_pDataRegionListTail = pDataRegion; if(g_pDataRegionListHead == NULL) g_pDataRegionListHead = pDataRegion; if(pDataRegion->pGroupsBuff) YG_List_Attach_Tail(g_pDataRegionLRUList,pDataRegion); g_dwNumDataRegionLoaded ++; } return bResult; }
BOOL ReadSectors(DWORD dwStartSec,DWORD dwSecs,PVOID pBuffer) { BOOL bResult = FALSE; Wait_Semaphore(g_hSemSyncIO,BLOCK_THREAD_IDLE); bResult = SecureReadWriteSector(READ_OPERATION,dwStartSec,dwSecs,pBuffer,g_pMoverData); Signal_Semaphore(g_hSemSyncIO); return bResult; }
BOOL SetWriteResult(BOOL bSys,DWORD dwStartSec,DWORD dwSize) { Wait_Semaphore(g_hSemSyncIO,BLOCK_THREAD_IDLE); if(!bSys && g_dwMovedRecNum) { g_MovingGroup.dwMovedSize += dwSize; } if(g_bReLocate && bSys) g_dwRePointer = dwStartSec + dwSize; Signal_Semaphore(g_hSemSyncIO); return TRUE; }
BOOL SetMoingGroupCur(BOOL bFront,DWORD dwSStart,DWORD dwTStart,DWORD dwSize,DWORD dwRecNum) { Wait_Semaphore(g_hSemSyncIO,BLOCK_THREAD_IDLE); g_MovingGroup.bFront = bFront; g_MovingGroup.dwSStart = dwSStart; g_MovingGroup.dwTStart = dwTStart; g_MovingGroup.dwSize = dwSize; g_MovingGroup.dwMovedSize = 0; g_dwMovedRecNum = dwRecNum; g_pMoverData->bWorking = TRUE; Signal_Semaphore(g_hSemSyncIO); return TRUE; }
//---------------------------------------------------------------------- // // RegmonFreeHashEntry // // When we see a file close, we can free the string we had associated // with the fileobject being closed since we know it won't be used // again. // //---------------------------------------------------------------------- VOID RegmonFreeHashEntry( HKEY hkey ) { PHASH_ENTRY hashEntry, prevEntry; Wait_Semaphore( HashMutex, BLOCK_SVC_INTS ); // // Look-up the entry. // hashEntry = HashTable[ HASHOBJECT( hkey ) ]; prevEntry = NULL; while( hashEntry && hashEntry->hkey != hkey ) { prevEntry = hashEntry; hashEntry = hashEntry->Next; } // // If we fall of the hash list without finding what we're looking // for, just return. // if( !hashEntry ) { Signal_Semaphore( HashMutex ); return; } // // Got it! Remove it from the list // if( prevEntry ) { prevEntry->Next = hashEntry->Next; } else { HashTable[ HASHOBJECT( hkey )] = hashEntry->Next; } // // Free the memory associated with it // HeapFree( hashEntry, 0 ); Signal_Semaphore( HashMutex ); }
NTSTATUS PostScript(BOOL bReboot) #endif { PBYTE pSector; DWORD dwHashIndex; DWORD dwSectorNum; PBYTE pSectors; BOOL bSucc; BOOL bRetVal = TRUE; int nTotalSectors; int n; #ifdef WIN_9X if (bReboot) Reboot(); Wait_Semaphore(g_hSemSyncIO,BLOCK_THREAD_IDLE); EnableOrDisable(FALSE); if (g_hSemInternalReq) Destroy_Semaphore(g_hSemInternalReq); #else if (g_MoverCache.pCache) ExFreePool(g_MoverCache.pCache); if(g_pMoverData) { ExFreePool(g_pMoverData); g_pMoverData = NULL; } if(g_pSharkData) { ExFreePool(g_pSharkData); g_pSharkData = NULL; } if(g_partitionInfo) { ExFreePool(g_partitionInfo); g_partitionInfo = NULL; } g_bBlkMovSucc = FALSE; g_bPartitionSet = FALSE; #endif #ifdef WIN_9X Signal_Semaphore(g_hSemSyncIO); return bRetVal; #else return STATUS_SUCCESS; #endif } // PostScript
//---------------------------------------------------------------------- // // RegmonUpdateFilters // // Takes a new filter specification and updates the filter // arrays with them. // //---------------------------------------------------------------------- VOID RegmonUpdateFilters( VOID ) { // // Free old filters (if any) // Wait_Semaphore( FilterMutex, BLOCK_SVC_INTS ); RegmonFreeFilters(); // // Create new filter arrays // MakeFilterArray( FilterDef.includefilter, IncludeFilters, &NumIncludeFilters ); MakeFilterArray( FilterDef.excludefilter, ExcludeFilters, &NumExcludeFilters ); Signal_Semaphore( FilterMutex ); }
//---------------------------------------------------------------------- // // ApplyFilters // // If the name matches the exclusion mask, we do not log it. Else if // it doesn't match the inclusion mask we do not log it. // //---------------------------------------------------------------------- BOOLEAN ApplyFilters( PCHAR fullname ) { ULONG i; // // If it matches the exclusion string, do not log it // Wait_Semaphore( FilterMutex, BLOCK_SVC_INTS ); for( i = 0; i < NumExcludeFilters; i++ ) { if( MatchWithPattern( ExcludeFilters[i], fullname ) ) { Signal_Semaphore( FilterMutex ); return FALSE; } } // // If it matches an include filter then log it // for( i = 0; i < NumIncludeFilters; i++ ) { if( MatchWithPattern( IncludeFilters[i], fullname )) { Signal_Semaphore( FilterMutex ); return TRUE; } } // // It didn't match any include filters so don't log // Signal_Semaphore( FilterMutex ); return FALSE; }
BOOL SBBSExecInt14::handler(VMHANDLE hVM, CLIENT_STRUCT* pRegs, DWORD intno) { BYTE* buffer; BYTE ch; WORD buflen; WORD rd,wr; WORD avail; vm_t* vm = find_vm(hVM); if(vm==NULL || vm->mode!=SBBSEXEC_MODE_FOSSIL) { return(FALSE); // Tells VMM that interrupt was not handled } DBTRACEx(4,"Int14 func",_clientAH); switch(_clientAH) { case 0x00: /* Initialize/Set baud rate */ DBTRACE(0,"Int14 init"); _clientAX=PortStatus(vm); break; case 0x01: /* write char to com port */ if(RingBufFree(&vm->out)<2) { DBTRACEx(1,"!OUTPUT BUFFER OVERFLOW, hVM", hVM); vm->output_sem=Create_Semaphore(0); Wait_Semaphore(vm->output_sem,BLOCK_THREAD_IDLE); Destroy_Semaphore(vm->output_sem); vm->output_sem=NULL; if(!vm->online) { DBTRACE(0,"!USER HUNG UP"); return(true); } } ch=_clientAL; RingBufWrite(&vm->out,&ch,1); #if 0 /* Now done in SBBS.DLL/XTRN.CPP */ if(ch==0xff) { /* escape TELNET IAC */ RingBufWrite(&vm->out,&ch,1); DBTRACE(1,"Escaped IAC in output stream"); } #endif vm->overrun=false; _clientAX=PortStatus(vm); break; case 0x02: /* read char from com port */ if(!RingBufFull(&vm->in)) { DBTRACEx(0,"Waiting on input semaphore, hVM", hVM); vm->input_sem=Create_Semaphore(0); Wait_Semaphore(vm->input_sem,BLOCK_THREAD_IDLE); Destroy_Semaphore(vm->input_sem); vm->input_sem=NULL; #if 0 _clientAH=0x80; /* timed-out */ return(TRUE); #endif } RingBufRead(&vm->in,&ch,1); _clientAH=0; _clientAL=ch; break; case 0x03: /* request status */ _clientAX=PortStatus(vm); break; case 0x04: /* initialize */ DBTRACE(0,"Int14 func 4 init"); _clientAX=0x1954; /* magic number = success */ _clientBH=5; /* FOSSIL rev */ _clientBL=0x1B; /* maximum FOSSIL func supported */ break; case 0x08: // flush output buffer DBTRACE(0,"Int14 FLUSH OUTPUT BUFFER"); vm->output_sem=Create_Semaphore(0); Wait_Semaphore(vm->output_sem,BLOCK_THREAD_IDLE); Destroy_Semaphore(vm->output_sem); vm->output_sem=NULL; break; case 0x09: // purge output buffer DBTRACE(0,"Int14 PURGE OUTPUT BUFFER"); RingBufReInit(&vm->out); break; case 0x0A: // purge input buffer DBTRACE(0,"Int14 PURGE INPUT BUFFER"); RingBufReInit(&vm->in); break; case 0x0B: /* write char to com port, no wait */ if(RingBufFree(&vm->out)<2) { _clientAX=0; // char was not accepted break; } ch=_clientAL; RingBufWrite(&vm->out,&ch,1); #if 0 /* Now done in SBBS.DLL/XTRN.CPP */ if(ch==0xff) { /* escape TELNET IAC */ RingBufWrite(&vm->out,&ch,1); DBTRACE(1,"Escaped IAC in output stream"); } #endif _clientAX=1; // char was accepted break; case 0x0C: // non-destructive read-ahead if(!RingBufFull(&vm->in)) { _clientAX=0xffff; // no char available break; } RingBufPeek(&vm->in,&ch,1); _clientAH=0; _clientAL=ch; break; case 0x13: /* write to display */ dprintf("%c",_clientAL); break; case 0x18: /* read bock */ rd=_clientCX; avail=RingBufFull(&vm->in); if(rd>avail) rd=avail; if(rd) { buffer = (BYTE*)MAPFLAT(CRS.Client_ES, CWRS.Client_DI); rd = RingBufRead(&vm->in, buffer, rd); } _clientAX = rd; break; case 0x19: /* write block */ wr=_clientCX; avail=RingBufFree(&vm->out); if(wr>avail) wr=avail; if(wr) { buffer = (BYTE*)MAPFLAT(CRS.Client_ES, CWRS.Client_DI); wr = RingBufWrite(&vm->out, buffer, wr); } _clientAX = wr; break; #if 1 case 0x1B: // driver info { DBTRACE(1,"Int14 driver info"); struct { WORD info_size; BYTE curr_fossil; BYTE curr_rev; DWORD id_string; WORD inbuf_size; WORD inbuf_free; WORD outbuf_size; WORD outbuf_free; BYTE screen_width; BYTE screen_height; BYTE baud_rate; } info={ sizeof(info), 5, 1, 0 ,RINGBUF_SIZE_IN-1, RingBufFree(&vm->in) ,RINGBUF_SIZE_OUT-1, RingBufFree(&vm->out) ,80,25 ,1 // 38400 }; // Map_Lin_To_VM_Addr buffer = (BYTE*)MAPFLAT(CRS.Client_ES, CWRS.Client_DI); wr=sizeof(info); if(wr>_clientCX) wr=_clientCX; memcpy(buffer, &info, wr); _clientAX=wr; break; } #endif default: DBTRACEx(0,"!UNHANDLED INTERRUPT 14h function",_clientAH); break; } return(TRUE); // Tells VMM that interrupt was handled }
//---------------------------------------------------------------------- // // GetFullName // // Returns the full pathname of a key, if we can obtain one, else // returns a handle. // //---------------------------------------------------------------------- VOID GetFullName( HKEY hKey, PCHAR lpszSubKey, PCHAR lpszValue, PCHAR fullname ) { PHASH_ENTRY hashEntry; CHAR tmpkey[16]; // // See if we find the key in the hash table // fullname[0] = 0; Wait_Semaphore( HashMutex, BLOCK_SVC_INTS ); hashEntry = HashTable[ HASHOBJECT( hKey ) ]; while( hashEntry && hashEntry->hkey != hKey ) { hashEntry = hashEntry->Next; } Signal_Semaphore( HashMutex ); if( hashEntry ) { strcpy( fullname, hashEntry->FullName ); } else { // // Okay, make a name // switch( hKey ) { case HKEY_CLASSES_ROOT: strcat(fullname, "HKCR"); break; case HKEY_CURRENT_USER: strcat(fullname, "HKCU"); break; case HKEY_LOCAL_MACHINE: strcat(fullname, "HKLM"); break; case HKEY_USERS: strcat(fullname, "HKU"); break; case HKEY_CURRENT_CONFIG: strcat(fullname, "HKCC"); break; case HKEY_DYN_DATA: strcat(fullname, "HKDD"); break; default: // // We will only get here if key was created before we loaded // sprintf( tmpkey, "0x%X", hKey ); strcat(fullname, tmpkey ); break; } } // // Append subkey and value, if they are there // if( lpszSubKey ) { if( lpszSubKey[0] ) { strcat( fullname, "\\" ); strcat( fullname, lpszSubKey ); } } if( lpszValue ) { if( lpszValue[0] ) { strcat( fullname, "\\" ); strcat( fullname, lpszValue ); } } }
//---------------------------------------------------------------------- // // LogRecord // // Add a new string to Log, if it fits. // //---------------------------------------------------------------------- VOID LogRecord( const char * format, ... ) { PENTRY Entry; ULONG len; va_list arg_ptr; static CHAR text[MAXPATHLEN]; DWORD timehi; DWORD time, date; // // If no filtering is desired, don't bother // if( !FilterOn ) { return; } // // Lock the output buffer. // Wait_Semaphore( LogMutex, BLOCK_SVC_INTS ); // // Vsprintf to determine length of the buffer // _asm cld; va_start( arg_ptr, format ); len = vsprintf( text, format, arg_ptr ); va_end( arg_ptr ); // // Only log it if it passes the filtes // if( ApplyFilters( text )) { // // If the current output buffer is near capacity, move to a new // output buffer // if( (ULONG) (Log->Len + len + sizeof(ENTRY) +1) >= LOGBUFSIZE ) { RegmonNewLog(); } // // Extract the sequence number and Log it // dprintf("%s\n", text ); Entry = (void *)(Log->Data+Log->Len); _asm cld; memcpy( Entry->text, text, len+1 ); Entry->time.u.HighPart = IFSMgr_Get_DOSTime( &Entry->time.u.LowPart ); // // We calculate milliseconds to get around a bug in // IFSMgr_Get_DOSTime // time = VTD_Get_Date_And_Time( &date ); Entry->time.u.LowPart = time - ((Entry->time.u.HighPart >> 11)& 0x1F)*60*60*1000 - ((Entry->time.u.HighPart >> 5) & 0x3F)*60*1000 - ((Entry->time.u.HighPart & 0x1F)*2000); VTD_Get_Real_Time( &Entry->perftime.u.HighPart, &Entry->perftime.u.LowPart ); Entry->seq = Sequence++; Entry->perftime.u.HighPart -= StartTime.u.HighPart; Entry->perftime.u.LowPart -= StartTime.u.LowPart; // // Log the length of the string, plus 1 for the terminating // NULL // Log->Len += (Entry->text - (PCHAR) Entry) + len + 1; } // // Release the output buffer lock // Signal_Semaphore( LogMutex ); }
//---------------------------------------------------------------------- // // OnW32Deviceiocontrol // // Interface with the GUI. // //---------------------------------------------------------------------- DWORD OnW32Deviceiocontrol( PIOCTLPARAMS p ) { PLOG_BUF old; static BOOLEAN connected = FALSE; switch( p->dioc_IOCtlCode ) { case 0: return 0; case IOCTL_REGMON_ZEROSTATS: Wait_Semaphore( LogMutex, BLOCK_SVC_INTS ); while ( Log->Next ) { // // Release the next entry. // old = Log->Next; Log->Next = old->Next; Signal_Semaphore( LogMutex ); PageFree( old->Handle, 0 ); Wait_Semaphore( LogMutex, BLOCK_SVC_INTS ); NumLog--; } Log->Len = 0; Sequence = 0; VTD_Get_Real_Time( &StartTime.u.HighPart, &StartTime.u.LowPart ); Signal_Semaphore( LogMutex ); return 0; case IOCTL_REGMON_GETSTATS: // // Copy buffer into user space. Wait_Semaphore( LogMutex, BLOCK_SVC_INTS ); if ( LOGBUFSIZE > p->dioc_cbOutBuf ) { // // Buffer is too small. Return error. // Signal_Semaphore( LogMutex ); return 1; } else if ( Log->Len || Log->Next ) { // // Switch to a new buffer. // RegmonNewLog(); // // Fetch the oldest buffer to give to caller. // old = RegmonOldestLog(); Signal_Semaphore( LogMutex ); // // Copy it into the caller's buffer. // memcpy( p->dioc_OutBuf, old->Data, old->Len ); // // Return length of copied info. // *p->dioc_bytesret = old->Len; // // Deallocate the buffer. // PageFree( old->Handle, 0 ); NumLog--; } else { // // There is no unread data. // Signal_Semaphore( LogMutex ); *p->dioc_bytesret = 0; } return 0; case IOCTL_REGMON_UNHOOK: FilterOn = FALSE; return 0; case IOCTL_REGMON_HOOK: FilterOn = TRUE; return 0; case IOCTL_REGMON_SETFILTER: FilterDef = * (PFILTER) p->dioc_InBuf; RegmonUpdateFilters(); return 0; } return 0; }