actually allocate max memory

This commit is contained in:
Alex Zenla
2024-01-10 19:18:48 -08:00
parent 153619a02c
commit 629c3d81b0
7 changed files with 80 additions and 64 deletions

View File

@ -3,7 +3,7 @@ use crate::{XenCall, XenCallError};
use std::ffi::c_ulong;
use std::ptr::addr_of;
use std::ptr::addr_of_mut;
pub struct MemoryControl<'a> {
call: &'a XenCall,
@ -22,19 +22,28 @@ impl MemoryControl<'_> {
mem_flags: u32,
extent_starts: &[u64],
) -> Result<Vec<u64>, XenCallError> {
let extent_starts = extent_starts.to_vec();
let reservation = MemoryReservation {
extent_start: addr_of!(extent_starts) as c_ulong,
let mut extent_starts = extent_starts.to_vec();
let mut reservation = MemoryReservation {
extent_start: extent_starts.as_mut_ptr() as c_ulong,
nr_extents,
extent_order,
mem_flags,
domid: domid as u16,
};
self.call.hypercall2(
let code = self.call.hypercall2(
HYPERVISOR_MEMORY_OP,
XEN_MEM_POPULATE_PHYSMAP as c_ulong,
addr_of!(reservation) as c_ulong,
addr_of_mut!(reservation) as c_ulong,
)?;
Ok(extent_starts)
if code < 0 {
return Err(XenCallError::new("failed to populate physmap"));
}
if code as usize > extent_starts.len() {
return Err(XenCallError::new("failed to populate physmap"));
}
Ok(extent_starts[0..code as usize].to_vec())
}
}