Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/memory/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,33 @@ impl Frame {
}

/// allocate contigugous frames, and you can specify the alignment, set the lower `align_log2` bits to 0.
pub fn new_contiguous_with_base(
frame_count: usize,
align_log2: usize,
) -> HvResult<Self> {
pub fn new_contiguous_with_base(frame_count: usize, align_log2: usize) -> HvResult<Self> {
let align_mask = (1 << align_log2) - 1;
// Create a vector to keep track of attempted frames
let mut attempted_frames = Vec::new();
loop{
if let Ok(frame) = Frame::new_contiguous(frame_count, 0){
if frame.start_paddr() & ((1 << align_log2) - 1) == 0{
info!("new contiguous success!!! start_paddr:0x{:x}",frame.start_paddr());
loop {
if let Ok(frame) = Frame::new_contiguous(frame_count, 0) {
if frame.start_paddr() & align_mask == 0 {
info!(
"new contiguous success!!! start_paddr:0x{:x}",
frame.start_paddr()
);
return Ok(frame);
}else{
} else {
let start_paddr = frame.start_paddr();
let next_aligned_addr = (start_paddr + align_mask) & !align_mask;
let temp_frame_count = (next_aligned_addr - start_paddr) / PAGE_SIZE;
drop(frame);
attempted_frames.push(Frame::new_zero());
attempted_frames.push(Frame::new_contiguous(temp_frame_count, 0));
if let Ok(frame) = Frame::new_contiguous(frame_count, 0) {
info!(
"new contiguous success!!! start_paddr:0x{:x}",
frame.start_paddr()
);
return Ok(frame);
}
}
}else{
} else {
return Err(hv_err!(ENOMEM));
}
}
Expand Down