Unify sys_mmap*

New helper - sys_mmap_pgoff(); switch syscalls to using it.

Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2009-11-30 17:37:04 -05:00
parent 0067bd8a55
commit f8b7256096
46 changed files with 109 additions and 907 deletions

View File

@ -178,25 +178,18 @@ SYSCALL_DEFINE6(osf_mmap, unsigned long, addr, unsigned long, len,
unsigned long, prot, unsigned long, flags, unsigned long, fd, unsigned long, prot, unsigned long, flags, unsigned long, fd,
unsigned long, off) unsigned long, off)
{ {
struct file *file = NULL; unsigned long ret = -EINVAL;
unsigned long ret = -EBADF;
#if 0 #if 0
if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED)) if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED))
printk("%s: unimplemented OSF mmap flags %04lx\n", printk("%s: unimplemented OSF mmap flags %04lx\n",
current->comm, flags); current->comm, flags);
#endif #endif
if (!(flags & MAP_ANONYMOUS)) { if ((off + PAGE_ALIGN(len)) < off)
file = fget(fd);
if (!file)
goto out; goto out;
} if (off & ~PAGE_MASK)
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); goto out;
down_write(&current->mm->mmap_sem); ret = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
ret = do_mmap(file, addr, len, prot, flags, off);
up_write(&current->mm->mmap_sem);
if (file)
fput(file);
out: out:
return ret; return ret;
} }

View File

