diff --git a/proto/vcpu/vcpu.c b/proto/vcpu/vcpu.c index 8f367a4b47af25d51c5b07958fbdce3a5314d82d..7822986873b0071b02d56880aa158d5323b470a0 100644 --- a/proto/vcpu/vcpu.c +++ b/proto/vcpu/vcpu.c @@ -1,21 +1,39 @@ #include "vcpu.h" #include "../debug/debug.h" #include "../region/vxmon.h" -#include "linux/string.h" +#include "linux/slab.h" #include <linux/errno.h> -int init_vcpu(struct vcpu_t *vcpu, struct vmxon_t *vmxon) { +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 isn't allocated\n"); - return -EFAULT; + 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; +} diff --git a/proto/vcpu/vcpu.h b/proto/vcpu/vcpu.h index a61e34dc079cf8e14cec14bc9c7f745120f20bf0..3851ddaac48bde6f09bc956de52ba16e262ccb06 100644 --- a/proto/vcpu/vcpu.h +++ b/proto/vcpu/vcpu.h @@ -1,12 +1,19 @@ #pragma once +#include "../region/vmcs.h" #include "../region/vxmon.h" struct vcpu_t { + unsigned long id; + /*vmxon region has to be freed!*/ struct vmxon_t *vmxon; + /*vmcs region has to be freed!*/ + struct vmcs_t *vmcs; /*NOTE: prolly should store the PAs of pointers to avoid unnecessary * address translations, although they should reside in the TLB by that * point*/ }; -int init_vcpu(struct vcpu_t *vcpu, struct vmxon_t *vmxon); +int init_vcpu(struct vcpu_t *vcpu, unsigned long id); + +void destroy_vcpu(struct vcpu_t *vcpu);