Ejemplo n.º 1
0
bool Worker::restart()
{
	numFailures++;

	if (numFailures >= maxFailures) {
		Logger::error << "Max worker failures ('" << maxFailures << "') reached, can't recover." << endl;
		throw WorkerException("SVS script error, can't recover, contact administrator.", false);
	}

	Logger::warning << "trying to restart worker" << endl;

	terminateProcess();

	bool ok = startProcess();

	if (!ok) {
		return false;
	}

	ok = sendSession();

	if (!ok) {
		terminateProcess();
		return false;
	}

	return true;
}
int main(int argc, char** argv) {
  gettimeofday(&start, NULL);

  std::ifstream file ("outputFile.txt");
  std::string line;
  std::vector< std::string > lines;
  std::vector<PageTable*> page_tables;
  int page_faults = 0;
  TLB tlb;
  bool useTLB = (argc > 1 && strcmp(argv[1], "-t") == 0);

  while (getline(file, line)){
    if (useTLB){
      switch(line[0]){
        case 'S': startProcess(page_tables, std::stoi(split(line)[1]), std::stoi(split(line)[2])); break;
        case 'R': page_faults += referenceTLB(page_tables, tlb, std::stoi(split(line)[1]), std::stoi(split(line)[2])); break;
        case 'T': terminateProcess(page_tables, std::stoi(split(line)[1])); break;
      }
    }else{
      switch(line[0]){
        case 'S': startProcess(page_tables, std::stoi(split(line)[1]), std::stoi(split(line)[2])); break;
        case 'R': page_faults += referenceNoTLB(page_tables, tlb, std::stoi(split(line)[1]), std::stoi(split(line)[2])); break;
        case 'T': terminateProcess(page_tables, std::stoi(split(line)[1])); break;
      }
    }
  }

  std::cout << "Num Page Faults: " << page_faults << std::endl;

  gettimeofday(&end, NULL);
  std::cout << "Elapsed Time: " << ((end.tv_sec  - start.tv_sec) * 1000 + ((end.tv_usec - start.tv_usec)/1000.0) + 0.5) << "ms" << std::endl;

  file.close();
  return 0;
}
Ejemplo n.º 3
0
bool Worker::startint()
{

	WriteLocker locker(&mutex);

	if (status == WORKER_RUNNING) {
		return true;
	}

	bool ok = startProcess();

	if (!ok) {
		return false;
	}

	ok = sendSession();

	if (!ok) {
		terminateProcess();
		return false;
	}

	started = true;

	return true;
}
Ejemplo n.º 4
0
void useExStVec(int type){
    if(currentProcess!=NULL)  {
        /* Se ho già fatto spectrapvec per il tipo di eccezione*/
        if (currentProcess->excStVec[type*2]!=NULL){
            /* Salvo lo stato nella oldarea adeguata*/
            switch(type){
                case SPECTLB:
                	saveStateIn(tlb_old, currentProcess->excStVec[type*2]);
                    break;
                case SPECPGMT:
                	saveStateIn(pgmtrap_old, currentProcess->excStVec[type*2]);
                    break;
                case SPECSYSBP:
                	saveStateIn(sysbp_old, currentProcess->excStVec[type*2]);
                    break;
            }
            /* Carico lo stato dalla newarea */
            LDST(currentProcess->excStVec[(type*2)+1]);
        }else{
           /* Altrimenti tratto come una SYS2  */
           terminateProcess(currentProcess); 
           scheduler();
        }
    } 
}
Ejemplo n.º 5
0
Worker::~Worker()
{
	terminateProcess();

#if ! defined(_MSC_VER)
	delete args;
#endif
}
Ejemplo n.º 6
0
void ScreenSaver::timeout()
{
    // After a while we close the screen saver and sleep
    // in order to save some power
    qCDebug(HAWAII_COMPOSITOR) << "Screen saver timeout...";
    terminateProcess();
    m_compositor->setState(Compositor::Sleeping);
}
Ejemplo n.º 7
0
/**
@brief (SYS5) Specify Exception State Vector.
@param type Type of exception.
@param stateOld The address into which the old processor state is to be stored when an exception
occurs while running this process.
@param stateNew The processor state area that is to be taken as the new processor state if an
exception occurs while running this process.
@return Void.
*/
EXTERN void specTrapVec(int type, state_t *stateOld, state_t *stateNew)
{
	/* [Case 1] If the exception type is not recognized or SYS5 has been called more than once, terminate the process */
	if (type < 0 || type > 2 || ++CurrentProcess->exceptionState[type] > 1) terminateProcess();
	/* [Case 2] SYS5 has been called for the first time */
	else
	{
		CurrentProcess->p_stateOldArea[type] = stateOld;
		CurrentProcess->p_stateNewArea[type] = stateNew;
	}
}
Ejemplo n.º 8
0
void Action::terminate()
{
    if (m_processes.empty())
        return;

    for (auto p : m_processes)
        p->terminate();

    waitForFinished(5000);
    for (auto p : m_processes)
        terminateProcess(p);
}
Ejemplo n.º 9
0
void
ScriptManager::slotStopScript()
{
    QListViewItem* const li = m_gui->listView->currentItem();
    const QString name = li->text( 0 );

    // Just a sanity check
    if( m_scripts.find( name ) == m_scripts.end() )
        return;

    terminateProcess( &m_scripts[name].process );
    m_scripts[name].log = QString::null;
    slotCurrentChanged( m_gui->listView->currentItem() );

    li->setPixmap( 0, QPixmap() );
}
void ConnectionClient::finishProcess()
{
    TIME_SCOPE_DURATION("ConnectionClient::finishProcess");

    processAliveTimer.stop();

    disconnectProcessFinished();
    endProcess();
    disconnectFromServer();
    terminateProcess();
    killProcess();

    process_.reset();

    serverProxy_.resetCounter();
}
Ejemplo n.º 11
0
void Worker::terminate(const string& line, time_t timeout)
{
	WriteLocker locker(&mutex);

	if (status != WORKER_RUNNING) {
		return;
	}

	bool ok = sendLine(line, timeout);

	if (ok) {
		ok = readResult(timeout);
	}

	terminateProcess();
}
Ejemplo n.º 12
0
/**
@brief This function handles a system call request coming from a process running in Kernel Mode.
@return Void.
*/
HIDDEN void syscallKernelMode()
{
	/* Identify and handle the system call */
	switch (SYSBP_Old->a1)
	{
		case CREATEPROCESS:
			CurrentProcess->p_s.a1 = createProcess((state_t *) SYSBP_Old->a2);
			break;

		case TERMINATEPROCESS:
			terminateProcess();
			break;

		case VERHOGEN:
			verhogen((int *) SYSBP_Old->a2);
			break;

		case PASSEREN:
			passeren((int *) SYSBP_Old->a2);
			break;

		case GETCPUTIME:
			CurrentProcess->p_s.a1 = getCPUTime();
			break;

		case WAITCLOCK:
			waitClock();
			break;

		case WAITIO:
			CurrentProcess->p_s.a1 = waitIO((int) SYSBP_Old->a2, (int) SYSBP_Old->a3, (int) SYSBP_Old->a4);
			break;

		case SPECTRAPVEC:
			specTrapVec((int) SYSBP_Old->a2, (state_t *) SYSBP_Old->a3, (state_t *) SYSBP_Old->a4);
			break;

		default:
			/* Distinguish whether SYS5 has been invoked or not */
			checkSYS5(SYSBK_EXCEPTION, SYSBP_Old);
	}

	/* Call the scheduler */
	scheduler();
}
Ejemplo n.º 13
0
ScriptManager::~ScriptManager()
{
    DEBUG_BLOCK

    QStringList runningScripts;
    ScriptMap::Iterator it;
    ScriptMap::Iterator end( m_scripts.end() );
    for( it = m_scripts.begin(); it != end; ++it ) {
        if( it.data().process ) {
            terminateProcess( &it.data().process );
            runningScripts << it.key();
        }
    }

    // Save config
    KConfig* const config = amaroK::config( "ScriptManager" );
    config->writeEntry( "Running Scripts", runningScripts );

    s_instance = 0;
}
Ejemplo n.º 14
0
void ChangeSelectionDialog::recalculateDetails()
{
    terminateProcess();
    enableButtons(false);

    const QString workingDir = workingDirectory();
    QPalette palette = m_ui->workingDirectoryEdit->palette();
    Theme *theme = creatorTheme();
    if (workingDir.isEmpty()) {
        m_ui->detailsText->setPlainText(tr("Error: Bad working directory."));
        palette.setColor(QPalette::Text, theme->color(Theme::TextColorError));
        m_ui->workingDirectoryEdit->setPalette(palette);
        return;
    } else {
        palette.setColor(QPalette::Text, theme->color(Theme::TextColorNormal));
        m_ui->workingDirectoryEdit->setPalette(palette);
    }

    const QString ref = change();
    if (ref.isEmpty()) {
        m_ui->detailsText->clear();
        return;
    }

    QStringList args;
    args << QLatin1String("show") << QLatin1String("--stat=80") << ref;

    m_process = new QProcess(this);
    m_process->setWorkingDirectory(workingDir);
    m_process->setProcessEnvironment(m_gitEnvironment);

    connect(m_process, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
            this, &ChangeSelectionDialog::setDetails);

    m_process->start(m_gitExecutable.toString(), args);
    m_process->closeWriteChannel();
    if (!m_process->waitForStarted())
        m_ui->detailsText->setPlainText(tr("Error: Could not start Git."));
    else
        m_ui->detailsText->setPlainText(tr("Fetching commit data..."));
}
Ejemplo n.º 15
0
/**
@brief The function will undertake one of the following actions:
(1) If the offending process has NOT issued a SYS5, then invoke SYS2;
(2) If the offending process has issued a SYS5, then pass up the exception.
@return Void.
*/
HIDDEN void checkSYS5(int exceptionType, state_t *exceptionOldArea)
{
	/* [Case 1] SYS5 has not been issued */
	if (CurrentProcess->exceptionState[exceptionType] == 0)
	{
		/* Terminate the current process (SYS2) */
		terminateProcess();

		/* Call the scheduler */
		scheduler();
	}
	/* [Case 2] SYS5 has been issued */
	else
	{
		/* Move current process Exception State Area into the processor Exception State Area */
		saveCurrentState(exceptionOldArea, CurrentProcess->p_stateOldArea[exceptionType]);

		/* Load the processor state in order to start execution */
		LDST(CurrentProcess->p_stateNewArea[exceptionType]);
	}
}
Ejemplo n.º 16
0
void
ScriptManager::slotUninstallScript()
{
    const QString name = m_gui->listView->currentItem()->text( 0 );

    if( KMessageBox::warningContinueCancel( 0, i18n( "Are you sure you want to uninstall the script '%1'?" ).arg( name ), i18n("Uninstall Script"), i18n("Uninstall") ) == KMessageBox::Cancel )
        return;

    if( m_scripts.find( name ) == m_scripts.end() )
        return;

    const QString directory = m_scripts[name].url.directory();

    // Delete directory recursively
    const KURL url = KURL::fromPathOrURL( directory );
    if( !KIO::NetAccess::del( url, 0 ) ) {
        KMessageBox::sorry( 0, i18n( "<p>Could not uninstall this script.</p><p>The ScriptManager can only uninstall scripts which have been installed as packages.</p>" ) );
        return;
    }

    QStringList keys;

    // Find all scripts that were in the uninstalled folder
    {
        foreachType( ScriptMap, m_scripts )
            if( it.data().url.directory() == directory )
                keys << it.key();
    }

    // Terminate script processes, remove entries from script list
    {
        foreach( keys ) {
            delete m_scripts[*it].li;
            terminateProcess( &m_scripts[*it].process );
            m_scripts.erase( *it );
        }
    }
}
Ejemplo n.º 17
0
LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg) {
		case WM_COMMAND:
			switch (wParam) {
				case IDC_KILL:
					if (MessageBox(hWnd, "Are you sure you want to terminate the application?", "Confirm", MB_YESNO | MB_ICONQUESTION) == IDYES) {
						terminateProcess();
					}
					break;
				case IDC_EXIT:
					if (MessageBox(hWnd, "Are you sure you want to remove this icon?  You will no longer be able to use it to terminate the application.", "Confirm", MB_YESNO | MB_ICONQUESTION) == IDYES) {
						DestroyWindow(hWnd);
						//PostQuitMessage(0); // Doesn't work under Windows Server 2008, does work under Win7
					}
					break;
			}
			break;
		case TRAY_MSG:
			switch (lParam) {
				case WM_RBUTTONDOWN: {
					HMENU popupMenu = CreatePopupMenu();
					AppendMenu(popupMenu, MF_ENABLED, IDC_KILL, "Terminate application");
					AppendMenu(popupMenu, MF_ENABLED, IDC_EXIT, "Remove this icon");
					POINT mp;
					GetCursorPos(&mp);
					SetForegroundWindow(hWnd);
					TrackPopupMenuEx(popupMenu, 0, mp.x, mp.y, hWnd, NULL);
					PostMessage(hWnd, WM_NULL, 0, 0);
					DestroyMenu(popupMenu);
					break;
				}
			}
			break;
	}
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Ejemplo n.º 18
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool RIApplication::closeProject(bool askToSaveIfDirty)
{
    RIMainWindow* mainWnd = RIMainWindow::instance();

    terminateProcess();

    if (false)
    {
        QMessageBox msgBox(mainWnd);
        msgBox.setIcon(QMessageBox::Warning);
        msgBox.setText("The project being closed has been modified.");
        msgBox.setInformativeText("Do you want to save your changes?");
        msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
        //msgBox.setDefaultButton(QMessageBox::Save);

        int ret = msgBox.exec();
        if (ret == QMessageBox::Save)
        {
            //m_sceneManager->saveAll();
        }
        else if (ret == QMessageBox::Cancel)
        {
            return false;
        }
    }

    mainWnd->cleanupGuiBeforeProjectClose();

    caf::EffectGenerator::clearEffectCache();
    m_project->close();

    onProjectOpenedOrClosed();

    return true;
    
}
Ejemplo n.º 19
0
// ****************************************************************************************************************
bool CWinProcess::terminateProcessFromModuleName(const std::string &moduleName, uint exitCode)
{
	return terminateProcess(getProcessIdFromModuleFilename(moduleName), exitCode);
}
Ejemplo n.º 20
0
ChangeSelectionDialog::~ChangeSelectionDialog()
{
    terminateProcess();
    delete m_ui;
}
Ejemplo n.º 21
0
void
sessionExit( int status )
{
	int pid;
#ifdef USE_PAM
	int pretc;
#endif

	if (removeAuth) {
		switch (source( systemEnviron, td->reset, td_setup )) {
		case 0:
		case wcCompose( 0, 0, 127 ):
			break;
		default:
			logError( "Reset script returned non-zero exit code\n" );
			break;
		}
		sessreg( td, 0, 0, 0 );

		switch (Fork( &pid )) {
		case 0:
#if defined(USE_PAM) && defined(HAVE_INITGROUPS)
			if (restoreGids() && setUid( curuser, curuid ))
#else
			if (setUser( curuser, curuid, curgid ))
#endif

			{
				removeUserAuthorization( td );
#ifdef K5AUTH
				krb5Destroy( td->name );
#endif /* K5AUTH */
#if !defined(USE_PAM) && !defined(_AIX)
# ifdef KERBEROS
				if (krbtkfile[0]) {
					(void)dest_tkt();
#  ifdef AFS
					if (k_hasafs())
						(void)k_unlog();
#  endif
				}
# endif
#endif /* !USE_PAM && !_AIX*/
			}
			exit( 0 );
		case -1:
			logError( "Cannot clean up session: fork() failed: %m" );
			break;
		default:
			Wait4( &pid );
			break;
		}
	}

#ifdef USE_PAM
	if (removeCreds) {
# ifdef HAVE_INITGROUPS
		restoreGids();
# endif
		if (removeSession) {
			pretc = pam_close_session( pamh, 0 );
			reInitErrorLog();
			if (pretc != PAM_SUCCESS)
				logError( "pam_close_session() failed: %s\n",
				          pam_strerror( pamh, pretc ) );
		}
		pretc = pam_setcred( pamh, PAM_DELETE_CRED );
		reInitErrorLog();
		if (pretc != PAM_SUCCESS)
			logError( "pam_setcred(DELETE_CRED) failed: %s\n",
			          pam_strerror( pamh, pretc ) );
		resetGids();
	}
	if (pamh) {
		pam_end( pamh, PAM_SUCCESS );
		reInitErrorLog();
	}
#endif

	finishGreet();

	/* make sure the server gets reset after the session is over */
	if (td->serverPid >= 2) {
		if (!td->terminateServer && td->resetSignal)
			terminateProcess( td->serverPid, td->resetSignal );
	} else
		resetServer( td );
	debug( "display %s exiting with status %d\n", td->name, status );
	exit( status );
}
Ejemplo n.º 22
0
void sysBpHandler(){
	saveStateIn(sysbp_old, &currentProcess->p_s);
	unsigned int cause = CAUSE_EXCCODE_GET(sysbp_old->CP15_Cause);
	unsigned int a0 = (*sysbp_old).a1;
	unsigned int a1 = (*sysbp_old).a2;
	unsigned int a2 = (*sysbp_old).a3;
	unsigned int a3 = (*sysbp_old).a4;
	/* Se l'eccezione è di tipo System call */
	if(cause==EXC_SYSCALL){
    	/* Se il processo è in kernel mode gestisce adeguatamente */
    	if( (currentProcess->p_s.cpsr & STATUS_SYS_MODE) == STATUS_SYS_MODE){
			/* Se è fra SYS1 e SYS8 richiama le funzioni adeguate */
			switch(a0){
			    case CREATEPROCESS:
			        createProcess((state_t *) a1);
			        break;
			    case TERMINATEPROCESS:
			        terminateProcess(currentProcess);
			        break;
		        case VERHOGEN:
		            verhogen((int *) a1);
			        break;
		        case PASSEREN:
		            passeren((int *) a1);
			        break;
		        case SPECTRAPVEC:
		            specExStVec((int) a1, (state_t *) a2, (state_t *) a3);
			        break;
		        case GETCPUTIME:
		            getCPUTime();
			        break;
		        case WAITCLOCK:
		            waitForClock();
			        break;
		        case WAITIO:
		            waitForIO((int) a1, (int) a2, (int) a3);
			        break;
			    /* Altrimenti la gestione viene passata in alto */
			    default:
			        useExStVec(SPECSYSBP);
				break;            
			}
			
		    /* Richiamo lo scheduler */
		    scheduler();
		/* Se invece è in user mode */
		} else if((currentProcess->p_s.cpsr & STATUS_USER_MODE) == STATUS_USER_MODE){
			/* Se è una system call */
			if(a0 >= CREATEPROCESS && a0 <= WAITIO){
			    /* Gestisco come fosse una program trap */
			    saveStateIn(sysbp_old, pgmtrap_old);
			    /* Setto il registro cause a Reserved Instruction */
			    pgmtrap_old->CP15_Cause = CAUSE_EXCCODE_SET(pgmtrap_old->CP15_Cause, EXC_RESERVEDINSTR);
			    /* Richiamo l'handler per le pgmtrap */
			    pgmHandler();
			} else {
				useExStVec(SPECSYSBP);
			}
		}
	/* Altrimenti se l'eccezione è di tipo BreakPoint */
	} else if(cause == EXC_BREAKPOINT){
		useExStVec(SPECSYSBP);
	}

	PANIC();
}
Ejemplo n.º 23
0
void sysBpHandler(){
	
	int cause;
	int mode;
	
	//1-dovremmo salvare lo stato del registro
	
	//2-boh -> il tipo dice per evitare loop syscall :/
	currentProcess->p_s.cpsr += //qualcosa;
	
	//3-prendiamo il mode
	mode= ((sysBp_old->cpsr & STATUS_SYS_MODE) >> 0x3); //forse funziona -> STATUS_SYS_MODE in uarmConst.h
	
	//4-cause interrupt
	cause=getCAUSE();
	
	if(cause == EXC_SYSCALL){ //caso system call
		
		//controlla se è in user mode
		if(mode==TRUE){ //è definito da qualche parte il true?
			
			//controllo se è una delle 11 syscall
			if((sysBp_old->reg_a0 >= 1) && (sysBp_old->reg_a0 <= SYSCALL_MAX)){ //SYSCALL_MAX sta in const.h
			
				sysBp_old->CP15_Cause = setCAUSE(); //siamo sicuri non ci vadano parametri?
				
				//salva il sysbp old in pgmtrap old
				
				pgmTrapHandler();
				
			}
			else{
				//ERRORE!!! FACCIAMO UN ALTRA VOLTA!!!
			}
		}
		else{//caso kernel mode
			
			int ret;
			
			/* Salva i parametri delle SYSCALL */
			U32 argv1 = sysBp_old->a2;
			U32 argv2 = sysBp_old->a3;
			U32 argv3 = sysBp_old->a4;
			
			
			
			/* Gestisce ogni singola SYSCALL */
			switch(sysBp_old->a1)
			{
				case CREATEPROCESS:
					//currentProcess->p_state.reg_v0 = createProcess((state_t *) arg1);
					break;
					
				case TERMINATEPROCESS:
					//ris = terminateProcess((int) arg1);
					//if(currentProcess != NULL) currentProcess->p_state.reg_v0 = ris;
					break;
					
				case SEMOP:
					semaphoreOperation((int *) argv1, (int) argv2);
					break;
				
				case SPECSYSHDL:
					
					break;
					
				case SPECTLBHDL:
					
					break;
					
				case SPECPGMTHDL:
					
					break;
					
					
				case EXITTRAP:
					
					break;
					
				case GETCPUTIME:
					//currentProcess->p_state.reg_v0 = getCPUTime();
					break;
					
				case WAITCLOCK:
					//waitClock();
					break;
					
				case IODEVOP:
					
					break;
					
				case GETPID:
					currentProcess->p_state.reg_v0 = getPid();
					break;
					
				
				/*
					
				case WAITIO:
					currentProcess->p_state.reg_v0 = waitIO((int) arg1, (int) arg2, (int) arg3);
					break;
					
				case GETPPID:
					currentProcess->p_state.reg_v0 = getPpid();
					break;
					
				case SPECTLBVECT:
					specTLBvect((state_t *) arg1, (state_t *)arg2);
					break;
					
				case SPECPGMVECT:
					specPGMvect((state_t *) arg1, (state_t *)arg2);
					break;
					
				case SPECSYSVECT:
					specSYSvect((state_t *) arg1, (state_t *)arg2);
					break;
					
				 */
					
				default:
					/* Se non è già stata eseguita la SYS12, viene terminato il processo corrente */
					if(currentProcess->ExStVec[ESV_SYSBP] == 0)
					{
						int ris;
						
						ris = terminateProcess(-1);
						if(currentProcess != NULL) currentProcess->p_state.reg_v0 = ris;
					}
					/* Altrimenti viene salvata la SysBP Old Area all'interno del processo corrente */
					else
					{
						saveCurrentState(sysBp_old, currentProcess->sysbpState_old);
						LDST(currentProcess->sysbpState_new);
					}
			}
			
			scheduler();
			
		}
	}
	else{ //caso breakpoint
	
 
	}
}