From e8e28f0e51c233f13720654db03283493a051b45 Mon Sep 17 00:00:00 2001 From: Youjie Zheng Date: Wed, 18 Sep 2024 22:06:20 +0845 Subject: [PATCH] [mm] Add find_free_area function for mmap syscalls --- modules/axhal/src/paging.rs | 2 +- modules/axmm/src/aspace.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/axhal/src/paging.rs b/modules/axhal/src/paging.rs index d34ba0bd02..f09b1d8479 100644 --- a/modules/axhal/src/paging.rs +++ b/modules/axhal/src/paging.rs @@ -79,7 +79,7 @@ pub fn set_kernel_page_table_root(root_paddr: PhysAddr) { /// /// # Panics /// -/// It must be called after [`set_kernel_page_table`], otherwise it will panic. +/// It must be called after [`set_kernel_page_table_root`], otherwise it will panic. pub fn kernel_page_table_root() -> PhysAddr { *KERNEL_PAGE_TABLE_ROOT .get() diff --git a/modules/axmm/src/aspace.rs b/modules/axmm/src/aspace.rs index 7992c458bc..39e377e065 100644 --- a/modules/axmm/src/aspace.rs +++ b/modules/axmm/src/aspace.rs @@ -74,6 +74,20 @@ impl AddrSpace { Ok(()) } + /// Finds a free area that can accommodate the given size. + /// + /// The search starts from the given hint address, and the area should be within the given limit range. + /// + /// Returns the start address of the free area. Returns None if no such area is found. + pub fn find_free_area( + &self, + hint: VirtAddr, + size: usize, + limit: VirtAddrRange, + ) -> Option { + self.areas.find_free_area(hint, size, limit) + } + /// Add a new linear mapping. /// /// See [`Backend`] for more details about the mapping backends.