int kvm_cpu__exit(struct kvm *kvm) { int i, r; void *ret = NULL; kvm_cpu__delete(kvm->cpus[0]); kvm->cpus[0] = NULL; for (i = 1; i < kvm->nrcpus; i++) { if (kvm->cpus[i]->is_running) { pthread_kill(kvm->cpus[i]->thread, SIGKVMEXIT); if (pthread_join(kvm->cpus[i]->thread, &ret) != 0) die("pthread_join"); kvm_cpu__delete(kvm->cpus[i]); } if (ret == NULL) r = 0; } free(kvm->cpus); kvm->nrcpus = 0; return r; }
static void *kvm_cpu_thread(void *arg) { current_kvm_cpu = arg; if (kvm_cpu__start(current_kvm_cpu)) goto panic_kvm; kvm_cpu__delete(current_kvm_cpu); return (void *) (intptr_t) 0; panic_kvm: fprintf(stderr, "KVM exit reason: %u (\"%s\")\n", current_kvm_cpu->kvm_run->exit_reason, kvm_exit_reasons[current_kvm_cpu->kvm_run->exit_reason]); if (current_kvm_cpu->kvm_run->exit_reason == KVM_EXIT_UNKNOWN) fprintf(stderr, "KVM exit code: 0x%Lu\n", current_kvm_cpu->kvm_run->hw.hardware_exit_reason); kvm_cpu__show_registers(current_kvm_cpu); kvm_cpu__show_code(current_kvm_cpu); kvm_cpu__show_page_tables(current_kvm_cpu); kvm_cpu__delete(current_kvm_cpu); return (void *) (intptr_t) 1; }