PQTOPLEVEL32 prc32GetInfo2(ULONG fl, // in: QS32_* flags APIRET *parc) // out: error, ptr can be NULL { APIRET arc; PQTOPLEVEL32 pReturn = NULL; #define BUFSIZE (1024 * 1024) // 1 meg if (!(arc = DosAllocMem((PVOID*)&pReturn, BUFSIZE, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_TILE))) { if (arc = DosQuerySysState(fl, fl, // this was missing V0.9.10 (2001-04-08) [umoeller] 0, 0, (PCHAR)pReturn, BUFSIZE)) { DosFreeMem(pReturn); pReturn = NULL; } } if (parc) *parc = arc; return pReturn; }
APIRET QuerySysInfo(void) { APIRET RC; if(!pqData) pqData = (PQTOPLEVEL) new char[PQ_BUFSIZE]; memset(pqData, 0, PQ_BUFSIZE); RC = DosQuerySysState(0x1F, 0, 0, 0, pqData, PQ_BUFSIZE); return RC; }
MRESULT khs_umIsExceptWindow( HWND hwnd, MPARAM mp1, MPARAM mp2 ) { PKHSCD pkhscd = WinQueryWindowPtr( hwnd, 0 ); HWND hwndTarget = HWNDFROMMP( mp1 ); PID pid; PCHAR modulePath; PCHAR moduleName; ULONG maxPathLen; APIRET rc; BOOL result; WinQueryWindowProcess( hwndTarget, &pid, NULL ); #ifdef DEBUG fprintf( pkhscd->fp, "PID = %x\n", pid ); #endif memset( pkhscd->pQTopLevel, 0, DOSQSS_BUFSIZE ); rc = DosQuerySysState( 0x01, 0, pid, 1, pkhscd->pQTopLevel, DOSQSS_BUFSIZE ); if( rc != 0 ) return FALSE; DosQuerySysInfo( QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH, &maxPathLen, sizeof( ULONG )); modulePath = malloc( maxPathLen ); DosQueryModuleName( pkhscd->pQTopLevel->procdata->hndmod, maxPathLen, modulePath ); #ifdef DEBUG fprintf( pkhscd->fp, "Module path = %s\n", modulePath ); #endif moduleName = strrchr( modulePath, '\\' ); if( moduleName == NULL ) moduleName = modulePath; else moduleName++; #ifdef DEBUG fprintf( pkhscd->fp, "Module name = %s\n", moduleName ); #endif result = exceptFindName( pkhscd->exceptListBuf, moduleName ); free( modulePath ); #ifdef DEBUG fprintf( pkhscd->fp, "exceptFindName() = %ld\n", result ); fflush( pkhscd->fp ); #endif return MRFROMLONG( result ); }
ULONG APIENTRY getSGID( VOID ) { PQTOPLEVEL pQTopLevel = ( PQTOPLEVEL )m_achSysState; PPIB ppib; if( m_ulSGID != ( ULONG )-1 ) return m_ulSGID; DosGetInfoBlocks( NULL, &ppib ); DosQuerySysState( 0x01, 0, ppib->pib_ulpid, 1, pQTopLevel, BUF_SIZE ); m_ulSGID = pQTopLevel->procdata->sessid; return m_ulSGID; }
void FillMenu( HWND hwndMenu ) { char szPidPath[1024]; char szBuffer[1024]; char* pBuf; QSPTRREC* pRecHead; QSPREC* pApp; int numItems, iCounter; PVOID pBuffer; PSWBLOCK pSB; TASKDATA* data; SHORT id = ID_ITEM_FIRST; // Delete all current items numItems = LONGFROMMR( WinSendMsg( hwndMenu, MM_QUERYITEMCOUNT, 0, 0 )); while( numItems-- ) { MENUITEM mi; SHORT id = LONGFROMMR( WinSendMsg( hwndMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(0), 0 )); if( WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT( id, FALSE ), MPFROMP( &mi ))) { if( mi.hItem ) { data = (TASKDATA*)mi.hItem; free( data->szTitle ); free( data ); } } WinSendMsg( hwndMenu, MM_DELETEITEM, MPFROM2SHORT( id, FALSE ), 0 ); } if( bType ) { // Ctrl is pressed, get the processes in the system. pBuf = (char*)malloc( 0x8000 ); // Get processes DosQuerySysState( QS_PROCESS, 0, 0, 0, (char*)pBuf, 0x8000 ); // Point to first process pRecHead = (QSPTRREC*)pBuf; pApp = pRecHead->pProcRec; // While its a process record while( pApp->RecType == 1 ) { // Get module name for process memset( szPidPath, 0, _MAX_PATH ); DosQueryModuleName( pApp->hMte, 512, szPidPath ); if( strlen( szPidPath ) == 0 ) { // If no hit is the kernel if( pApp->type == 1 ) { sprintf( szPidPath, "VDM (%d)", pApp->pid ); } else { strcpy ( szPidPath, "*SYSINIT" ); } } else { // Else trim the path strcpy ( szBuffer, FileGetFileExt( szPidPath )); sprintf( szPidPath, "%s (%d)", szBuffer, pApp->pid ); } // add to menu data = (TASKDATA*)malloc( sizeof( TASKDATA )); data->szTitle = strdup( szPidPath ); data->hWindow = NULLHANDLE; data->pid = pApp->pid; switch( pApp->type ) { case 0: data->hIcon = ico_os2fs; break; case 1: data->hIcon = ico_dos; break; case 2: data->hIcon = ico_os2vio; break; case 3: data->hIcon = ico_pm; break; case 4: data->hIcon = ico_detach; break; default: data->hIcon = NULLHANDLE; break; } winhInsertMenuItem( hwndMenu, MIT_END, id++, szPidPath, MIS_OWNERDRAW, 0, data ); // get next record pApp=(QSPREC *)((pApp->pThrdRec) + pApp->cTCB); } free(pBuf); } else { // Get number of items in switchlist numItems = WinQuerySwitchList( WinQueryAnchorBlock( hwndMenu ), NULL, 0 ); // Get all items into buffer pBuffer = malloc(( numItems * sizeof(SWENTRY)) + sizeof(HSWITCH)); WinQuerySwitchList( WinQueryAnchorBlock(hwndMenu), (SWBLOCK*)pBuffer, (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH)); pSB = (PSWBLOCK)(pBuffer); for( iCounter = 0; iCounter < numItems; iCounter++ ) { // Should be JUMPABLE and VISIBLE to show in list if( pSB->aswentry[iCounter].swctl.uchVisibility == SWL_VISIBLE ) { // Put in menu data = (TASKDATA*)malloc( sizeof( TASKDATA )); data->szTitle = strdup( pSB->aswentry[iCounter].swctl.szSwtitle ); data->hWindow = pSB->aswentry[iCounter].swctl.hwnd; data->pid = pSB->aswentry[iCounter].swctl.idProcess; CleanString( data->szTitle ); if( pSB->aswentry[iCounter].swctl.hwndIcon != NULLHANDLE ) { data->hIcon = pSB->aswentry[iCounter].swctl.hwndIcon; } else { data->hIcon = (HPOINTER)WinSendMsg( data->hWindow, WM_QUERYICON, 0, 0 ); } winhInsertMenuItem( hwndMenu, MIT_END, id++, pSB->aswentry[iCounter].swctl.szSwtitle, MIS_OWNERDRAW, 0, data ); } } free(pBuffer); } }
int RAND_poll (void) { char failed_module[20]; QWORD qwTime; ULONG SysVars[QSV_FOREGROUND_PROCESS]; if (hDoscalls == 0) { ULONG rc = DosLoadModule (failed_module, sizeof (failed_module), "DOSCALLS", &hDoscalls); #ifndef __KLIBC__ if (rc == 0) { rc = DosQueryProcAddr (hDoscalls, 976, NULL, (PFN *) & DosPerfSysCall); if (rc) DosPerfSysCall = NULL; rc = DosQueryProcAddr (hDoscalls, 368, NULL, (PFN *) & DosQuerySysState); if (rc) DosQuerySysState = NULL; } #endif } /* Sample the hi-res timer, runs at around 1.1 MHz */ DosTmrQueryTime (&qwTime); RAND_add (&qwTime, sizeof (qwTime), 2); /* Sample a bunch of system variables, includes various process & memory statistics */ DosQuerySysInfo (1, QSV_FOREGROUND_PROCESS, SysVars, sizeof (SysVars)); RAND_add (SysVars, sizeof (SysVars), 4); /* If available, sample CPU registers that count at CPU MHz * Only fairly new CPUs (PPro & K6 onwards) & OS/2 versions support this */ if (DosPerfSysCall) { CPUUTIL util; if (DosPerfSysCall (CMD_KI_RDCNT, (ULONG) & util, 0, 0) == 0) { RAND_add (&util, sizeof (util), 10); } else { #ifndef __KLIBC__ DosPerfSysCall = NULL; #endif } } /* DosQuerySysState() gives us a huge quantity of process, thread, memory & handle stats */ if (DosQuerySysState) { char *buffer = OPENSSL_malloc (256 * 1024); if (DosQuerySysState (0x1F, 0, 0, 0, buffer, 256 * 1024) == 0) { /* First 4 bytes in buffer is a pointer to the thread count * there should be at least 1 byte of entropy per thread */ RAND_add (buffer, 256 * 1024, **(ULONG **) buffer); } OPENSSL_free (buffer); return 1; } return 0; }
double hb_secondsCPU( int n ) { double d = 0.0; #if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_UNIX ) FILETIME Create, Exit, Kernel, User; #endif #if defined( HB_OS_OS2 ) static ULONG s_timer_interval = 0; QSGREC ** pBuf; #endif if( ( n < 1 || n > 3 ) && ( n < 11 || n > 13 ) ) n = 3; #if defined( HB_OS_UNIX ) && ! defined( HB_OS_VXWORKS ) { struct tms tm; times( &tm ); if( n > 10 ) { n -= 10; if( n & 1 ) d += tm.tms_cutime; if( n & 2 ) d += tm.tms_cstime; } if( n & 1 ) d += tm.tms_utime; if( n & 2 ) d += tm.tms_stime; /* In POSIX-1996 the CLK_TCK symbol is mentioned as obsolescent */ #if 0 d /= CLK_TCK; #endif d /= ( double ) sysconf( _SC_CLK_TCK ); } #else if( n > 10 ) n -= 10; #if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) if( hb_iswinnt() && GetProcessTimes( GetCurrentProcess(), &Create, &Exit, &Kernel, &User ) ) { if( n & 1 ) { d += ( double ) ( ( ( HB_MAXINT ) User.dwHighDateTime << 32 ) + ( HB_MAXINT ) User.dwLowDateTime ); } if( n & 2 ) { d += ( double ) ( ( ( HB_MAXINT ) Kernel.dwHighDateTime << 32 ) + ( HB_MAXINT ) Kernel.dwLowDateTime ); } d /= 10000000.0; } else #elif defined( HB_OS_OS2 ) if( s_timer_interval == 0 ) DosQuerySysInfo( QSV_TIMER_INTERVAL, QSV_TIMER_INTERVAL, ( PVOID ) &s_timer_interval, sizeof( ULONG ) ); pBuf = ( QSGREC ** ) hb_xalloc( BUFSIZE ); if( pBuf ) { #if defined( __GNUC__ ) APIRET rc = DosQuerySysState( QS_PROCESS, 0L, _getpid(), 0L, pBuf, BUFSIZE ); #else APIRET rc = DosQuerySysState( QS_PROCESS, 0L, getpid(), 0L, pBuf, BUFSIZE ); #endif if( rc == NO_ERROR ) { QSGREC * pGrec = *pBuf; QSPREC * pPrec = ( QSPREC * ) ( ( ULONG ) pGrec + sizeof( QSGREC ) ); QSTREC * pTrec = pPrec->pThrdRec; int i; for( i = 0; i < pPrec->cTCB; i++, pTrec++ ) { if( n & 1 ) d += pTrec->usertime; if( n & 2 ) d += pTrec->systime; } d = d * 10.0 / s_timer_interval; } hb_xfree( pBuf ); } else #endif { /* TODO: this code is only for DOS and other platforms which cannot calculate process time */ if( n & 1 ) d = hb_dateSeconds(); } #endif return d; }
VOID update_thread( PVOID cntr ) { APIRET rc; HAB hab; HMQ hmq; PVOID pvFlipRaw, pvFlopRaw; QPROCESSARRAY apqFlipSorted, apqFlopSorted; APPRECORDARRAY removeList; QPROCESSARRAY procInsertList; QTHREADARRAY threadInsertList; QTHREADARRAY updateList; hab = WinInitialize( 0 ); hmq = WinCreateMsgQueue( hab, 0 ); rc = DosAllocMem( &pvFlipRaw, MEMPOOL, PAG_COMMIT | PAG_READ | PAG_WRITE ); rc = DosAllocMem( &pvFlopRaw, MEMPOOL, PAG_COMMIT | PAG_READ | PAG_WRITE ); rc = DosAllocMem( ( PPVOID ) &apqFlipSorted.pData, sizeof( PQPROCESS ) * MAX_PROCESSES, PAG_COMMIT | PAG_READ | PAG_WRITE ); apqFlipSorted.ulSize = 0; rc = DosAllocMem( ( PPVOID ) &apqFlopSorted.pData, sizeof( PQPROCESS ) * MAX_PROCESSES, PAG_COMMIT | PAG_READ | PAG_WRITE ); apqFlopSorted.ulSize = 0; rc = DosAllocMem( ( PPVOID ) &removeList.pData, sizeof( PAPPRECORD ) * ( MAX_PROCESSES + MAX_THREADS ), PAG_COMMIT | PAG_READ | PAG_WRITE ); removeList.ulSize = 0; rc = DosAllocMem( ( PPVOID ) &procInsertList.pData, sizeof( PQPROCESS ) * MAX_PROCESSES, PAG_COMMIT | PAG_READ | PAG_WRITE ); procInsertList.ulSize = 0; rc = DosAllocMem( ( PPVOID ) &threadInsertList.pData, sizeof( PQTHREAD ) * MAX_THREADS, PAG_COMMIT | PAG_READ | PAG_WRITE ); threadInsertList.ulSize = 0; rc = DosAllocMem( ( PPVOID ) &updateList.pData, sizeof( PQTHREAD ) * MAX_THREADS, PAG_COMMIT | PAG_READ | PAG_WRITE ); updateList.ulSize = 0; DosCreateMutexSem( NULL, &hmuxUpdate, 0L, FALSE ); /* * to save time, the update is done in the flip-flop way - this saves * the cost of reallocating and commiting memory * **/ while( TRUE ) { memset( pvFlipRaw, 0, MEMPOOL ); rc = DosQuerySysState( 0x01, 0L, 0L, 0L, ( PCHAR ) pvFlipRaw, MEMPOOL ); sort_raw( ( PQTOPLEVEL ) pvFlipRaw, &apqFlipSorted ); DosRequestMutexSem( hmuxUpdate, SEM_INDEFINITE_WAIT ); build_update_lists( &apqFlipSorted, &apqFlopSorted, &removeList, &procInsertList, &threadInsertList, &updateList ); update_container( ( HWND ) cntr, &removeList, &procInsertList, &threadInsertList, &updateList ); DosReleaseMutexSem( hmuxUpdate ); DosSleep( 5 * 1000 ); memset( pvFlopRaw, 0, MEMPOOL ); rc = DosQuerySysState( 0x01, 0L, 0L, 0L, ( PCHAR ) pvFlopRaw, MEMPOOL ); sort_raw( ( PQTOPLEVEL ) pvFlopRaw, &apqFlopSorted ); DosRequestMutexSem( hmuxUpdate, SEM_INDEFINITE_WAIT ); build_update_lists( &apqFlopSorted, &apqFlipSorted, &removeList, &procInsertList, &threadInsertList, &updateList ); update_container( ( HWND ) cntr, &removeList, &procInsertList, &threadInsertList, &updateList ); DosReleaseMutexSem( hmuxUpdate ); DosSleep( 5 * 1000 ); }; };
void linuxContinue ( char *error_message, int thread_num, /* Specific worker to launch or */ /* special value ALL_WORKERS */ int wait_flag) { #ifdef __linux__ #define PROCNAME "/proc/%d/exe" #endif #ifdef __FreeBSD__ #define PROCNAME "/proc/%d/file" #endif pid_t my_pid, running_pid; char filename[30]; int fd; struct stat filedata; ino_t inode1, inode2; /* Compare this process' ID and the pid from the INI file */ my_pid = getpid (); openIniFile (LOCALINI_FILE, 1); running_pid = IniGetInt (LOCALINI_FILE, "Pid", 0); if (running_pid == 0 || my_pid == running_pid) goto ok; #if defined (__APPLE__) || defined (__HAIKU__) goto ok; #elif defined (__OS2__) { USHORT handle1 = 0, handle2 = 0; unsigned char buf[0x2000]; if( !DosQuerySysState(0x01, 0, 0, 0, (PCHAR)buf, 0x2000) ) { PQPROCESS p = ((PQTOPLEVEL)buf)->procdata; while(p && p->rectype == 1) { if( p->pid == running_pid ) handle1 = p->hndmod; if( p->pid == my_pid ) handle2 = p->hndmod; p = (PQPROCESS)(p->threads + p->threadcnt); } if( handle1 != handle2 ) goto ok; } } #else /* See if the two pids are running the same executable */ sprintf (filename, PROCNAME, my_pid); fd = _open (filename, _O_RDONLY); if (fd < 0) goto ok; fstat (fd, &filedata); inode1 = filedata.st_ino; _close (fd); sprintf (filename, PROCNAME, running_pid); fd = _open (filename, _O_RDONLY); if (fd < 0) goto ok; fstat (fd, &filedata); inode2 = filedata.st_ino; _close (fd); if (inode1 != inode2) goto ok; #endif /* The two pids are running the same executable, raise an error and return */ if (error_message != NULL) printf ("%s", error_message); return; /* All is OK, save our pid, run, then delete our pid */ ok: IniWriteInt (LOCALINI_FILE, "Pid", my_pid); LaunchWorkerThreads (thread_num, wait_flag); if (wait_flag) IniWriteInt (LOCALINI_FILE, "Pid", 0); }