@ -416,12 +416,12 @@ sys_mmap2:
tst r5, #PGOFF_MASK tst r5, #PGOFF_MASK
moveq r5, r5, lsr #PAGE_SHIFT - 12 moveq r5, r5, lsr #PAGE_SHIFT - 12
streq r5, [sp, #4] streq r5, [sp, #4]
beq do_mmap2 beq sys_mmap_pgoff
mov r0, #-EINVAL mov r0, #-EINVAL
mov pc, lr mov pc, lr
#else #else
str r5, [sp, #4] str r5, [sp, #4]
b do_mmap2 b sys_mmap_pgoff
#endif #endif
ENDPROC(sys_mmap2) ENDPROC(sys_mmap2)

View File

@ -28,34 +28,6 @@
#include <linux/ipc.h> #include <linux/ipc.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
/* common code for old and new mmaps */
inline long do_mmap2(
unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
{
int error = -EINVAL;
struct file * file = NULL;
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
error = -EBADF;
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;
}
struct mmap_arg_struct { struct mmap_arg_struct {
unsigned long addr; unsigned long addr;
unsigned long len; unsigned long len;
@ -77,7 +49,7 @@ asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
if (a.offset & ~PAGE_MASK) if (a.offset & ~PAGE_MASK)
goto out; goto out;
error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
out: out:
return error; return error;
} }

View File

@ -29,10 +29,6 @@ asmlinkage int sys_sigaltstack(const stack_t __user *, stack_t __user *,
struct pt_regs *); struct pt_regs *);
asmlinkage int sys_rt_sigreturn(struct pt_regs *); asmlinkage int sys_rt_sigreturn(struct pt_regs *);
/* kernel/sys_avr32.c */
asmlinkage long sys_mmap2(unsigned long, unsigned long, unsigned long,
unsigned long, unsigned long, off_t);
/* mm/cache.c */ /* mm/cache.c */
asmlinkage int sys_cacheflush(int, void __user *, size_t); asmlinkage int sys_cacheflush(int, void __user *, size_t);

View File

@ -5,39 +5,8 @@
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
*/ */
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/mm.h>
#include <linux/unistd.h> #include <linux/unistd.h>
#include <asm/mman.h>
#include <asm/uaccess.h>
#include <asm/syscalls.h>
asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, off_t offset)
{
int error = -EBADF;
struct file *file = NULL;
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
if (!(flags & MAP_ANONYMOUS)) {
file = fget(fd);
if (!file)
return error;
}
down_write(&current->mm->mmap_sem);
error = do_mmap_pgoff(file, addr, len, prot, flags, offset);
up_write(&current->mm->mmap_sem);
if (file)
fput(file);
return error;
}
int kernel_execve(const char *file, char **argv, char **envp) int kernel_execve(const char *file, char **argv, char **envp)
{ {
register long scno asm("r8") = __NR_execve; register long scno asm("r8") = __NR_execve;

View File

@ -61,7 +61,7 @@ __sys_execve:
__sys_mmap2: __sys_mmap2:
pushm lr pushm lr
st.w --sp, ARG6 st.w --sp, ARG6
call sys_mmap2 call sys_mmap_pgoff
sub sp, -4 sub sp, -4
popm pc popm pc

View File

@ -22,39 +22,6 @@
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/dma.h> #include <asm/dma.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);
}
asmlinkage void *sys_sram_alloc(size_t size, unsigned long flags) asmlinkage void *sys_sram_alloc(size_t size, unsigned long flags)
{ {
return sram_alloc_with_lsl(size, flags); return sram_alloc_with_lsl(size, flags);

View File

@ -1422,7 +1422,7 @@ ENTRY(_sys_call_table)
.long _sys_ni_syscall /* streams2 */ .long _sys_ni_syscall /* streams2 */
.long _sys_vfork /* 190 */ .long _sys_vfork /* 190 */
.long _sys_getrlimit .long _sys_getrlimit
.long _sys_mmap2 .long _sys_mmap_pgoff
.long _sys_truncate64 .long _sys_truncate64
.long _sys_ftruncate64 .long _sys_ftruncate64
.long _sys_stat64 /* 195 */ .long _sys_stat64 /* 195 */

View File

@ -26,31 +26,6 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/segment.h> #include <asm/segment.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 unsigned long old_mmap(unsigned long __user *args) asmlinkage unsigned long old_mmap(unsigned long __user *args)
{ {
unsigned long buffer[6]; unsigned long buffer[6];
@ -63,7 +38,7 @@ asmlinkage unsigned long old_mmap(unsigned long __user *args)
if (buffer[5] & ~PAGE_MASK) /* verify that offset is on page boundary */ if (buffer[5] & ~PAGE_MASK) /* verify that offset is on page boundary */
goto out; goto out;
err = do_mmap2(buffer[0], buffer[1], buffer[2], buffer[3], err = sys_mmap_pgoff(buffer[0], buffer[1], buffer[2], buffer[3],
buffer[4], buffer[5] >> PAGE_SHIFT); buffer[4], buffer[5] >> PAGE_SHIFT);
out: out:
return err; return err;
@ -73,7 +48,8 @@ asmlinkage long
sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
unsigned long flags, unsigned long fd, unsigned long pgoff) unsigned long flags, unsigned long fd, unsigned long pgoff)
{ {
return do_mmap2(addr, len, prot, flags, fd, pgoff); /* bug(?): 8Kb pages here */
return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
} }
/* /*

View File

@ -31,9 +31,6 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff) unsigned long fd, unsigned long pgoff)
{ {
int error = -EBADF;
struct file * file = NULL;
/* As with sparc32, make sure the shift for mmap2 is constant /* As with sparc32, make sure the shift for mmap2 is constant
(12), no matter what PAGE_SIZE we have.... */ (12), no matter what PAGE_SIZE we have.... */
@ -41,70 +38,11 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
trying to map something we can't */ trying to map something we can't */
if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1)) if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1))
return -EINVAL; return -EINVAL;
pgoff >>= PAGE_SHIFT - 12;
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); return sys_mmap_pgoff(addr, len, prot, flags, fd,
if (!(flags & MAP_ANONYMOUS)) { pgoff >> (PAGE_SHIFT - 12));
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;
}
#if 0 /* DAVIDM - do we want this */
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);
out:
return error;
}
#endif
/* /*
* sys_ipc() is the de-multiplexer for the SysV IPC calls.. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
* *

View File

@ -26,39 +26,6 @@
#include <asm/traps.h> #include <asm/traps.h>
#include <asm/unistd.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);
}
/* /*
* Perform the select(nd, in, out, ex, tv) and mmap() system * Perform the select(nd, in, out, ex, tv) and mmap() system
* calls. Linux/m68k cloned Linux/i386, which didn't use to be able to * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
@ -87,58 +54,12 @@ asmlinkage int old_mmap(struct mmap_arg_struct *arg)
if (a.offset & ~PAGE_MASK) if (a.offset & ~PAGE_MASK)
goto out; goto out;
a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
a.offset >> PAGE_SHIFT);
error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
out: out:
return error; return error;
} }
#if 0 /* DAVIDM - do we want this */
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);
out:
return error;
}
#endif
struct sel_arg_struct { struct sel_arg_struct {
unsigned long n; unsigned long n;
fd_set *inp, *outp, *exp; fd_set *inp, *outp, *exp;

View File

@ -206,7 +206,7 @@ SYMBOL_NAME_LABEL(sys_call_table)
.long SYMBOL_NAME(sys_ni_syscall) /* streams2 */ .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */
.long SYMBOL_NAME(sys_vfork) /* 190 */ .long SYMBOL_NAME(sys_vfork) /* 190 */
.long SYMBOL_NAME(sys_getrlimit) .long SYMBOL_NAME(sys_getrlimit)
.long SYMBOL_NAME(sys_mmap2) .long SYMBOL_NAME(sys_mmap_pgoff)
.long SYMBOL_NAME(sys_truncate64) .long SYMBOL_NAME(sys_truncate64)
.long SYMBOL_NAME(sys_ftruncate64) .long SYMBOL_NAME(sys_ftruncate64)
.long SYMBOL_NAME(sys_stat64) /* 195 */ .long SYMBOL_NAME(sys_stat64) /* 195 */

View File

@ -185,39 +185,6 @@ int ia64_mmap_check(unsigned long addr, unsigned long len,
return 0; return 0;
} }
static inline unsigned long
do_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, unsigned long pgoff)
{
struct file *file = NULL;
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
if (!(flags & MAP_ANONYMOUS)) {
file = fget(fd);
if (!file)
return -EBADF;
if (!file->f_op || !file->f_op->mmap) {
addr = -ENODEV;
goto out;
}
}
/* Careful about overflows.. */
len = PAGE_ALIGN(len);
if (!len || len > TASK_SIZE) {
addr = -EINVAL;
goto out;
}
down_write(&current->mm->mmap_sem);
addr = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
up_write(&current->mm->mmap_sem);
out: if (file)
fput(file);
return addr;
}
/* /*
* mmap2() is like mmap() except that the offset is expressed in units * mmap2() is like mmap() except that the offset is expressed in units
* of PAGE_SIZE (instead of bytes). This allows to mmap2() (pieces * of PAGE_SIZE (instead of bytes). This allows to mmap2() (pieces
@ -226,7 +193,7 @@ out: if (file)
asmlinkage unsigned long asmlinkage unsigned long
sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff) sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff)
{ {
addr = do_mmap2(addr, len, prot, flags, fd, pgoff); addr = sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
if (!IS_ERR((void *) addr)) if (!IS_ERR((void *) addr))
force_successful_syscall_return(); force_successful_syscall_return();
return addr; return addr;
@ -238,7 +205,7 @@ sys_mmap (unsigned long addr, unsigned long len, int prot, int flags, int fd, lo
if (offset_in_page(off) != 0) if (offset_in_page(off) != 0)
return -EINVAL; return -EINVAL;
addr = do_mmap2(addr, len, prot, flags, fd, off >> PAGE_SHIFT); addr = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
if (!IS_ERR((void *) addr)) if (!IS_ERR((void *) addr))
force_successful_syscall_return(); force_successful_syscall_return();
return addr; return addr;

View File

@ -76,30 +76,6 @@ asmlinkage int sys_tas(int __user *addr)
return oldval; return oldval;
} }
asmlinkage long sys_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;
}
/* /*
* sys_ipc() is the de-multiplexer for the SysV IPC calls.. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
* *

View File

@ -191,7 +191,7 @@ ENTRY(sys_call_table)
.long sys_ni_syscall /* streams2 */ .long sys_ni_syscall /* streams2 */
.long sys_vfork /* 190 */ .long sys_vfork /* 190 */
.long sys_getrlimit .long sys_getrlimit
.long sys_mmap2 .long sys_mmap_pgoff
.long sys_truncate64 .long sys_truncate64
.long sys_ftruncate64 .long sys_ftruncate64
.long sys_stat64 /* 195 */ .long sys_stat64 /* 195 */

