Skip to content

Commit 71d07fe

Browse files
committed
test: add multi-frame allocation support and fix warning
1 parent c584a75 commit 71d07fe

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/npt/arch/x86_64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ impl PagingMetaData for ExtendedPageTableMetadata {
176176

177177
// Under the x86 architecture, the flush_tlb operation will invoke the ring0 instruction,
178178
// causing the test to trigger a SIGSEGV exception.
179+
#[allow(unused_variables)]
179180
fn flush_tlb(vaddr: Option<GuestPhysAddr>) {
180181
#[cfg(not(test))]
181182
if let Some(vaddr) = vaddr {

src/test_utils/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,31 @@ impl PagingHandler for MockHal {
7676
Self::mock_alloc_frame()
7777
}
7878

79+
fn alloc_frames(count: usize, _align: usize) -> Option<PhysAddr> {
80+
if count == 0 {
81+
return Some(PhysAddr::from(0));
82+
}
83+
// For simplicity, just allocate frames sequentially
84+
let first = Self::mock_alloc_frame()?;
85+
for _ in 1..count {
86+
if Self::mock_alloc_frame().is_none() {
87+
return None;
88+
}
89+
}
90+
Some(first)
91+
}
92+
7993
fn dealloc_frame(_paddr: PhysAddr) {
8094
Self::mock_dealloc_frame(_paddr)
8195
}
8296

97+
fn dealloc_frames(paddr: PhysAddr, count: usize) {
98+
for i in 0..count {
99+
let offset = i * PAGE_SIZE;
100+
Self::mock_dealloc_frame(PhysAddr::from(paddr.as_usize() + offset));
101+
}
102+
}
103+
83104
fn phys_to_virt(paddr: PhysAddr) -> VirtAddr {
84105
Self::mock_phys_to_virt(paddr)
85106
}

0 commit comments

Comments
 (0)