Skip to content

Commit 54d5739

Browse files
committed
[style] format the code style for axmm
1 parent 5c5fcfe commit 54d5739

File tree

11 files changed

+47
-35
lines changed

11 files changed

+47
-35
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/arceos_posix_api/src/imp/path_link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn handle_relative_path(dir_fd: isize, path: &str) -> AxResult<String> {
364364
fn prepend_cwd(path: &str) -> AxResult<String> {
365365
let cwd = current_dir().map_err(|_| AxError::NotFound)?;
366366
debug_assert!(cwd.ends_with('/'), "当前工作目录路径应以 '/' 结尾");
367-
Ok(format!("{}{}", cwd, path))
367+
Ok(format!("{cwd}{path}"))
368368
}
369369

370370
/// 根据 `force_dir` 和路径结尾调整路径

modules/axhal/src/arch/x86_64/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl TaskContext {
429429
self.ext_state.save();
430430
next_ctx.ext_state.restore();
431431
}
432-
#[cfg(any(feature = "tls"))]
432+
#[cfg(feature = "tls")]
433433
unsafe {
434434
self.fs_base = super::read_thread_pointer();
435435
super::write_thread_pointer(next_ctx.fs_base);

modules/axmm/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ documentation = "https://arceos-org.github.io/arceos/axmm/index.html"
1111

1212
[features]
1313
default = []
14-
cow = []
14+
cow = ["dep:lazy_static"]
1515

1616
[dependencies]
1717
axhal = { workspace = true, features = ["paging"] }
1818
axalloc = { workspace = true }
1919
axconfig = { workspace = true }
2020

21-
lazy_static = { version = "1.5", features = ["spin_no_std"] }
21+
lazy_static = { version = "1.5", features = ["spin_no_std"], optional = true }
2222
log = "=0.4.21"
2323
axerrno = "0.1"
2424
lazyinit = "0.2"
2525
memory_addr = "0.3"
2626
kspin = "0.1"
2727
memory_set = "0.3"
28-
page_table_multiarch = "0.5.3"

modules/axmm/src/aspace.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ use core::fmt;
22

33
use axerrno::{AxError, AxResult, ax_err};
44
use axhal::mem::phys_to_virt;
5-
use axhal::paging::{MappingFlags, PageTable, PagingError};
6-
use memory_addr::{MemoryAddr, PAGE_SIZE_4K, PhysAddr, VirtAddr, VirtAddrRange, is_aligned};
5+
use axhal::paging::{MappingFlags, PageSize, PageTable, PagingError};
6+
use memory_addr::{MemoryAddr, PhysAddr, VirtAddr, VirtAddrRange, is_aligned};
77
use memory_set::{MemoryArea, MemorySet};
8-
use page_table_multiarch::PageSize;
98

109
use crate::backend::Backend;
1110
use crate::mapping_err_to_ax_err;
12-
use crate::page_iter_wrapper::PageIterWrapper;
11+
use crate::page_iter_wrapper::{PAGE_SIZE_4K, PageIterWrapper};
1312

1413
#[cfg(feature = "cow")]
1514
use crate::backend::{alloc_frame, dealloc_frame};
@@ -235,8 +234,8 @@ impl AddrSpace {
235234
///
236235
/// # Parameters
237236
///
238-
/// - `start`: The starting virtual address of the region to map.
239-
/// - `size`: The size (in bytes) of the region.
237+
/// - `start`: The starting virtual address of the region to map, which must be page-aligned.
238+
/// - `size`: The size (in bytes) of the region, which must also be page-aligned.
240239
/// - `access_flags` indicates the access type
241240
///
242241
/// # Returns
@@ -269,7 +268,13 @@ impl AddrSpace {
269268

270269
let backend = area.backend();
271270
if let Backend::Alloc { populate, align } = *backend {
272-
for addr in PageIterWrapper::new(start, area.end().min(end), align).unwrap() {
271+
for addr in PageIterWrapper::new(
272+
start.align_down(align),
273+
end.align_up(align).min(area.end()),
274+
align,
275+
)
276+
.unwrap()
277+
{
273278
match self.pt.query(addr) {
274279
#[allow(unused_variables)]
275280
Ok((paddr, flags, page_size)) => {
@@ -550,8 +555,8 @@ impl AddrSpace {
550555
/// ### Behavior without `cow` Feature
551556
/// - Each mapped page in the original address space is copied into the
552557
/// corresponding address in the new address space.
553-
/// - If the target address in the new space is not mapped, a page fault is
554-
/// handled via [`Backend::handle_page_fault`], and memory is allocated before copying.
558+
/// - If the target address in the new space is not mapped, a page fault will be
559+
/// handled, and memory is allocated before copying.
555560
/// - The actual copying is done using [`core::ptr::copy_nonoverlapping`] at the
556561
/// physical address level.
557562
pub fn try_clone(&mut self) -> AxResult<Self> {

modules/axmm/src/backend/alloc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::page_iter_wrapper::PageIterWrapper;
1+
use crate::page_iter_wrapper::{PAGE_SIZE_4K, PageIterWrapper};
22
use axalloc::global_allocator;
33
use axhal::mem::{phys_to_virt, virt_to_phys};
44
use axhal::paging::{MappingFlags, PageSize, PageTable};
5-
use memory_addr::{PAGE_SIZE_4K, PhysAddr, VirtAddr};
5+
use memory_addr::{PhysAddr, VirtAddr};
66

77
#[cfg(feature = "cow")]
88
use crate::frameinfo::frame_table;
@@ -28,7 +28,7 @@ use super::Backend;
2828
/// - If `zeroed` is `true`, the function uses `unsafe` operations to zero out the memory.
2929
/// - The allocated memory must be accessed via its physical address, which requires
3030
/// conversion using `virt_to_phys`.
31-
pub fn alloc_frame(zeroed: bool, align: PageSize) -> Option<PhysAddr> {
31+
pub(crate) fn alloc_frame(zeroed: bool, align: PageSize) -> Option<PhysAddr> {
3232
let page_size: usize = align.into();
3333
let num_pages = page_size / PAGE_SIZE_4K;
3434
let vaddr = VirtAddr::from(global_allocator().alloc_pages(num_pages, page_size).ok()?);
@@ -62,7 +62,7 @@ pub fn alloc_frame(zeroed: bool, align: PageSize) -> Option<PhysAddr> {
6262
/// otherwise undefined behavior may occur.
6363
/// - If the deallocation fails, the function will call `panic!`. Details about
6464
/// the failure can be obtained from the global memory allocator’s error messages.
65-
pub fn dealloc_frame(frame: PhysAddr, align: PageSize) {
65+
pub(crate) fn dealloc_frame(frame: PhysAddr, align: PageSize) {
6666
#[cfg(feature = "cow")]
6767
if frame_table().dec_ref(frame) > 1 {
6868
return;

modules/axmm/src/backend/linear.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use axhal::paging::{MappingFlags, PageTable};
1+
use axhal::paging::{MappingFlags, PageSize, PageTable};
22
use memory_addr::{PhysAddr, VirtAddr};
3-
use page_table_multiarch::PageSize;
43

54
use super::Backend;
65

modules/axmm/src/backend/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
//! Memory mapping backends.
22
3-
use axhal::paging::{MappingFlags, PageTable};
3+
use axhal::paging::{MappingFlags, PageSize, PageTable};
44
use memory_addr::VirtAddr;
55
use memory_set::MappingBackend;
6-
use page_table_multiarch::PageSize;
7-
86
mod alloc;
97
mod linear;
108

11-
pub use alloc::{alloc_frame, dealloc_frame};
9+
#[allow(unused_imports)]
10+
pub(crate) use alloc::{alloc_frame, dealloc_frame};
1211

1312
/// A unified enum type for different memory mapping backends.
1413
///

modules/axmm/src/frameinfo.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//! FrameInfo
2-
//!
31
//! A simple physical FrameInfo manager is provided to track and manage
42
//! the reference count for every 4KB memory page frame in the system.
53
//!

modules/axmm/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ mod aspace;
1010
mod backend;
1111
#[cfg(feature = "cow")]
1212
mod frameinfo;
13-
mod page_iter_wrapper;
1413

14+
pub mod page_iter_wrapper;
1515
pub use self::aspace::AddrSpace;
1616
pub use self::backend::Backend;
1717

1818
use axerrno::{AxError, AxResult};
1919
use axhal::mem::phys_to_virt;
20+
use axhal::paging::PageSize;
2021
use kspin::SpinNoIrq;
2122
use lazyinit::LazyInit;
2223
use memory_addr::{PhysAddr, va};
2324
use memory_set::MappingError;
24-
use page_table_multiarch::PageSize;
2525

2626
static KERNEL_ASPACE: LazyInit<SpinNoIrq<AddrSpace>> = LazyInit::new();
2727

0 commit comments

Comments
 (0)