Resolve minor issues in mmap

This commit is contained in:
Zhang Junyang
2023-08-04 10:21:37 +08:00
committed by Tate, Hongliang Tian
parent 48ae6611f6
commit b54843172b
3 changed files with 16 additions and 20 deletions

View File

@ -37,17 +37,17 @@ bitflags! {
}
#[derive(Debug)]
pub struct MMapOption {
pub struct MMapOptions {
typ: MMapType,
flags: MMapFlags,
}
impl TryFrom<u64> for MMapOption {
impl TryFrom<u32> for MMapOptions {
type Error = Error;
fn try_from(value: u64) -> Result<Self> {
let typ_raw = value as u32 & MAP_TYPE;
let flags_raw = value as u32 & !MAP_TYPE;
fn try_from(value: u32) -> Result<Self> {
let typ_raw = value & MAP_TYPE;
let flags_raw = value & !MAP_TYPE;
let typ = match typ_raw {
0x0 => MMapType::MapFile,
0x1 => MMapType::MapShared,
@ -55,18 +55,14 @@ impl TryFrom<u64> for MMapOption {
0x3 => MMapType::MapSharedValidate,
_ => return Err(Error::with_message(Errno::EINVAL, "unknown mmap flags")),
};
if let Some(flags) = MMapFlags::from_bits(flags_raw) {
Ok(MMapOption {
typ: typ,
flags: flags,
})
} else {
Err(Error::with_message(Errno::EINVAL, "unknown mmap flags"))
}
let Some(flags) = MMapFlags::from_bits(flags_raw) else {
return Err(Error::with_message(Errno::EINVAL, "unknown mmap flags"));
};
Ok(MMapOptions { typ, flags })
}
}
impl MMapOption {
impl MMapOptions {
pub fn typ(&self) -> MMapType {
self.typ
}

View File

@ -4,7 +4,7 @@
//! So we define a UserVm struct to store such infomation.
//! Briefly, it contains the exact usage of each segment of virtual spaces.
pub mod mmap_flags;
pub mod mmap_options;
pub mod user_heap;
use crate::prelude::*;

View File

@ -1,7 +1,7 @@
//! This mod defines mmap flags and the handler to syscall mmap
use crate::fs::file_table::FileDescripter;
use crate::process::process_vm::mmap_flags::{MMapFlags, MMapOption, MMapType};
use crate::process::process_vm::mmap_options::{MMapFlags, MMapOptions, MMapType};
use crate::vm::perms::VmPerms;
use crate::vm::vmo::{VmoChildOptions, VmoOptions, VmoRightsOp};
use crate::{log_syscall_entry, prelude::*};
@ -23,7 +23,7 @@ pub fn sys_mmap(
) -> Result<SyscallReturn> {
log_syscall_entry!(SYS_MMAP);
let perms = VmPerm::try_from(perms).unwrap();
let option = MMapOption::try_from(flags).unwrap();
let option = MMapOptions::try_from(flags as u32).unwrap();
let res = do_sys_mmap(
addr as usize,
len as usize,
@ -39,7 +39,7 @@ pub fn do_sys_mmap(
addr: Vaddr,
len: usize,
vm_perm: VmPerm,
option: MMapOption,
option: MMapOptions,
fd: FileDescripter,
offset: usize,
) -> Result<Vaddr> {
@ -67,7 +67,7 @@ fn mmap_anonymous_vmo(
len: usize,
offset: usize,
perms: VmPerms,
option: MMapOption,
option: MMapOptions,
) -> Result<Vaddr> {
assert!(option.flags().contains(MMapFlags::MAP_ANONYMOUS));
debug_assert!(offset == 0);
@ -97,7 +97,7 @@ fn mmap_filebacked_vmo(
len: usize,
offset: usize,
perms: VmPerms,
option: MMapOption,
option: MMapOptions,
) -> Result<Vaddr> {
let current = current!();
let page_cache_vmo = {