View File

@ -29,37 +29,16 @@
#include <asm/page.h> #include <asm/page.h>
#include <asm/unistd.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, asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff) unsigned long fd, unsigned long pgoff)
{ {
return do_mmap2(addr, len, prot, flags, fd, pgoff); /*
* This is wrong for sun3 - there PAGE_SIZE is 8Kb,
* so we need to shift the argument down by 1; m68k mmap64(3)
* (in libc) expects the last argument of mmap2 in 4Kb units.
*/
return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
} }
/* /*
@ -90,58 +69,12 @@ asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
if (a.offset & ~PAGE_MASK) if (a.offset & ~PAGE_MASK)
goto out; goto out;
a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
a.offset >> PAGE_SHIFT);
error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
out: out:
return error; 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);
out:
return error;
}
#endif
struct sel_arg_struct { struct sel_arg_struct {
unsigned long n; unsigned long n;
fd_set __user *inp, *outp, *exp; fd_set __user *inp, *outp, *exp;

View File

@ -27,39 +27,6 @@
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/unistd.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);
}
/* /*
* Perform the select(nd, in, out, ex, tv) and mmap() system * Perform the select(nd, in, out, ex, tv) and mmap() system
* calls. Linux/m68k cloned Linux/i386, which didn't use to be able to * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to
@ -88,9 +55,8 @@ asmlinkage int old_mmap(struct mmap_arg_struct *arg)
if (a.offset & ~PAGE_MASK) if (a.offset & ~PAGE_MASK)
goto out; goto out;
a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
a.offset >> PAGE_SHIFT);
error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
out: out:
return error; return error;
} }

View File

@ -210,7 +210,7 @@ ENTRY(sys_call_table)
.long sys_ni_syscall /* streams2 */ .long sys_ni_syscall /* streams2 */
.long sys_vfork /* 190 */ .long sys_vfork /* 190 */
.long sys_getrlimit .long sys_getrlimit
.long sys_mmap2 .long sys_mmap_pgoff
.long sys_truncate64 .long sys_truncate64
.long sys_ftruncate64 .long sys_ftruncate64
.long sys_stat64 /* 195 */ .long sys_stat64 /* 195 */

