Revision 55f8d6ac

b/cpus.c
222 222
    close(fds[1]);
223 223
    return err;
224 224
}
225
#else
225

  
226
#ifdef CONFIG_IOTHREAD
227
static void dummy_signal(int sig)
228
{
229
}
230
#endif
231

  
232
#else /* _WIN32 */
233

  
226 234
HANDLE qemu_event_handle;
227 235

  
228 236
static void dummy_event_handler(void *opaque)
......
248 256
        exit (1);
249 257
    }
250 258
}
251
#endif
259
#endif /* _WIN32 */
252 260

  
253 261
#ifndef CONFIG_IOTHREAD
254 262
int qemu_init_main_loop(void)
......
348 356
static QemuCond qemu_pause_cond;
349 357
static QemuCond qemu_work_cond;
350 358

  
351
static void tcg_init_ipi(void);
352
static void kvm_init_ipi(CPUState *env);
353
static sigset_t block_io_signals(void);
354

  
355 359
/* If we have signalfd, we mask out the signals we want to handle and then
356 360
 * use signalfd to listen for them.  We rely on whatever the current signal
357 361
 * handler is to dispatch the signals when we receive them.
......
387 391
    }
388 392
}
389 393

  
394
static void cpu_signal(int sig)
395
{
396
    if (cpu_single_env) {
397
        cpu_exit(cpu_single_env);
398
    }
399
    exit_request = 1;
400
}
401

  
402
static void qemu_kvm_init_cpu_signals(CPUState *env)
403
{
404
    int r;
405
    sigset_t set;
406
    struct sigaction sigact;
407

  
408
    memset(&sigact, 0, sizeof(sigact));
409
    sigact.sa_handler = dummy_signal;
410
    sigaction(SIG_IPI, &sigact, NULL);
411

  
412
    pthread_sigmask(SIG_BLOCK, NULL, &set);
413
    sigdelset(&set, SIG_IPI);
414
    sigdelset(&set, SIGBUS);
415
    r = kvm_set_signal_mask(env, &set);
416
    if (r) {
417
        fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r));
418
        exit(1);
419
    }
420
}
421

  
422
static void qemu_tcg_init_cpu_signals(void)
423
{
424
    sigset_t set;
425
    struct sigaction sigact;
426

  
427
    memset(&sigact, 0, sizeof(sigact));
428
    sigact.sa_handler = cpu_signal;
429
    sigaction(SIG_IPI, &sigact, NULL);
430

  
431
    sigemptyset(&set);
432
    sigaddset(&set, SIG_IPI);
433
    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
434
}
435

  
436
static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
437
                           void *ctx);
438

  
439
static sigset_t block_io_signals(void)
440
{
441
    sigset_t set;
442
    struct sigaction action;
443

  
444
    /* SIGUSR2 used by posix-aio-compat.c */
445
    sigemptyset(&set);
446
    sigaddset(&set, SIGUSR2);
447
    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
448

  
449
    sigemptyset(&set);
450
    sigaddset(&set, SIGIO);
451
    sigaddset(&set, SIGALRM);
452
    sigaddset(&set, SIG_IPI);
453
    sigaddset(&set, SIGBUS);
454
    pthread_sigmask(SIG_BLOCK, &set, NULL);
455

  
456
    memset(&action, 0, sizeof(action));
457
    action.sa_flags = SA_SIGINFO;
458
    action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler;
459
    sigaction(SIGBUS, &action, NULL);
460
    prctl(PR_MCE_KILL, 1, 1, 0, 0);
461

  
462
    return set;
463
}
464

  
390 465
static int qemu_signalfd_init(sigset_t mask)
391 466
{
392 467
    int sigfd;
......
615 690
        exit(1);
616 691
    }
617 692

  
618
    kvm_init_ipi(env);
693
    qemu_kvm_init_cpu_signals(env);
619 694

  
620 695
    /* signal CPU creation */
621 696
    env->created = 1;
......
638 713
{
639 714
    CPUState *env = arg;
640 715

  
641
    tcg_init_ipi();
716
    qemu_tcg_init_cpu_signals();
642 717
    qemu_thread_self(env->thread);
643 718

  
644 719
    /* signal CPU creation */
......
679 754
    return qemu_thread_equal(&this, env->thread);
680 755
}
681 756

  
682
static void cpu_signal(int sig)
683
{
684
    if (cpu_single_env)
685
        cpu_exit(cpu_single_env);
686
    exit_request = 1;
687
}
688

  
689
static void tcg_init_ipi(void)
690
{
691
    sigset_t set;
692
    struct sigaction sigact;
693

  
694
    memset(&sigact, 0, sizeof(sigact));
695
    sigact.sa_handler = cpu_signal;
696
    sigaction(SIG_IPI, &sigact, NULL);
697

  
698
    sigemptyset(&set);
699
    sigaddset(&set, SIG_IPI);
700
    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
701
}
702

  
703
static void dummy_signal(int sig)
704
{
705
}
706

  
707
static void kvm_init_ipi(CPUState *env)
708
{
709
    int r;
710
    sigset_t set;
711
    struct sigaction sigact;
712

  
713
    memset(&sigact, 0, sizeof(sigact));
714
    sigact.sa_handler = dummy_signal;
715
    sigaction(SIG_IPI, &sigact, NULL);
716

  
717
    pthread_sigmask(SIG_BLOCK, NULL, &set);
718
    sigdelset(&set, SIG_IPI);
719
    sigdelset(&set, SIGBUS);
720
    r = kvm_set_signal_mask(env, &set);
721
    if (r) {
722
        fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(r));
723
        exit(1);
724
    }
725
}
726

  
727
static sigset_t block_io_signals(void)
728
{
729
    sigset_t set;
730
    struct sigaction action;
731

  
732
    /* SIGUSR2 used by posix-aio-compat.c */
733
    sigemptyset(&set);
734
    sigaddset(&set, SIGUSR2);
735
    pthread_sigmask(SIG_UNBLOCK, &set, NULL);
736

  
737
    sigemptyset(&set);
738
    sigaddset(&set, SIGIO);
739
    sigaddset(&set, SIGALRM);
740
    sigaddset(&set, SIG_IPI);
741
    sigaddset(&set, SIGBUS);
742
    pthread_sigmask(SIG_BLOCK, &set, NULL);
743

  
744
    memset(&action, 0, sizeof(action));
745
    action.sa_flags = SA_SIGINFO;
746
    action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler;
747
    sigaction(SIGBUS, &action, NULL);
748
    prctl(PR_MCE_KILL, 1, 1, 0, 0);
749

  
750
    return set;
751
}
752

  
753 757
void qemu_mutex_lock_iothread(void)
754 758
{
755 759
    if (kvm_enabled()) {

Also available in: Unified diff