@@ -2,14 +2,13 @@ use core::fmt;
2
2
3
3
use axerrno:: { AxError , AxResult , ax_err} ;
4
4
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} ;
7
7
use memory_set:: { MemoryArea , MemorySet } ;
8
- use page_table_multiarch:: PageSize ;
9
8
10
9
use crate :: backend:: Backend ;
11
10
use crate :: mapping_err_to_ax_err;
12
- use crate :: page_iter_wrapper:: PageIterWrapper ;
11
+ use crate :: page_iter_wrapper:: { PAGE_SIZE_4K , PageIterWrapper } ;
13
12
14
13
#[ cfg( feature = "cow" ) ]
15
14
use crate :: backend:: { alloc_frame, dealloc_frame} ;
@@ -235,8 +234,8 @@ impl AddrSpace {
235
234
///
236
235
/// # Parameters
237
236
///
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 .
240
239
/// - `access_flags` indicates the access type
241
240
///
242
241
/// # Returns
@@ -269,7 +268,13 @@ impl AddrSpace {
269
268
270
269
let backend = area. backend ( ) ;
271
270
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
+ {
273
278
match self . pt . query ( addr) {
274
279
#[ allow( unused_variables) ]
275
280
Ok ( ( paddr, flags, page_size) ) => {
@@ -550,8 +555,8 @@ impl AddrSpace {
550
555
/// ### Behavior without `cow` Feature
551
556
/// - Each mapped page in the original address space is copied into the
552
557
/// 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.
555
560
/// - The actual copying is done using [`core::ptr::copy_nonoverlapping`] at the
556
561
/// physical address level.
557
562
pub fn try_clone ( & mut self ) -> AxResult < Self > {
0 commit comments