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

View File

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

View File

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