Skip to content
Snippets Groups Projects
Select Git revision
  • 5479548a31d8f4ee360f6c1d595db2d0babe8bbb
  • master default protected
  • 3-blue-pill-investigation
  • 2-vcpu-initialization-vmxon-and-vmcs-regions
  • 1-error-handling-based-on-errno
5 results

vcpu.c

Blame
  • vcpu.c 809 B
    #include "vcpu.h"
    #include "../debug/debug.h"
    #include "../region/vxmon.h"
    #include "linux/slab.h"
    #include <linux/errno.h>
    
    int init_vcpu(struct vcpu_t *vcpu, unsigned long id) {
        if (!vcpu) {
            DEBUG_FMT("vcpu isn't allocated\n");
            return -EFAULT;
        }
    
        struct vmxon_t *vmxon = alloc_vmxon();
    
        if (!vmxon) {
            DEBUG_FMT("VMXON region allocation failed\n");
            return -ENOMEM;
        }
    
        struct vmcs_t *vmcs = alloc_vmcs();
    
        if (!vmcs) {
            DEBUG_FMT("VMCS region allocation failed\n");
            return -ENOMEM;
        }
    
        vcpu->vmxon = vmxon;
        vcpu->vmcs = vmcs;
        vcpu->id = id;
    
        return 0;
    }
    
    void destroy_vcpu(struct vcpu_t *vcpu) {
        kfree(vcpu->vmxon);
        kfree(vcpu->vmcs);
        /*BUG: prolly won't change the pointer itself */
        vcpu = NULL;
    }