View File

@ -62,46 +62,14 @@ out:
return error; return error;
} }
asmlinkage long
sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
{
struct file *file = NULL;
int ret = -EBADF;
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
if (!(flags & MAP_ANONYMOUS)) {
file = fget(fd);
if (!file) {
printk(KERN_INFO "no fd in mmap\r\n");
goto out;
}
}
down_write(&current->mm->mmap_sem);
ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
up_write(&current->mm->mmap_sem);
if (file)
fput(file);
out:
return ret;
}
asmlinkage long sys_mmap(unsigned long addr, unsigned long len, asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long prot, unsigned long flags,
unsigned long fd, off_t pgoff) unsigned long fd, off_t pgoff)
{ {
int err = -EINVAL; if (pgoff & ~PAGE_MASK)
return -EINVAL;
if (pgoff & ~PAGE_MASK) { return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
printk(KERN_INFO "no pagemask in mmap\r\n");
goto out;
}
err = sys_mmap2(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
out:
return err;
} }
/* /*

View File

@ -196,7 +196,7 @@ ENTRY(sys_call_table)
.long sys_ni_syscall /* reserved for streams2 */ .long sys_ni_syscall /* reserved for streams2 */
.long sys_vfork /* 190 */ .long sys_vfork /* 190 */
.long sys_getrlimit .long sys_getrlimit
.long sys_mmap2 /* mmap2 */ .long sys_mmap_pgoff /* mmap2 */
.long sys_truncate64 .long sys_truncate64
.long sys_ftruncate64 .long sys_ftruncate64
.long sys_stat64 /* 195 */ .long sys_stat64 /* 195 */

View File

@ -67,28 +67,13 @@ SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len,
unsigned long, prot, unsigned long, flags, unsigned long, fd, unsigned long, prot, unsigned long, flags, unsigned long, fd,
unsigned long, pgoff) unsigned long, pgoff)
{ {
struct file * file = NULL;
unsigned long error; unsigned long error;
error = -EINVAL; error = -EINVAL;
if (pgoff & (~PAGE_MASK >> 12)) if (pgoff & (~PAGE_MASK >> 12))
goto out; goto out;
pgoff >>= PAGE_SHIFT-12; error = sys_mmap_pgoff(addr, len, prot, flags, fd,
pgoff >> (PAGE_SHIFT-12));
if (!(flags & MAP_ANONYMOUS)) {
error = -EBADF;
file = fget(fd);
if (!file)
goto out;
}
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
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: out:
return error; return error;
} }

View File

@ -129,31 +129,6 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
} }
} }
/* common code for old and new mmaps */
static inline unsigned long
do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
unsigned long flags, unsigned long fd, unsigned long pgoff)
{
unsigned long 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;
}
SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
unsigned long, prot, unsigned long, flags, unsigned long, unsigned long, prot, unsigned long, flags, unsigned long,
fd, off_t, offset) fd, off_t, offset)
@ -164,7 +139,7 @@ SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
if (offset & ~PAGE_MASK) if (offset & ~PAGE_MASK)
goto out; goto out;
result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); result = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
out: out:
return result; return result;
@ -177,7 +152,7 @@ SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
if (pgoff & (~PAGE_MASK >> 12)) if (pgoff & (~PAGE_MASK >> 12))
return -EINVAL; return -EINVAL;
return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12)); return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
} }
save_static_function(sys_fork); save_static_function(sys_fork);

View File

@ -578,7 +578,7 @@ ENTRY(sys_call_table)
.long sys_ni_syscall /* reserved for streams2 */ .long sys_ni_syscall /* reserved for streams2 */
.long sys_vfork /* 190 */ .long sys_vfork /* 190 */
.long sys_getrlimit .long sys_getrlimit
.long sys_mmap2 .long sys_mmap_pgoff
.long sys_truncate64 .long sys_truncate64
.long sys_ftruncate64 .long sys_ftruncate64
.long sys_stat64 /* 195 */ .long sys_stat64 /* 195 */

View File

