/*===========================================================================* * rs_memctl_make_vm_instance * *===========================================================================*/ static int rs_memctl_make_vm_instance(struct vmproc *new_vm_vmp) { int r; u32_t flags; int verify; struct vmproc *this_vm_vmp; this_vm_vmp = &vmproc[VM_PROC_NR]; pt_assert(&this_vm_vmp->vm_pt); /* Check if the operation is allowed. */ assert(num_vm_instances == 1 || num_vm_instances == 2); if(num_vm_instances == 2) { printf("VM can currently support no more than 2 VM instances at the time."); return EPERM; } /* Copy settings from current VM. */ new_vm_vmp->vm_flags |= VMF_VM_INSTANCE; num_vm_instances++; /* Pin memory for the new VM instance. */ r = map_pin_memory(new_vm_vmp); if(r != OK) { return r; } /* Preallocate page tables for the entire address space for both * VM and the new VM instance. */ flags = 0; verify = FALSE; r = pt_ptalloc_in_range(&this_vm_vmp->vm_pt, VM_OWN_HEAPBASE, VM_DATATOP, flags, verify); if(r != OK) { return r; } r = pt_ptalloc_in_range(&new_vm_vmp->vm_pt, VM_OWN_HEAPBASE, VM_DATATOP, flags, verify); if(r != OK) { return r; } /* Let the new VM instance map VM's page tables and its own. */ r = pt_ptmap(this_vm_vmp, new_vm_vmp); if(r != OK) { return r; } r = pt_ptmap(new_vm_vmp, new_vm_vmp); if(r != OK) { return r; } pt_assert(&this_vm_vmp->vm_pt); pt_assert(&new_vm_vmp->vm_pt); return OK; }
/*===========================================================================* * rs_memctl_make_vm_instance * *===========================================================================*/ static int rs_memctl_make_vm_instance(struct vmproc *new_vm_vmp) { int r; u32_t flags; int verify; struct vmproc *this_vm_vmp; this_vm_vmp = &vmproc[VM_PROC_NR]; /* Pin memory for the new VM instance. */ r = map_pin_memory(new_vm_vmp); if(r != OK) { return r; } /* Preallocate page tables for the entire address space for both * VM and the new VM instance. */ flags = 0; verify = FALSE; r = pt_ptalloc_in_range(&this_vm_vmp->vm_pt, 0, 0, flags, verify); if(r != OK) { return r; } r = pt_ptalloc_in_range(&new_vm_vmp->vm_pt, 0, 0, flags, verify); if(r != OK) { return r; } /* Let the new VM instance map VM's page tables and its own. */ r = pt_ptmap(this_vm_vmp, new_vm_vmp); if(r != OK) { return r; } r = pt_ptmap(new_vm_vmp, new_vm_vmp); if(r != OK) { return r; } return OK; }