From 22f9c072f3cca8d5c475a8c42635d81fd23d81c3 Mon Sep 17 00:00:00 2001 From: Marsman1996 Date: Sun, 18 Aug 2024 14:58:00 +0800 Subject: [PATCH] Move the check location following Linux behaviors --- kernel/aster-nix/src/syscall/madvise.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/aster-nix/src/syscall/madvise.rs b/kernel/aster-nix/src/syscall/madvise.rs index 47db5ec1d..909875155 100644 --- a/kernel/aster-nix/src/syscall/madvise.rs +++ b/kernel/aster-nix/src/syscall/madvise.rs @@ -14,6 +14,14 @@ pub fn sys_madvise( "start = 0x{:x}, len = 0x{:x}, behavior = {:?}", start, len, behavior ); + + if start % PAGE_SIZE != 0 { + return_errno_with_message!(Errno::EINVAL, "the start address should be page aligned"); + } + if len == 0 { + return Ok(SyscallReturn::Return(0)); + } + match behavior { MadviseBehavior::MADV_NORMAL | MadviseBehavior::MADV_SEQUENTIAL @@ -33,16 +41,8 @@ pub fn sys_madvise( } fn madv_free(start: Vaddr, len: usize, ctx: &Context) -> Result<()> { - if start % PAGE_SIZE != 0 { - return_errno_with_message!(Errno::EINVAL, "the start address should be page aligned"); - } - if len % PAGE_SIZE != 0 { - return_errno_with_message!(Errno::EINVAL, "the length should be page aligned"); - } - - if len == 0 { - return_errno_with_message!(Errno::EINVAL, "madv_free len cannot be zero"); + return Ok(()); } let root_vmar = ctx.process.root_vmar();