@ -23,42 +23,13 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
/*
* memory mapping syscall
*/
asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
{
struct file *file = NULL;
long error = -EINVAL;
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
error = -EBADF;
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 old_mmap(unsigned long addr, unsigned long len, asmlinkage long old_mmap(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long offset) unsigned long fd, unsigned long offset)
{ {
if (offset & ~PAGE_MASK) if (offset & ~PAGE_MASK)
return -EINVAL; return -EINVAL;
return sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
} }
struct sel_arg_struct { struct sel_arg_struct {

View File

@ -110,37 +110,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
return addr; return addr;
} }
static unsigned long do_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long fd,
unsigned long pgoff)
{
struct file * file = NULL;
unsigned long error = -EBADF;
if (!(flags & MAP_ANONYMOUS)) {
file = fget(fd);
if (!file)
goto out;
}
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
down_write(&current->mm->mmap_sem);
error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
up_write(&current->mm->mmap_sem);
if (file != NULL)
fput(file);
out:
return error;
}
asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long fd, unsigned long prot, unsigned long flags, unsigned long fd,
unsigned long pgoff) unsigned long pgoff)
{ {
/* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
we have. */ we have. */
return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT - 12)); return sys_mmap_pgoff(addr, len, prot, flags, fd,
pgoff >> (PAGE_SHIFT - 12));
} }
asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
@ -148,7 +125,8 @@ asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
unsigned long offset) unsigned long offset)
{ {
if (!(offset & ~PAGE_MASK)) { if (!(offset & ~PAGE_MASK)) {
return do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); return sys_mmap_pgoff(addr, len, prot, flags, fd,
offset >> PAGE_SHIFT);
} else { } else {
return -EINVAL; return -EINVAL;
} }

View File

@ -140,7 +140,6 @@ static inline unsigned long do_mmap2(unsigned long addr, size_t len,
unsigned long prot, unsigned long flags, unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long off, int shift) unsigned long fd, unsigned long off, int shift)
{ {
struct file * file = NULL;
unsigned long ret = -EINVAL; unsigned long ret = -EINVAL;
if (!arch_validate_prot(prot)) if (!arch_validate_prot(prot))
@ -152,19 +151,7 @@ static inline unsigned long do_mmap2(unsigned long addr, size_t len,
off >>= shift; off >>= shift;
} }
ret = -EBADF; ret = sys_mmap_pgoff(addr, len, prot, flags, fd, off);
if (!(flags & MAP_ANONYMOUS)) {
if (!(file = fget(fd)))
goto out;
}
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
down_write(&current->mm->mmap_sem);
ret = do_mmap_pgoff(file, addr, len, prot, flags, off);
up_write(&current->mm->mmap_sem);
if (file)
fput(file);
out: out:
return ret; return ret;
} }

View File

@ -624,33 +624,6 @@ struct mmap_arg_struct_emu31 {
u32 offset; u32 offset;
}; };
/* 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)
{
struct file * file = NULL;
unsigned long error = -EBADF;
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 unsigned long asmlinkage unsigned long
old32_mmap(struct mmap_arg_struct_emu31 __user *arg) old32_mmap(struct mmap_arg_struct_emu31 __user *arg)
{ {
@ -664,7 +637,8 @@ old32_mmap(struct mmap_arg_struct_emu31 __user *arg)
if (a.offset & ~PAGE_MASK) if (a.offset & ~PAGE_MASK)
goto out; goto out;
error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
a.offset >> PAGE_SHIFT);
out: out:
return error; return error;
} }
@ -677,7 +651,7 @@ sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg)
if (copy_from_user(&a, arg, sizeof(a))) if (copy_from_user(&a, arg, sizeof(a)))
goto out; goto out;
error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
out: out:
return error; return error;
} }

View File

@ -32,32 +32,6 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include "entry.h" #include "entry.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)
{
long 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;
}
/* /*
* Perform the select(nd, in, out, ex, tv) and mmap() system * Perform the select(nd, in, out, ex, tv) and mmap() system
* calls. Linux for S/390 isn't able to handle more than 5 * calls. Linux for S/390 isn't able to handle more than 5
@ -81,7 +55,7 @@ SYSCALL_DEFINE1(mmap2, struct mmap_arg_struct __user *, arg)
if (copy_from_user(&a, arg, sizeof(a))) if (copy_from_user(&a, arg, sizeof(a)))
goto out; goto out;
error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
out: out:
return error; return error;
} }
@ -98,7 +72,7 @@ SYSCALL_DEFINE1(s390_old_mmap, struct mmap_arg_struct __user *, arg)
if (a.offset & ~PAGE_MASK) if (a.offset & ~PAGE_MASK)
goto out; goto out;
error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
out: out:
return error; return error;
} }

View File

@ -36,34 +36,15 @@ asmlinkage long
sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
unsigned long flags, unsigned long fd, unsigned long pgoff) unsigned long flags, unsigned long fd, unsigned long pgoff)
{ {
int error = -EBADF; return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
struct file *file = NULL;
if (pgoff & (~PAGE_MASK >> 12))
return -EINVAL;
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
if (!(flags & MAP_ANONYMOUS)) {
file = fget(fd);
if (!file)
return error;
}
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);
return error;
} }
asmlinkage long asmlinkage long
sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, sys_mmap(unsigned long addr, unsigned long len, unsigned long prot,
unsigned long flags, unsigned long fd, off_t pgoff) unsigned long flags, unsigned long fd, off_t pgoff)
{ {
return sys_mmap2(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT); /* where's the alignment check? */
return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
} }
asmlinkage long asmlinkage long

