cleanup elf loader and more work towards boot support

This commit is contained in:
Alex Zenla
2024-01-10 10:08:39 -08:00
parent 5ff0ea8a1b
commit d46d0cf0c3
7 changed files with 134 additions and 53 deletions

View File

@ -5,7 +5,7 @@ use xencall::{XenCall, XenCallError};
fn main() -> Result<(), XenCallError> {
let call = XenCall::open()?;
let domctl: DomainControl = DomainControl::new(&call);
let info = domctl.create_domain(CreateDomain::default())?;
println!("created domain {}", info.domid);
let domid = domctl.create_domain(CreateDomain::default())?;
println!("created domain {}", domid);
Ok(())
}

View File

@ -1,7 +1,8 @@
use crate::sys::{
ArchDomainConfig, CreateDomain, DomCtl, DomCtlValue, GetDomainInfo, MaxMem, MaxVcpus,
HYPERVISOR_DOMCTL, XEN_DOMCTL_CREATEDOMAIN, XEN_DOMCTL_GETDOMAININFO,
XEN_DOMCTL_INTERFACE_VERSION, XEN_DOMCTL_MAX_MEM, XEN_DOMCTL_MAX_VCPUS,
ArchDomainConfig, CreateDomain, DomCtl, DomCtlValue, GetDomainInfo, HypercallInit, MaxMem,
MaxVcpus, HYPERVISOR_DOMCTL, XEN_DOMCTL_CREATEDOMAIN, XEN_DOMCTL_DESTROYDOMAIN,
XEN_DOMCTL_GETDOMAININFO, XEN_DOMCTL_HYPERCALL_INIT, XEN_DOMCTL_INTERFACE_VERSION,
XEN_DOMCTL_MAX_MEM, XEN_DOMCTL_MAX_VCPUS,
};
use crate::{XenCall, XenCallError};
use std::ffi::c_ulong;
@ -11,10 +12,6 @@ pub struct DomainControl<'a> {
call: &'a XenCall,
}
pub struct CreatedDomain {
pub domid: u32,
}
impl DomainControl<'_> {
pub fn new(call: &XenCall) -> DomainControl {
DomainControl { call }
@ -55,10 +52,7 @@ impl DomainControl<'_> {
Ok(unsafe { domctl.value.get_domain_info })
}
pub fn create_domain(
&self,
create_domain: CreateDomain,
) -> Result<CreatedDomain, XenCallError> {
pub fn create_domain(&self, create_domain: CreateDomain) -> Result<u32, XenCallError> {
let domctl = DomCtl {
cmd: XEN_DOMCTL_CREATEDOMAIN,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
@ -67,9 +61,7 @@ impl DomainControl<'_> {
};
self.call
.hypercall1(HYPERVISOR_DOMCTL, addr_of!(domctl) as c_ulong)?;
Ok(CreatedDomain {
domid: domctl.domid,
})
Ok(domctl.domid)
}
pub fn set_max_mem(&mut self, domid: u32, memkb: u64) -> Result<(), XenCallError> {
@ -99,4 +91,30 @@ impl DomainControl<'_> {
.hypercall1(HYPERVISOR_DOMCTL, addr_of!(domctl) as c_ulong)?;
Ok(())
}
pub fn hypercall_init(&self, domid: u32, gmfn: u64) -> Result<(), XenCallError> {
let domctl = DomCtl {
cmd: XEN_DOMCTL_HYPERCALL_INIT,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
domid,
value: DomCtlValue {
hypercall_init: HypercallInit { gmfn },
},
};
self.call
.hypercall1(HYPERVISOR_DOMCTL, addr_of!(domctl) as c_ulong)?;
Ok(())
}
pub fn destroy_domain(&self, domid: u32) -> Result<(), XenCallError> {
let domctl = DomCtl {
cmd: XEN_DOMCTL_DESTROYDOMAIN,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
domid,
value: DomCtlValue { pad: [0; 128] },
};
self.call
.hypercall1(HYPERVISOR_DOMCTL, addr_of!(domctl) as c_ulong)?;
Ok(())
}
}

View File

@ -195,6 +195,8 @@ pub union DomCtlValue {
pub get_domain_info: GetDomainInfo,
pub max_mem: MaxMem,
pub max_cpus: MaxVcpus,
pub hypercall_init: HypercallInit,
pub pad: [u8; 128],
}
#[repr(C)]
@ -277,6 +279,12 @@ pub struct MaxVcpus {
pub max_vcpus: u32,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct HypercallInit {
pub gmfn: u64,
}
pub const XEN_DOMCTL_INTERFACE_VERSION: u32 = 0x00000015;
pub const SECINITSID_DOMU: u32 = 13;