Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions api/ruxos_posix_api/src/imp/mmap/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn sys_mmap(
fid
};

let mut new = Vma::new(fid, offset, prot, flags);
let mut new = Vma::new(fid, offset, prot, flags)?;
let binding_task = current();
let mut vma_map = binding_task.mm.vma_map.lock();
let addr_condition = if start == 0 { None } else { Some(start) };
Expand Down Expand Up @@ -460,10 +460,11 @@ pub fn sys_mremap(
return Err(LinuxError::ENOMEM);
}
// find the right region to expand them in orignal addr.
let dummy_vma = Vma::new(-1, 0, 0, 0).unwrap();
let (upper, _) = vma_map
.lower_bound(Bound::Included(&old_end))
.peek_next()
.unwrap_or((&VMA_END, &Vma::new(-1, 0, 0, 0)));
.unwrap_or((&VMA_END, &dummy_vma));
if upper - old_end >= new_size - old_size {
let ret = old_vma.start_addr;
let new_end = old_start + new_size;
Expand Down
3 changes: 2 additions & 1 deletion api/ruxos_posix_api/src/imp/mmap/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ pub(crate) fn find_free_region(
} else {
VMA_START
};
let dummy_vma = Vma::new(-1, 0, 0, 0).unwrap();
let (upper, _) = vma_map
.lower_bound(Bound::Included(&start))
.peek_next()
.unwrap_or((&VMA_END, &Vma::new(-1, 0, 0, 0)));
.unwrap_or((&VMA_END, &dummy_vma));
if upper - start >= len && end_addr <= start {
return Some(start);
}
Expand Down
11 changes: 6 additions & 5 deletions modules/ruxtask/src/vma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::fs::get_file_like;
use crate::TaskId;
use alloc::{collections::BTreeMap, sync::Arc};
use axalloc::global_allocator;
use axerrno::LinuxError;
use memory_addr::PhysAddr;
use ruxfs::File;
use ruxhal::mem::phys_to_virt;
Expand Down Expand Up @@ -181,20 +182,20 @@ impl Default for MmapStruct {
/// Impl for Vma.
impl Vma {
/// Create a new `Vma` instance.
pub fn new(_fid: i32, offset: usize, prot: u32, flags: u32) -> Self {
pub fn new(_fid: i32, offset: usize, prot: u32, flags: u32) -> Result<Self, LinuxError> {
// #[cfg(feature = "fs")]
let file = if _fid < 0 {
None
} else {
let f = get_file_like(_fid).expect("invaild fd for vma");
let f = get_file_like(_fid)?;
Some(
f.clone()
.into_any()
.downcast::<File>()
.expect("should be effective fid"),
.map_err(|_| LinuxError::EBADF)?,
)
};
Vma {
Ok(Vma {
start_addr: 0,
end_addr: 0,
size: 0,
Expand All @@ -204,7 +205,7 @@ impl Vma {
flags,
prot,
from_process: current().id(),
}
})
}

/// Clone a new `Vma` instance.
Expand Down
Loading