View File

@ -28,37 +28,13 @@
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/cachectl.h> #include <asm/cachectl.h>
static inline long
do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
unsigned long flags, int 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 int old_mmap(unsigned long addr, unsigned long len, asmlinkage int old_mmap(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long prot, unsigned long flags,
int fd, unsigned long off) int fd, unsigned long off)
{ {
if (off & ~PAGE_MASK) if (off & ~PAGE_MASK)
return -EINVAL; return -EINVAL;
return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT); return sys_mmap_pgoff(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
} }
asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
@ -74,7 +50,7 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
pgoff >>= PAGE_SHIFT - 12; pgoff >>= PAGE_SHIFT - 12;
return do_mmap2(addr, len, prot, flags, fd, pgoff); return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
} }
/* /*

View File

@ -234,31 +234,6 @@ int sparc_mmap_check(unsigned long addr, unsigned long len)
} }
/* Linux version of mmap */ /* Linux version of mmap */
static unsigned long do_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long fd,
unsigned long pgoff)
{
struct file * file = NULL;
unsigned long retval = -EBADF;
if (!(flags & MAP_ANONYMOUS)) {
file = fget(fd);
if (!file)
goto out;
}
len = PAGE_ALIGN(len);
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
down_write(&current->mm->mmap_sem);
retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
up_write(&current->mm->mmap_sem);
if (file)
fput(file);
out:
return retval;
}
asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long fd, unsigned long prot, unsigned long flags, unsigned long fd,
@ -266,14 +241,16 @@ asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
{ {
/* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
we have. */ we have. */
return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT - 12)); return sys_mmap_pgoff(addr, len, prot, flags, fd,
pgoff >> (PAGE_SHIFT - 12));
} }
asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long fd, unsigned long prot, unsigned long flags, unsigned long fd,
unsigned long off) unsigned long off)
{ {
return do_mmap2(addr, len, prot, flags, fd, off >> PAGE_SHIFT); /* no alignment check? */
return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
} }
long sparc_remap_file_pages(unsigned long start, unsigned long size, long sparc_remap_file_pages(unsigned long start, unsigned long size,

View File

@ -572,23 +572,13 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
unsigned long, prot, unsigned long, flags, unsigned long, fd, unsigned long, prot, unsigned long, flags, unsigned long, fd,
unsigned long, off) unsigned long, off)
{ {
struct file * file = NULL; unsigned long retval = -EINVAL;
unsigned long retval = -EBADF;
if (!(flags & MAP_ANONYMOUS)) { if ((off + PAGE_ALIGN(len)) < off)
file = fget(fd);
if (!file)
goto out; goto out;
} if (off & ~PAGE_MASK)
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); goto out;
len = PAGE_ALIGN(len); retval = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
down_write(&current->mm->mmap_sem);
retval = do_mmap(file, addr, len, prot, flags, off);
up_write(&current->mm->mmap_sem);
if (file)
fput(file);
out: out:
return retval; return retval;
} }

View File

@ -8,6 +8,7 @@
#include "linux/mm.h" #include "linux/mm.h"
#include "linux/sched.h" #include "linux/sched.h"
#include "linux/utsname.h" #include "linux/utsname.h"
#include "linux/syscalls.h"
#include "asm/current.h" #include "asm/current.h"
#include "asm/mman.h" #include "asm/mman.h"
#include "asm/uaccess.h" #include "asm/uaccess.h"
@ -37,31 +38,6 @@ long sys_vfork(void)
return ret; return ret;
} }
/* common code for old and new mmaps */
long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
{
long 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;
}
long old_mmap(unsigned long addr, unsigned long len, long old_mmap(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags, unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long offset) unsigned long fd, unsigned long offset)
@ -70,7 +46,7 @@ long old_mmap(unsigned long addr, unsigned long len,
if (offset & ~PAGE_MASK) if (offset & ~PAGE_MASK)
goto out; goto out;
err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); err = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
out: out:
return err; return err;
} }

View File

@ -20,7 +20,3 @@ extern syscall_handler_t *sys_call_table[];
#define EXECUTE_SYSCALL(syscall, regs) \ #define EXECUTE_SYSCALL(syscall, regs) \
((long (*)(struct syscall_args)) \ ((long (*)(struct syscall_args)) \
(*sys_call_table[syscall]))(SYSCALL_ARGS(&regs->regs)) (*sys_call_table[syscall]))(SYSCALL_ARGS(&regs->regs))
extern long sys_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff);

View File

