fix memory initialization in boot setup

This commit is contained in:
Alex Zenla
2024-01-10 22:42:26 -08:00
parent 629c3d81b0
commit 38a5718ca6
4 changed files with 49 additions and 14 deletions

View File

@ -3,7 +3,8 @@ pub mod memory;
pub mod sys;
use crate::sys::{
Hypercall, MmapBatch, XenCapabilitiesInfo, HYPERVISOR_XEN_VERSION, XENVER_CAPABILITIES,
Hypercall, MmapBatch, MultiCallEntry, XenCapabilitiesInfo, HYPERVISOR_MULTICALL,
HYPERVISOR_XEN_VERSION, XENVER_CAPABILITIES,
};
use libc::{mmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};
use nix::errno::Errno;
@ -128,6 +129,15 @@ impl XenCall {
self.hypercall(op, [arg1, arg2, arg3, arg4, 0])
}
pub fn multicall(&self, calls: &mut [MultiCallEntry]) -> Result<(), XenCallError> {
self.hypercall2(
HYPERVISOR_MULTICALL,
calls.as_mut_ptr() as c_ulong,
calls.len() as c_ulong,
)?;
Ok(())
}
pub fn hypercall5(
&self,
op: c_ulong,

View File

@ -1,8 +1,11 @@
use crate::sys::{MemoryReservation, HYPERVISOR_MEMORY_OP, XEN_MEM_POPULATE_PHYSMAP};
use crate::sys::{
MemoryReservation, MultiCallEntry, HYPERVISOR_MEMORY_OP, XEN_MEM_POPULATE_PHYSMAP,
};
use crate::{XenCall, XenCallError};
use std::ffi::c_ulong;
use libc::c_long;
use std::ptr::addr_of_mut;
pub struct MemoryControl<'a> {
@ -30,12 +33,21 @@ impl MemoryControl<'_> {
mem_flags,
domid: domid as u16,
};
let code = self.call.hypercall2(
HYPERVISOR_MEMORY_OP,
XEN_MEM_POPULATE_PHYSMAP as c_ulong,
addr_of_mut!(reservation) as c_ulong,
)?;
let calls = &mut [MultiCallEntry {
op: HYPERVISOR_MEMORY_OP,
result: 0,
args: [
XEN_MEM_POPULATE_PHYSMAP as c_ulong,
addr_of_mut!(reservation) as c_ulong,
0,
0,
0,
0,
],
}];
self.call.multicall(calls)?;
let code = calls[0].result as c_long;
if code < 0 {
return Err(XenCallError::new("failed to populate physmap"));
}

View File

@ -318,4 +318,12 @@ pub struct MemoryReservation {
pub domid: u16,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct MultiCallEntry {
pub op: c_ulong,
pub result: c_ulong,
pub args: [c_ulong; 6],
}
pub const XEN_MEM_POPULATE_PHYSMAP: u32 = 6;