Ejemplo n.º 1
0
/* Class method. This is a signal handler -- do not use thread synchronization or functions that are not async signal safe. */
void
RSIM_Simulator::signal_receiver(int signo, siginfo_t *info, void*)
{
    /* In order for this signal handler to be installed, there must be an active simulator. This is because the activate()
     * method installs the signal handler and the deactivate() removes it.  The active_sim is set before the signal handler is
     * installed and reset after it is removed. */
    RSIM_Simulator *simulator = active_sim;
    assert(simulator!=NULL);
    RSIM_Process *process = simulator->get_process();
    assert(process!=NULL);

#if 1 /* WARNING: this is not async signal safe, but useful for debugging */
    char buf[1024];
    sprintf(buf, "PID %d received signal %d with info=%p\n", getpid(), signo, info);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_signo = %d\n", info->si_signo);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_errno = %d\n", info->si_errno);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_code  = %d\n", info->si_code);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_pid   = %d\n", info->si_pid);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_uid   = %u\n", info->si_uid);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_int   = %u\n", info->si_int);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_ptr   = %p\n", info->si_ptr);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_status = %u\n", info->si_status);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_utime = %ld\n", info->si_utime);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_stime = %ld\n", info->si_stime);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_addr  = %p\n", info->si_addr);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_band  = %ld\n", info->si_band);
    write(2, buf, strlen(buf));
    sprintf(buf, "    info.si_fd    = %d\n", info->si_fd);
    write(2, buf, strlen(buf));
#endif

    process->signal_enqueue(RSIM_SignalHandling::mk(info));
}