Ejemplo n.º 1
0
void
RSIM_Simulator::terminate_self()
{
    RSIM_Process *process = get_process();
    if (!process->has_terminated())
        return;

    SAWYER_THREAD_TRAITS::RecursiveLockGuard lock(class_rwlock);
    int status = process->get_termination_status();
    if (WIFEXITED(status)) {
        exit(WEXITSTATUS(status));
    } else if (WIFSIGNALED(status)) {
        struct sigaction sa, old;
        memset(&sa, 0, sizeof sa);
        sa.sa_handler = SIG_DFL;
        sigaction(WTERMSIG(status), &sa, &old);
        raise(WTERMSIG(status));
        sigaction(WTERMSIG(status), &old, NULL);
    } else if (WIFSTOPPED(status)) {
        struct sigaction sa, old;
        memset(&sa, 0, sizeof sa);
        sa.sa_handler = SIG_DFL;
        sigaction(WTERMSIG(status), &sa, &old);
        raise(WTERMSIG(status));
        sigaction(WTERMSIG(status), &old, NULL);
    }
}
Ejemplo n.º 2
0
std::string
RSIM_Simulator::describe_termination()
{
    std::ostringstream m;
    RSIM_Process *process = get_process();
    if (process->has_terminated()) {
        int status = process->get_termination_status();
        if (WIFEXITED(status)) {
            mfprintf(m)("specimen %d exited with status %d", getpid(), WEXITSTATUS(status));
        } else if (WIFSIGNALED(status)) {
            mfprintf(m)("specimen %d exited due to signal %s %s",
                        getpid(), strsignal(WTERMSIG(status)), WCOREDUMP(status)?" core dumped":"");
        } else if (WIFSTOPPED(status)) {
            mfprintf(m)("specimen %d is stopped due to signal %s", getpid(), strsignal(WSTOPSIG(status)));
        } else {
            mfprintf(m)("specimen %d has unknown termination status: 0x%08x", getpid(), status);
        }
    } else {
        mfprintf(m)("specimen %d has not exited yet", getpid());
    }
    return m.str();
}
Ejemplo n.º 3
0
int
RSIM_Simulator::main_loop()
{
    RSIM_Process *process = get_process();
    RSIM_Thread *thread = process->get_main_thread();

    /* The simulator's main thread is executed by the calling thread because the simulator's main thread must be a thread group
     * leader. */
    bool cb_process_status = process->get_callbacks().call_process_callbacks(RSIM_Callbacks::BEFORE, process,
                                                                             RSIM_Callbacks::ProcessCallback::START,
                                                                             true);

    // The process' main thread has already been created and initialized but has not started running yet.
    thread->start();
    thread->waitForState(RSIM_Thread::TERMINATED);

    process->get_callbacks().call_process_callbacks(RSIM_Callbacks::AFTER, process,
                                                    RSIM_Callbacks::ProcessCallback::FINISH,
                                                    cb_process_status);

    return process->get_termination_status();
}