mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 00:43:24 +00:00
Make mprotect&munmap return fast when len is zero
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
212440dbb1
commit
aa77747f94
@ -12,7 +12,17 @@ pub fn sys_mprotect(addr: Vaddr, len: usize, perms: u64, ctx: &Context) -> Resul
|
||||
addr, len, vm_perms
|
||||
);
|
||||
let root_vmar = ctx.process.root_vmar();
|
||||
debug_assert!(addr % PAGE_SIZE == 0);
|
||||
|
||||
// According to linux behavior,
|
||||
// <https://elixir.bootlin.com/linux/v6.0.9/source/mm/mprotect.c#L681>,
|
||||
// the addr is checked even if len is 0.
|
||||
if addr % PAGE_SIZE != 0 {
|
||||
return_errno_with_message!(Errno::EINVAL, "the start address should be page aligned");
|
||||
}
|
||||
if len == 0 {
|
||||
return Ok(SyscallReturn::Return(0));
|
||||
}
|
||||
|
||||
let len = len.align_up(PAGE_SIZE);
|
||||
let range = addr..(addr + len);
|
||||
root_vmar.protect(vm_perms, range)?;
|
||||
|
@ -7,6 +7,14 @@ use crate::prelude::*;
|
||||
|
||||
pub fn sys_munmap(addr: Vaddr, len: usize, ctx: &Context) -> Result<SyscallReturn> {
|
||||
debug!("addr = 0x{:x}, len = {}", addr, len);
|
||||
|
||||
if addr % PAGE_SIZE != 0 {
|
||||
return_errno_with_message!(Errno::EINVAL, "munmap addr must be page-aligned");
|
||||
}
|
||||
if len == 0 {
|
||||
return_errno_with_message!(Errno::EINVAL, "munmap len cannot be zero");
|
||||
}
|
||||
|
||||
let root_vmar = ctx.process.root_vmar();
|
||||
let len = len.align_up(PAGE_SIZE);
|
||||
debug!("unmap range = 0x{:x} - 0x{:x}", addr, addr + len);
|
||||
|
Reference in New Issue
Block a user