split out elfloader and adjust mutability

This commit is contained in:
Alex Zenla
2024-01-10 08:57:44 -08:00
parent 19b797f1a2
commit 5ff0ea8a1b
9 changed files with 255 additions and 230 deletions

View File

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

View File

@ -2,8 +2,8 @@ use xencall::domctl::DomainControl;
use xencall::{XenCall, XenCallError};
fn main() -> Result<(), XenCallError> {
let mut call = XenCall::open()?;
let mut domctl: DomainControl = DomainControl::new(&mut call);
let call = XenCall::open()?;
let domctl: DomainControl = DomainControl::new(&call);
let info = domctl.get_domain_info(1)?;
println!("{:?}", info);
Ok(())

View File

@ -1,7 +1,7 @@
use xencall::{XenCall, XenCallError};
fn main() -> Result<(), XenCallError> {
let mut call = XenCall::open()?;
let call = XenCall::open()?;
let info = call.get_version_capabilities()?;
println!("{:?}", info);
Ok(())

View File

@ -8,7 +8,7 @@ use std::ffi::c_ulong;
use std::ptr::addr_of;
pub struct DomainControl<'a> {
call: &'a mut XenCall,
call: &'a XenCall,
}
pub struct CreatedDomain {
@ -16,11 +16,11 @@ pub struct CreatedDomain {
}
impl DomainControl<'_> {
pub fn new(call: &mut XenCall) -> DomainControl {
pub fn new(call: &XenCall) -> DomainControl {
DomainControl { call }
}
pub fn get_domain_info(&mut self, domid: u32) -> Result<GetDomainInfo, XenCallError> {
pub fn get_domain_info(&self, domid: u32) -> Result<GetDomainInfo, XenCallError> {
let domctl = DomCtl {
cmd: XEN_DOMCTL_GETDOMAININFO,
interface_version: XEN_DOMCTL_INTERFACE_VERSION,
@ -56,7 +56,7 @@ impl DomainControl<'_> {
}
pub fn create_domain(
&mut self,
&self,
create_domain: CreateDomain,
) -> Result<CreatedDomain, XenCallError> {
let domctl = DomCtl {

View File

@ -62,7 +62,7 @@ impl XenCall {
Ok(XenCall { handle: file })
}
pub fn hypercall(&mut self, op: c_ulong, arg: [c_ulong; 5]) -> Result<c_long, XenCallError> {
pub fn hypercall(&self, op: c_ulong, arg: [c_ulong; 5]) -> Result<c_long, XenCallError> {
unsafe {
let mut call = Hypercall { op, arg };
let result = sys::hypercall(self.handle.as_raw_fd(), &mut call)?;
@ -70,16 +70,16 @@ impl XenCall {
}
}
pub fn hypercall0(&mut self, op: c_ulong) -> Result<c_long, XenCallError> {
pub fn hypercall0(&self, op: c_ulong) -> Result<c_long, XenCallError> {
self.hypercall(op, [0, 0, 0, 0, 0])
}
pub fn hypercall1(&mut self, op: c_ulong, arg1: c_ulong) -> Result<c_long, XenCallError> {
pub fn hypercall1(&self, op: c_ulong, arg1: c_ulong) -> Result<c_long, XenCallError> {
self.hypercall(op, [arg1, 0, 0, 0, 0])
}
pub fn hypercall2(
&mut self,
&self,
op: c_ulong,
arg1: c_ulong,
arg2: c_ulong,
@ -88,7 +88,7 @@ impl XenCall {
}
pub fn hypercall3(
&mut self,
&self,
op: c_ulong,
arg1: c_ulong,
arg2: c_ulong,
@ -98,7 +98,7 @@ impl XenCall {
}
pub fn hypercall4(
&mut self,
&self,
op: c_ulong,
arg1: c_ulong,
arg2: c_ulong,
@ -109,7 +109,7 @@ impl XenCall {
}
pub fn hypercall5(
&mut self,
&self,
op: c_ulong,
arg1: c_ulong,
arg2: c_ulong,
@ -120,7 +120,7 @@ impl XenCall {
self.hypercall(op, [arg1, arg2, arg3, arg4, arg5])
}
pub fn mmap(&mut self, mmap: Mmap) -> Result<c_long, XenCallError> {
pub fn mmap(&self, mmap: Mmap) -> Result<c_long, XenCallError> {
unsafe {
let mut mmap = mmap.clone();
let result = sys::mmap(self.handle.as_raw_fd(), &mut mmap)?;
@ -128,7 +128,7 @@ impl XenCall {
}
}
pub fn get_version_capabilities(&mut self) -> Result<XenCapabilitiesInfo, XenCallError> {
pub fn get_version_capabilities(&self) -> Result<XenCapabilitiesInfo, XenCallError> {
let info = XenCapabilitiesInfo {
capabilities: [0; 1024],
};