void vm_destroy(struct vm *vm) { int i; ppt_unassign_all(vm); if (vm->iommu != NULL) iommu_destroy_domain(vm->iommu); vhpet_cleanup(vm->vhpet); vatpic_cleanup(vm->vatpic); vioapic_cleanup(vm->vioapic); for (i = 0; i < vm->num_mem_segs; i++) vm_free_mem_seg(vm, &vm->mem_segs[i]); vm->num_mem_segs = 0; for (i = 0; i < VM_MAXCPU; i++) vcpu_cleanup(vm, i); VMSPACE_FREE(vm->vmspace); VMCLEANUP(vm->cookie); free(vm, M_VM); }
static void vm_cleanup(struct vm *vm, bool destroy) { int i, vcpu; for (vcpu = 0; vcpu < VM_MAXCPU; vcpu++) { vcpu_cleanup(vm, vcpu, destroy); } if (destroy) { vrtc_cleanup(vm->vrtc); } else { vrtc_reset(vm->vrtc); } vpmtmr_cleanup(vm->vpmtmr); vatpit_cleanup(vm->vatpit); vhpet_cleanup(vm->vhpet); vatpic_cleanup(vm->vatpic); vioapic_cleanup(vm->vioapic); VM_CLEANUP(vm->cookie); if (destroy) { for (i = 0; i < vm->num_mem_segs; i++) { vm_free_mem_seg(&vm->mem_segs[i]); } vm->num_mem_segs = 0; } }