Skip to content

Commit ef03f42

Browse files
authored
chore: code fmt (#3)
* chore: code fmt * chore: update dependencies and remove unused patches
1 parent 1d16ab8 commit ef03f42

8 files changed

Lines changed: 29 additions & 26 deletions

File tree

src/address_space/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ use memory_addr::{MemoryAddr, PhysAddr, is_aligned_4k};
2020
use memory_set::{MemoryArea, MemorySet};
2121
use page_table_multiarch::PagingHandler;
2222

23-
use crate::npt::NestedPageTable as PageTable;
24-
use crate::{GuestPhysAddr, GuestPhysAddrRange, mapping_err_to_ax_err};
23+
use crate::{
24+
GuestPhysAddr, GuestPhysAddrRange, mapping_err_to_ax_err, npt::NestedPageTable as PageTable,
25+
};
2526

2627
mod backend;
2728

@@ -183,7 +184,7 @@ impl<H: PagingHandler> AddrSpace<H> {
183184
}
184185
self.pt
185186
.query(vaddr)
186-
.map(|(phys_addr, _, _)| {
187+
.map(|(phys_addr, ..)| {
187188
debug!("vaddr {vaddr:?} translate to {phys_addr:?}");
188189
phys_addr
189190
})
@@ -252,7 +253,7 @@ impl<H: PagingHandler> AddrSpace<H> {
252253
if let Some(area) = self.areas.find(vaddr) {
253254
self.pt
254255
.query(vaddr)
255-
.map(|(phys_addr, _, _)| (phys_addr, area.size()))
256+
.map(|(phys_addr, ..)| (phys_addr, area.size()))
256257
.ok()
257258
} else {
258259
None
@@ -278,13 +279,15 @@ impl<H: PagingHandler> Drop for AddrSpace<H> {
278279

279280
#[cfg(test)]
280281
mod tests {
282+
use core::sync::atomic::Ordering;
283+
284+
use axin::axin;
285+
281286
use super::*;
282287
use crate::test_utils::{
283288
ALLOC_COUNT, BASE_PADDR, DEALLOC_COUNT, MEMORY_LEN, MockHal, mock_hal_test,
284289
test_dealloc_count,
285290
};
286-
use axin::axin;
287-
use core::sync::atomic::Ordering;
288291

289292
/// Generate an address space for the test
290293
fn setup_test_addr_space() -> (AddrSpace<MockHal>, GuestPhysAddr, usize) {

src/device/device_addr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ use core::fmt::LowerHex;
1616

1717
use memory_addr::AddrRange;
1818

19-
use crate::GuestPhysAddr;
20-
2119
use super::{Port, SysRegAddr};
20+
use crate::GuestPhysAddr;
2221

2322
/// An address-like type that can be used to access devices.
2423
pub trait DeviceAddr: Copy + Eq + Ord + core::fmt::Debug {}

src/frame.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use core::marker::PhantomData;
1616

1717
use axerrno::{AxResult, ax_err_type};
18-
1918
pub(crate) use memory_addr::PAGE_SIZE_4K as PAGE_SIZE;
2019

2120
use crate::{AxMmHal, HostPhysAddr};
@@ -89,12 +88,14 @@ impl<H: AxMmHal> Drop for PhysFrame<H> {
8988

9089
#[cfg(test)]
9190
mod test {
92-
use super::*;
93-
use crate::test_utils::{BASE_PADDR, MockHal, mock_hal_test, test_dealloc_count};
9491
use alloc::vec::Vec;
92+
9593
use assert_matches::assert_matches;
9694
use axin::axin;
9795

96+
use super::*;
97+
use crate::test_utils::{BASE_PADDR, MockHal, mock_hal_test, test_dealloc_count};
98+
9899
#[test]
99100
#[axin(decorator(mock_hal_test), on_exit(test_dealloc_count(1)))]
100101
fn test_alloc_dealloc_cycle() {

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,10 @@ mod npt;
3131

3232
pub use addr::*;
3333
pub use address_space::*;
34-
34+
use axerrno::AxError;
3535
pub use frame::PhysFrame;
3636
pub use hal::AxMmHal;
37-
3837
pub use memory_accessor::GuestMemoryAccessor;
39-
40-
use axerrno::AxError;
4138
use memory_set::MappingError;
4239

4340
/// Information about nested page faults.

src/memory_accessor.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
//! This module provides a safe and consistent way to access guest memory
1818
//! from VirtIO device implementations, handling address translation and
1919
//! memory safety concerns.
20-
use crate::GuestPhysAddr;
2120
use axerrno::{AxError, AxResult};
2221
use memory_addr::PhysAddr;
2322

23+
use crate::GuestPhysAddr;
24+
2425
/// A stateful accessor to the memory space of a guest
2526
pub trait GuestMemoryAccessor {
2627
/// Translate a guest physical address to host physical address and get access limit
@@ -200,11 +201,12 @@ pub trait GuestMemoryAccessor {
200201

201202
#[cfg(test)]
202203
mod tests {
203-
use super::*;
204-
use crate::test_utils::{BASE_PADDR, mock_hal_test};
205204
use axin::axin;
206205
use memory_addr::PhysAddr;
207206

207+
use super::*;
208+
use crate::test_utils::{BASE_PADDR, mock_hal_test};
209+
208210
/// Mock implementation of GuestMemoryAccessor for testing
209211
struct MockTranslator {
210212
base_addr: PhysAddr,

src/npt/arch/aarch64.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use core::arch::asm;
16-
use core::fmt;
15+
use core::{arch::asm, fmt};
16+
1717
use page_table_entry::{GenericPTE, MappingFlags};
1818
use page_table_multiarch::PagingMetaData;
19+
1920
// use memory_addr::HostPhysAddr;
2021
use crate::{GuestPhysAddr, HostPhysAddr};
2122

@@ -72,8 +73,8 @@ bitflags::bitflags! {
7273
#[repr(u64)]
7374
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
7475
enum MemType {
75-
Device = 0,
76-
Normal = 1,
76+
Device = 0,
77+
Normal = 1,
7778
NormalNonCache = 2,
7879
}
7980

src/npt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,6 @@ impl<H: PagingHandler> NestedPageTable<H> {
192192

193193
/// Translates a virtual address to a physical address.
194194
pub fn translate(&self, vaddr: crate::GuestPhysAddr) -> Option<crate::HostPhysAddr> {
195-
self.query(vaddr).ok().map(|(paddr, _, _)| paddr)
195+
self.query(vaddr).ok().map(|(paddr, ..)| paddr)
196196
}
197197
}

src/test_utils/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use crate::{AxMmHal, HostPhysAddr, HostVirtAddr};
1615
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
16+
1717
use lazy_static::lazy_static;
18-
use memory_addr::{PhysAddr, VirtAddr};
18+
use memory_addr::{PAGE_SIZE_4K as PAGE_SIZE, PhysAddr, VirtAddr};
1919
use page_table_multiarch::PagingHandler;
2020
use spin::Mutex;
2121

22-
use memory_addr::PAGE_SIZE_4K as PAGE_SIZE;
22+
use crate::{AxMmHal, HostPhysAddr, HostVirtAddr};
2323

2424
/// The starting physical address for the simulated memory region in tests.
2525
/// This offset is used to map simulated physical addresses to the `MEMORY` array's virtual address space.

0 commit comments

Comments
 (0)