Re: [PATCH 13/19] Unify sys_mmap*

From: Geert Uytterhoeven
Date: Mon Dec 07 2009 - 03:32:18 EST


On Mon, Dec 7, 2009 at 04:54, Al Viro <viro@xxxxxxxxxxxxxxxx> wrote:
>
> New helper - sys_mmap_pgoff(); switch syscalls to using it.
>
> Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
> ---
> Âarch/alpha/kernel/osf_sys.c        |  19 ++-----
> Âarch/arm/kernel/entry-common.S Â Â Â Â Â Â| Â Â4 +-
> Âarch/arm/kernel/sys_arm.c         |  30 +----------
> Âarch/avr32/include/asm/syscalls.h     |  Â4 --
> Âarch/avr32/kernel/sys_avr32.c       |  31 -----------
> Âarch/avr32/kernel/syscall-stubs.S Â Â Â Â | Â Â2 +-
> Âarch/blackfin/kernel/sys_bfin.c      |  33 -----------
> Âarch/blackfin/mach-common/entry.S Â Â Â Â | Â Â2 +-
> Âarch/cris/kernel/sys_cris.c        |  30 +---------
> Âarch/frv/kernel/sys_frv.c         |  66 +----------------------
> Âarch/h8300/kernel/sys_h8300.c       |  83 +----------------------------
> Âarch/h8300/kernel/syscalls.S Â Â Â Â Â Â Â| Â Â2 +-
> Âarch/ia64/kernel/sys_ia64.c        |  37 +------------
> Âarch/m32r/kernel/sys_m32r.c        |  24 --------
> Âarch/m32r/kernel/syscall_table.S Â Â Â Â Â| Â Â2 +-
> Âarch/m68k/kernel/sys_m68k.c        |  79 ++--------------------------
> Âarch/m68knommu/kernel/sys_m68k.c     Â|  38 +------------
> Âarch/m68knommu/kernel/syscalltable.S Â Â Â| Â Â2 +-
> Âarch/microblaze/kernel/sys_microblaze.c  |  38 +------------
> Âarch/microblaze/kernel/syscall_table.S Â Â| Â Â2 +-
> Âarch/mips/kernel/linux32.c        Â|  19 +------
> Âarch/mips/kernel/syscall.c        Â|  29 +---------
> Âarch/mn10300/kernel/entry.S Â Â Â Â Â Â Â | Â Â2 +-
> Âarch/mn10300/kernel/sys_mn10300.c     |  31 +----------
> Âarch/parisc/kernel/sys_parisc.c      |  30 ++---------
> Âarch/powerpc/kernel/syscalls.c      Â|  15 +-----
> Âarch/s390/kernel/compat_linux.c      |  32 +----------
> Âarch/s390/kernel/sys_s390.c        |  30 +----------
> Âarch/score/kernel/sys_score.c       |  21 +------
> Âarch/sh/kernel/sys_sh.c          |  28 +---------
> Âarch/sparc/kernel/sys_sparc_32.c     Â|  31 ++---------
> Âarch/sparc/kernel/sys_sparc_64.c     Â|  22 ++------
> Âarch/um/kernel/syscall.c         Â|  28 +---------
> Âarch/um/sys-i386/shared/sysdep/syscalls.h | Â Â4 --
> Âarch/x86/ia32/ia32entry.S Â Â Â Â Â Â Â Â | Â Â2 +-
> Âarch/x86/ia32/sys_ia32.c         Â|  43 +---------------
> Âarch/x86/include/asm/sys_ia32.h      |  Â3 -
> Âarch/x86/include/asm/syscalls.h      |  Â2 -
> Âarch/x86/kernel/sys_i386_32.c       |  27 +---------
> Âarch/x86/kernel/sys_x86_64.c       Â|  17 +------
> Âarch/x86/kernel/syscall_table_32.S Â Â Â Â| Â Â2 +-
> Âarch/xtensa/include/asm/syscall.h     |  Â2 -
> Âarch/xtensa/include/asm/unistd.h     Â|  Â2 +-
> Âarch/xtensa/kernel/syscall.c       Â|  25 ---------
> Âinclude/linux/syscalls.h         Â|  Â4 ++
> Âmm/util.c                 |  29 ++++++++++
> Â46 files changed, 105 insertions(+), 903 deletions(-)
>

> diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
> index 7deb402..fdab0f0 100644
> --- a/arch/m68k/kernel/sys_m68k.c
> +++ b/arch/m68k/kernel/sys_m68k.c
> @@ -29,37 +29,12 @@
> Â#include <asm/page.h>
> Â#include <asm/unistd.h>
>
> -/* common code for old and new mmaps */
> -static inline long do_mmap2(
> - Â Â Â unsigned long addr, unsigned long len,
> - Â Â Â unsigned long prot, unsigned long flags,
> - Â Â Â unsigned long fd, unsigned long pgoff)
> -{
> - Â Â Â int error = -EBADF;
> - Â Â Â struct file * file = NULL;
> -
> - Â Â Â flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
> - Â Â Â if (!(flags & MAP_ANONYMOUS)) {
> - Â Â Â Â Â Â Â file = fget(fd);
> - Â Â Â Â Â Â Â if (!file)
> - Â Â Â Â Â Â Â Â Â Â Â goto out;
> - Â Â Â }
> -
> - Â Â Â down_write(&current->mm->mmap_sem);
> - Â Â Â error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
> - Â Â Â up_write(&current->mm->mmap_sem);
> -
> - Â Â Â if (file)
> - Â Â Â Â Â Â Â fput(file);
> -out:
> - Â Â Â return error;
> -}
> -
> Âasmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
> Â Â Â Âunsigned long prot, unsigned long flags,
> Â Â Â Âunsigned long fd, unsigned long pgoff)
> Â{
> - Â Â Â return do_mmap2(addr, len, prot, flags, fd, pgoff);
> + Â Â Â /* this is wrong for sun3, BTW */

Can you please add the why part to the comment?
Thanks!

> + Â Â Â return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
> Â}
>
> Â/*
> @@ -90,57 +65,11 @@ asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
> Â Â Â Âif (a.offset & ~PAGE_MASK)
> Â Â Â Â Â Â Â Âgoto out;
>
> - Â Â Â a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
> -
> - Â Â Â error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
> -out:
> - Â Â Â return error;
> -}
> -
> -#if 0
> -struct mmap_arg_struct64 {
> - Â Â Â __u32 addr;
> - Â Â Â __u32 len;
> - Â Â Â __u32 prot;
> - Â Â Â __u32 flags;
> - Â Â Â __u64 offset; /* 64 bits */
> - Â Â Â __u32 fd;
> -};
> -
> -asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
> -{
> - Â Â Â int error = -EFAULT;
> - Â Â Â struct file * file = NULL;
> - Â Â Â struct mmap_arg_struct64 a;
> - Â Â Â unsigned long pgoff;
> -
> - Â Â Â if (copy_from_user(&a, arg, sizeof(a)))
> - Â Â Â Â Â Â Â return -EFAULT;
> -
> - Â Â Â if ((long)a.offset & ~PAGE_MASK)
> - Â Â Â Â Â Â Â return -EINVAL;
> -
> - Â Â Â pgoff = a.offset >> PAGE_SHIFT;
> - Â Â Â if ((a.offset >> PAGE_SHIFT) != pgoff)
> - Â Â Â Â Â Â Â return -EINVAL;
> -
> - Â Â Â if (!(a.flags & MAP_ANONYMOUS)) {
> - Â Â Â Â Â Â Â error = -EBADF;
> - Â Â Â Â Â Â Â file = fget(a.fd);
> - Â Â Â Â Â Â Â if (!file)
> - Â Â Â Â Â Â Â Â Â Â Â goto out;
> - Â Â Â }
> - Â Â Â a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
> -
> - Â Â Â down_write(&current->mm->mmap_sem);
> - Â Â Â error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
> - Â Â Â up_write(&current->mm->mmap_sem);
> - Â Â Â if (file)
> - Â Â Â Â Â Â Â fput(file);
> + Â Â Â error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âa.offset >> PAGE_SHIFT);
> Âout:
> Â Â Â Âreturn error;
> Â}
> -#endif
>
> Âstruct sel_arg_struct {
> Â Â Â Âunsigned long n;

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
¢éì®&Þ~º&¶¬–+-±éÝ¥Šw®žË±Êâmébžìdz¹Þ)í…æèw*jg¬±¨¶‰šŽŠÝj/êäz¹ÞŠà2ŠÞ¨è­Ú&¢)ß«a¶Úþø®G«éh®æj:+v‰¨Šwè†Ù>Wš±êÞiÛaxPjØm¶Ÿÿà -»+ƒùdš_