@ -696,7 +696,7 @@ ia32_sys_call_table:
.quad quiet_ni_syscall /* streams2 */ .quad quiet_ni_syscall /* streams2 */
.quad stub32_vfork /* 190 */ .quad stub32_vfork /* 190 */
.quad compat_sys_getrlimit .quad compat_sys_getrlimit
.quad sys32_mmap2 .quad sys_mmap_pgoff
.quad sys32_truncate64 .quad sys32_truncate64
.quad sys32_ftruncate64 .quad sys32_ftruncate64
.quad sys32_stat64 /* 195 */ .quad sys32_stat64 /* 195 */

View File

@ -155,9 +155,6 @@ struct mmap_arg_struct {
asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg) asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg)
{ {
struct mmap_arg_struct a; struct mmap_arg_struct a;
struct file *file = NULL;
unsigned long retval;
struct mm_struct *mm ;
if (copy_from_user(&a, arg, sizeof(a))) if (copy_from_user(&a, arg, sizeof(a)))
return -EFAULT; return -EFAULT;
@ -165,22 +162,8 @@ asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg)
if (a.offset & ~PAGE_MASK) if (a.offset & ~PAGE_MASK)
return -EINVAL; return -EINVAL;
if (!(a.flags & MAP_ANONYMOUS)) { return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
file = fget(a.fd);
if (!file)
return -EBADF;
}
mm = current->mm;
down_write(&mm->mmap_sem);
retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags,
a.offset>>PAGE_SHIFT); a.offset>>PAGE_SHIFT);
if (file)
fput(file);
up_write(&mm->mmap_sem);
return retval;
} }
asmlinkage long sys32_mprotect(unsigned long start, size_t len, asmlinkage long sys32_mprotect(unsigned long start, size_t len,
@ -483,30 +466,6 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
return ret; return ret;
} }
asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff)
{
struct mm_struct *mm = current->mm;
unsigned long error;
struct file *file = NULL;
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
if (!(flags & MAP_ANONYMOUS)) {
file = fget(fd);
if (!file)
return -EBADF;
}
down_write(&mm->mmap_sem);
error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
up_write(&mm->mmap_sem);
if (file)
fput(file);
return error;
}
asmlinkage long sys32_olduname(struct oldold_utsname __user *name) asmlinkage long sys32_olduname(struct oldold_utsname __user *name)
{ {
char *arch = "x86_64"; char *arch = "x86_64";

View File

@ -57,9 +57,6 @@ asmlinkage long sys32_pwrite(unsigned int, char __user *, u32, u32, u32);
asmlinkage long sys32_personality(unsigned long); asmlinkage long sys32_personality(unsigned long);
asmlinkage long sys32_sendfile(int, int, compat_off_t __user *, s32); asmlinkage long sys32_sendfile(int, int, compat_off_t __user *, s32);
asmlinkage long sys32_mmap2(unsigned long, unsigned long, unsigned long,
unsigned long, unsigned long, unsigned long);
struct oldold_utsname; struct oldold_utsname;
struct old_utsname; struct old_utsname;
asmlinkage long sys32_olduname(struct oldold_utsname __user *); asmlinkage long sys32_olduname(struct oldold_utsname __user *);

View File

@ -55,8 +55,6 @@ struct sel_arg_struct;
struct oldold_utsname; struct oldold_utsname;
struct old_utsname; struct old_utsname;
asmlinkage long sys_mmap2(unsigned long, unsigned long, unsigned long,
unsigned long, unsigned long, unsigned long);
asmlinkage int old_mmap(struct mmap_arg_struct __user *); asmlinkage int old_mmap(struct mmap_arg_struct __user *);
asmlinkage int old_select(struct sel_arg_struct __user *); asmlinkage int old_select(struct sel_arg_struct __user *);
asmlinkage int sys_ipc(uint, int, int, int, void __user *, long); asmlinkage int sys_ipc(uint, int, int, int, void __user *, long);

View File

@ -24,31 +24,6 @@
#include <asm/syscalls.h> #include <asm/syscalls.h>
asmlinkage long sys_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;
struct mm_struct *mm = current->mm;
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
if (!(flags & MAP_ANONYMOUS)) {
file = fget(fd);
if (!file)
goto out;
}
down_write(&mm->mmap_sem);
error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
up_write(&mm->mmap_sem);
if (file)
fput(file);
out:
return error;
}
/* /*
* Perform the select(nd, in, out, ex, tv) and mmap() system * Perform the select(nd, in, out, ex, tv) and mmap() system
* calls. Linux/i386 didn't use to be able to handle more than * calls. Linux/i386 didn't use to be able to handle more than
@ -77,7 +52,7 @@ asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
if (a.offset & ~PAGE_MASK) if (a.offset & ~PAGE_MASK)
goto out; goto out;
err = sys_mmap2(a.addr, a.len, a.prot, a.flags, err = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags,
a.fd, a.offset >> PAGE_SHIFT); a.fd, a.offset >> PAGE_SHIFT);
out: out:
return err; return err;

View File

@ -23,26 +23,11 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
unsigned long, fd, unsigned long, off) unsigned long, fd, unsigned long, off)
{ {
long error; long error;
struct file *file;
error = -EINVAL; error = -EINVAL;
if (off & ~PAGE_MASK) if (off & ~PAGE_MASK)
goto out; goto out;
error = -EBADF; error = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
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, off >> PAGE_SHIFT);
up_write(&current->mm->mmap_sem);
if (file)
fput(file);
out: out:
return error; return error;
} }

View File

@ -191,7 +191,7 @@ ENTRY(sys_call_table)
.long sys_ni_syscall /* reserved for streams2 */ .long sys_ni_syscall /* reserved for streams2 */
.long ptregs_vfork /* 190 */ .long ptregs_vfork /* 190 */
.long sys_getrlimit .long sys_getrlimit
.long sys_mmap2 .long sys_mmap_pgoff
.long sys_truncate64 .long sys_truncate64
.long sys_ftruncate64 .long sys_ftruncate64
.long sys_stat64 /* 195 */ .long sys_stat64 /* 195 */

View File

@ -13,8 +13,6 @@ struct sigaction;
asmlinkage long xtensa_execve(char*, char**, char**, struct pt_regs*); asmlinkage long xtensa_execve(char*, char**, char**, struct pt_regs*);
asmlinkage long xtensa_clone(unsigned long, unsigned long, struct pt_regs*); asmlinkage long xtensa_clone(unsigned long, unsigned long, struct pt_regs*);
asmlinkage long xtensa_pipe(int __user *); asmlinkage long xtensa_pipe(int __user *);
asmlinkage long xtensa_mmap2(unsigned long, unsigned long, unsigned long,
unsigned long, unsigned long, unsigned long);
asmlinkage long xtensa_ptrace(long, long, long, long); asmlinkage long xtensa_ptrace(long, long, long, long);
asmlinkage long xtensa_sigreturn(struct pt_regs*); asmlinkage long xtensa_sigreturn(struct pt_regs*);
asmlinkage long xtensa_rt_sigreturn(struct pt_regs*); asmlinkage long xtensa_rt_sigreturn(struct pt_regs*);

View File

@ -189,7 +189,7 @@ __SYSCALL( 79, sys_fremovexattr, 2)
/* File Map / Shared Memory Operations */ /* File Map / Shared Memory Operations */
#define __NR_mmap2 80 #define __NR_mmap2 80
__SYSCALL( 80, xtensa_mmap2, 6) __SYSCALL( 80, sys_mmap_pgoff, 6)
#define __NR_munmap 81 #define __NR_munmap 81
__SYSCALL( 81, sys_munmap, 2) __SYSCALL( 81, sys_munmap, 2)
#define __NR_mprotect 82 #define __NR_mprotect 82

View File

@ -57,31 +57,6 @@ asmlinkage long xtensa_pipe(int __user *userfds)
return error; return error;
} }
asmlinkage long xtensa_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 xtensa_shmat(int shmid, char __user *shmaddr, int shmflg) asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
{ {
unsigned long ret; unsigned long ret;

View File

@ -834,4 +834,8 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[]);
asmlinkage long sys_perf_event_open( asmlinkage long sys_perf_event_open(
struct perf_event_attr __user *attr_uptr, struct perf_event_attr __user *attr_uptr,
pid_t pid, int cpu, int group_fd, unsigned long flags); pid_t pid, int cpu, int group_fd, unsigned long flags);
asmlinkage long sys_mmap_pgoff(unsigned long addr, unsigned long len,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoff);
#endif #endif

View File

@ -4,6 +4,10 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/hugetlb.h>
#include <linux/syscalls.h>
#include <linux/mman.h>
#include <linux/file.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#define CREATE_TRACE_POINTS #define CREATE_TRACE_POINTS
@ -268,6 +272,31 @@ int __attribute__((weak)) get_user_pages_fast(unsigned long start,
} }
EXPORT_SYMBOL_GPL(get_user_pages_fast); EXPORT_SYMBOL_GPL(get_user_pages_fast);
SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
unsigned long, prot, unsigned long, flags,
unsigned long, fd, unsigned long, pgoff)
{
struct file * file = NULL;
unsigned long retval = -EBADF;
if (!(flags & MAP_ANONYMOUS)) {
file = fget(fd);
if (!file)
goto out;
}
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
down_write(&current->mm->mmap_sem);
retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
up_write(&current->mm->mmap_sem);
if (file)
fput(file);
out:
return retval;
}
/* Tracepoints definitions. */ /* Tracepoints definitions. */
EXPORT_TRACEPOINT_SYMBOL(kmalloc); EXPORT_TRACEPOINT_SYMBOL(kmalloc);
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);