Skip to content

Commit 74ee9c1

Browse files
committed
rustfmt
1 parent d8acfbc commit 74ee9c1

31 files changed

+509
-603
lines changed

ci/script.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -euxo pipefail
44

5+
export PATH=$PATH:~/.cargo/bin
6+
57
if [ -n "${TARGET:-}" ]; then
68
cargo check --target $TARGET
79

src/addr/mod.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,38 +64,35 @@ pub use self::sv32::*;
6464
pub use self::sv39::*;
6565
pub use self::sv48::*;
6666

67-
6867
#[macro_export]
69-
macro_rules! use_sv32{
70-
()=>{
68+
macro_rules! use_sv32 {
69+
() => {
7170
pub type VirtAddr = VirtAddrSv32;
7271
pub type PhysAddr = PhysAddrSv32;
7372
pub type Page = PageWith<VirtAddr>;
7473
pub type Frame = FrameWith<PhysAddr>;
75-
}
74+
};
7675
}
7776
#[macro_export]
78-
macro_rules! use_sv39{
79-
()=>{
77+
macro_rules! use_sv39 {
78+
() => {
8079
pub type VirtAddr = VirtAddrSv39;
8180
pub type PhysAddr = PhysAddrSv39;
8281
pub type Page = PageWith<VirtAddr>;
8382
pub type Frame = FrameWith<PhysAddr>;
84-
}
83+
};
8584
}
8685
#[macro_export]
87-
macro_rules! use_sv48{
88-
()=>{
86+
macro_rules! use_sv48 {
87+
() => {
8988
pub type VirtAddr = VirtAddrSv48;
9089
pub type PhysAddr = PhysAddrSv48;
9190
pub type Page = PageWith<VirtAddr>;
9291
pub type Frame = FrameWith<PhysAddr>;
93-
}
92+
};
9493
}
9594
#[cfg(target_arch = "riscv64")]
9695
use_sv48!();
9796

9897
#[cfg(target_arch = "riscv32")]
9998
use_sv32!();
100-
101-

src/asm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub unsafe fn sfence_vma(asid: usize, addr: usize) {
7575
}
7676

7777
#[cfg(feature = "hypervisor")]
78-
mod hypervisor_extension{
78+
mod hypervisor_extension {
7979
// Generating instructions for Hypervisor extension.
8080
// There are two kinds of instructions: rs1/rs2 type and rs1/rd type.
8181
// Also special register handling is required before LLVM could generate inline assembly for extended instructions.
@@ -151,4 +151,4 @@ mod hypervisor_extension{
151151
}
152152

153153
#[cfg(feature = "hypervisor")]
154-
pub use self::hypervisor_extension::*;
154+
pub use self::hypervisor_extension::*;

src/paging/frame_alloc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ pub trait FrameDeallocatorFor<P: PhysicalAddress> {
1616
/// Polyfill for default use cases.
1717
1818
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
19-
pub trait FrameAllocator{
19+
pub trait FrameAllocator {
2020
fn alloc(&mut self) -> Option<Frame>;
2121
}
2222
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
23-
pub trait FrameDeallocator{
23+
pub trait FrameDeallocator {
2424
fn dealloc(&mut self, frame: Frame);
2525
}
2626

2727
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
28-
impl<T: FrameAllocator> FrameAllocatorFor<PhysAddr> for T{
28+
impl<T: FrameAllocator> FrameAllocatorFor<PhysAddr> for T {
2929
#[inline]
30-
fn alloc(&mut self) -> Option<Frame>{
30+
fn alloc(&mut self) -> Option<Frame> {
3131
FrameAllocator::alloc(self)
3232
}
3333
}
3434
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
35-
impl<T: FrameDeallocator> FrameDeallocatorFor<PhysAddr> for T{
35+
impl<T: FrameDeallocator> FrameDeallocatorFor<PhysAddr> for T {
3636
#[inline]
37-
fn dealloc(&mut self, frame: Frame){
37+
fn dealloc(&mut self, frame: Frame) {
3838
FrameDeallocator::dealloc(self, frame)
3939
}
40-
}
40+
}

src/paging/multi_level.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::marker::PhantomData;
88
pub struct Rv32PageTableWith<'a, V: VirtualAddress + AddressL2, FL: MapperFlushable> {
99
root_table: &'a mut PageTableX32,
1010
linear_offset: u64, // VA = PA + linear_offset
11-
phantom: PhantomData<fn()->(V, FL)>,
11+
phantom: PhantomData<fn() -> (V, FL)>,
1212
}
1313

1414
impl<'a, V: VirtualAddress + AddressL2, FL: MapperFlushable> Rv32PageTableWith<'a, V, FL> {
@@ -26,9 +26,7 @@ impl<'a, V: VirtualAddress + AddressL2, FL: MapperFlushable> Rv32PageTableWith<'
2626
allocator: &mut impl FrameAllocatorFor<<Self as Mapper>::P>,
2727
) -> Result<&mut PageTableX32, MapToError> {
2828
if self.root_table[p2_index].is_unused() {
29-
let frame = allocator
30-
.alloc()
31-
.ok_or(MapToError::FrameAllocationFailed)?;
29+
let frame = allocator.alloc().ok_or(MapToError::FrameAllocationFailed)?;
3230
self.root_table[p2_index].set(frame.clone(), F::VALID);
3331
let p1_table: &mut PageTableX32 = unsafe { frame.as_kernel_mut(self.linear_offset) };
3432
p1_table.zero();
@@ -66,7 +64,8 @@ impl<'a, V: VirtualAddress + AddressL2, FL: MapperFlushable> Mapper
6664
fn unmap(
6765
&mut self,
6866
page: <Self as MapperExt>::Page,
69-
) -> Result<(<Self as MapperExt>::Frame, Self::MapperFlush), UnmapError<<Self as Mapper>::P>> {
67+
) -> Result<(<Self as MapperExt>::Frame, Self::MapperFlush), UnmapError<<Self as Mapper>::P>>
68+
{
7069
if self.root_table[page.p2_index()].is_unused() {
7170
return Err(UnmapError::PageNotMapped);
7271
}
@@ -99,7 +98,7 @@ impl<'a, V: VirtualAddress + AddressL2, FL: MapperFlushable> Mapper
9998
pub struct Rv39PageTableWith<'a, V: VirtualAddress + AddressL3, FL: MapperFlushable> {
10099
root_table: &'a mut PageTableX64,
101100
linear_offset: u64, // VA = PA + linear_offset
102-
phantom: PhantomData<fn()-> (V, FL)>,
101+
phantom: PhantomData<fn() -> (V, FL)>,
103102
}
104103

105104
impl<'a, V: VirtualAddress + AddressL3, FL: MapperFlushable> Rv39PageTableWith<'a, V, FL> {
@@ -118,9 +117,7 @@ impl<'a, V: VirtualAddress + AddressL3, FL: MapperFlushable> Rv39PageTableWith<'
118117
allocator: &mut impl FrameAllocatorFor<<Self as Mapper>::P>,
119118
) -> Result<&mut PageTableX64, MapToError> {
120119
let p2_table = if self.root_table[p3_index].is_unused() {
121-
let frame = allocator
122-
.alloc()
123-
.ok_or(MapToError::FrameAllocationFailed)?;
120+
let frame = allocator.alloc().ok_or(MapToError::FrameAllocationFailed)?;
124121
self.root_table[p3_index].set(frame.clone(), F::VALID);
125122
let p2_table: &mut PageTableX64 = unsafe { frame.as_kernel_mut(self.linear_offset) };
126123
p2_table.zero();
@@ -130,9 +127,7 @@ impl<'a, V: VirtualAddress + AddressL3, FL: MapperFlushable> Rv39PageTableWith<'
130127
unsafe { frame.as_kernel_mut(self.linear_offset) }
131128
};
132129
if p2_table[p2_index].is_unused() {
133-
let frame = allocator
134-
.alloc()
135-
.ok_or(MapToError::FrameAllocationFailed)?;
130+
let frame = allocator.alloc().ok_or(MapToError::FrameAllocationFailed)?;
136131
p2_table[p2_index].set(frame.clone(), F::VALID);
137132
let p1_table: &mut PageTableX64 = unsafe { frame.as_kernel_mut(self.linear_offset) };
138133
p1_table.zero();
@@ -170,7 +165,8 @@ impl<'a, V: VirtualAddress + AddressL3, FL: MapperFlushable> Mapper
170165
fn unmap(
171166
&mut self,
172167
page: <Self as MapperExt>::Page,
173-
) -> Result<(<Self as MapperExt>::Frame, Self::MapperFlush), UnmapError<<Self as Mapper>::P>> {
168+
) -> Result<(<Self as MapperExt>::Frame, Self::MapperFlush), UnmapError<<Self as Mapper>::P>>
169+
{
174170
if self.root_table[page.p3_index()].is_unused() {
175171
return Err(UnmapError::PageNotMapped);
176172
}
@@ -235,9 +231,7 @@ impl<'a, V: VirtualAddress + AddressL4, FL: MapperFlushable> Rv48PageTableWith<'
235231
allocator: &mut impl FrameAllocatorFor<<Self as Mapper>::P>,
236232
) -> Result<&mut PageTableX64, MapToError> {
237233
let p3_table = if self.root_table[p4_index].is_unused() {
238-
let frame = allocator
239-
.alloc()
240-
.ok_or(MapToError::FrameAllocationFailed)?;
234+
let frame = allocator.alloc().ok_or(MapToError::FrameAllocationFailed)?;
241235
self.root_table[p4_index].set(frame.clone(), F::VALID);
242236
let p3_table: &mut PageTableX64 = unsafe { frame.as_kernel_mut(self.linear_offset) };
243237
p3_table.zero();
@@ -248,9 +242,7 @@ impl<'a, V: VirtualAddress + AddressL4, FL: MapperFlushable> Rv48PageTableWith<'
248242
};
249243

250244
let p2_table = if p3_table[p3_index].is_unused() {
251-
let frame = allocator
252-
.alloc()
253-
.ok_or(MapToError::FrameAllocationFailed)?;
245+
let frame = allocator.alloc().ok_or(MapToError::FrameAllocationFailed)?;
254246
p3_table[p3_index].set(frame.clone(), F::VALID);
255247
let p2_table: &mut PageTableX64 = unsafe { frame.as_kernel_mut(self.linear_offset) };
256248
p2_table.zero();
@@ -261,9 +253,7 @@ impl<'a, V: VirtualAddress + AddressL4, FL: MapperFlushable> Rv48PageTableWith<'
261253
};
262254

263255
if p2_table[p2_index].is_unused() {
264-
let frame = allocator
265-
.alloc()
266-
.ok_or(MapToError::FrameAllocationFailed)?;
256+
let frame = allocator.alloc().ok_or(MapToError::FrameAllocationFailed)?;
267257
p2_table[p2_index].set(frame.clone(), F::VALID);
268258
let p1_table: &mut PageTableX64 = unsafe { frame.as_kernel_mut(self.linear_offset) };
269259
p1_table.zero();
@@ -306,7 +296,8 @@ impl<'a, V: VirtualAddress + AddressL4, FL: MapperFlushable> Mapper
306296
fn unmap(
307297
&mut self,
308298
page: <Self as MapperExt>::Page,
309-
) -> Result<(<Self as MapperExt>::Frame, Self::MapperFlush), UnmapError<<Self as Mapper>::P>> {
299+
) -> Result<(<Self as MapperExt>::Frame, Self::MapperFlush), UnmapError<<Self as Mapper>::P>>
300+
{
310301
if self.root_table[page.p4_index()].is_unused() {
311302
return Err(UnmapError::PageNotMapped);
312303
}

src/paging/multi_level_x4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::addr::*;
2+
use crate::asm::{hfence_gvma, hfence_vvma};
23
use crate::paging::multi_level::Rv32PageTableWith;
34
use crate::paging::multi_level::{Rv39PageTableWith, Rv48PageTableWith};
45
use crate::paging::recursive::MapperFlushable;
5-
use crate::asm::{hfence_gvma, hfence_vvma};
66

77
#[must_use = "Guest Physical Address Table changes must be flushed or ignored."]
88
pub struct MapperFlushGPA(usize);

src/paging/recursive.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,10 @@ impl<'a> Mapper for RecursivePageTable<'a> {
453453
Ok(MapperFlush::new(page))
454454
}
455455

456-
fn unmap(&mut self, page: Page) -> Result<(Frame, MapperFlush), UnmapError<<Self as Mapper>::P>> {
456+
fn unmap(
457+
&mut self,
458+
page: Page,
459+
) -> Result<(Frame, MapperFlush), UnmapError<<Self as Mapper>::P>> {
457460
if self.root_table[page.p2_index()].is_unused() {
458461
return Err(UnmapError::PageNotMapped);
459462
}
@@ -509,7 +512,10 @@ impl<'a> Mapper for RecursivePageTable<'a> {
509512
Ok(MapperFlush::new(page))
510513
}
511514

512-
fn unmap(&mut self, page: Page) -> Result<(Frame, MapperFlush), UnmapError<<Self as Mapper>::P>> {
515+
fn unmap(
516+
&mut self,
517+
page: Page,
518+
) -> Result<(Frame, MapperFlush), UnmapError<<Self as Mapper>::P>> {
513519
let p1_table = self.ref_p1(page).ok_or(UnmapError::PageNotMapped)?;
514520
let p1_entry = &mut p1_table[page.p1_index()];
515521
if !p1_entry.flags().contains(F::VALID) {

0 commit comments

Comments
 (0)