Skip to content
Snippets Groups Projects
Commit f8b72560 authored by Al Viro's avatar Al Viro
Browse files

Unify sys_mmap*


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

Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 0067bd8a
No related merge requests found
Showing
with 37 additions and 495 deletions
...@@ -178,25 +178,18 @@ SYSCALL_DEFINE6(osf_mmap, unsigned long, addr, unsigned long, len, ...@@ -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); goto out;
if (!file) if (off & ~PAGE_MASK)
goto out; goto out;
} ret = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
down_write(&current->mm->mmap_sem);
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;
} }
......
...@@ -416,12 +416,12 @@ sys_mmap2: ...@@ -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)
......
...@@ -28,34 +28,6 @@ ...@@ -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) ...@@ -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;
} }
......
...@@ -29,10 +29,6 @@ asmlinkage int sys_sigaltstack(const stack_t __user *, stack_t __user *, ...@@ -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);
......
...@@ -5,39 +5,8 @@ ...@@ -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;
......
...@@ -61,7 +61,7 @@ __sys_execve: ...@@ -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
......
...@@ -22,39 +22,6 @@ ...@@ -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);
......
...@@ -1422,7 +1422,7 @@ ENTRY(_sys_call_table) ...@@ -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 */
......
...@@ -26,31 +26,6 @@ ...@@ -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) ...@@ -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 ...@@ -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);
} }
/* /*
......
...@@ -31,9 +31,6 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, ...@@ -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,69 +38,10 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, ...@@ -41,69 +38,10 @@ 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);
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;
}
#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); return sys_mmap_pgoff(addr, len, prot, flags, fd,
error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff); pgoff >> (PAGE_SHIFT - 12));
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..
......
...@@ -26,39 +26,6 @@ ...@@ -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,57 +54,11 @@ asmlinkage int old_mmap(struct mmap_arg_struct *arg) ...@@ -87,57 +54,11 @@ 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:
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: out:
return error; return error;
} }
#endif
struct sel_arg_struct { struct sel_arg_struct {
unsigned long n; unsigned long n;
......
...@@ -206,7 +206,7 @@ SYMBOL_NAME_LABEL(sys_call_table) ...@@ -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 */
......
...@@ -185,39 +185,6 @@ int ia64_mmap_check(unsigned long addr, unsigned long len, ...@@ -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) ...@@ -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 ...@@ -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;
......
...@@ -76,30 +76,6 @@ asmlinkage int sys_tas(int __user *addr) ...@@ -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..
* *
......
...@@ -191,7 +191,7 @@ ENTRY(sys_call_table) ...@@ -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 */
......
...@@ -29,37 +29,16 @@ ...@@ -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,57 +69,11 @@ asmlinkage int old_mmap(struct mmap_arg_struct __user *arg) ...@@ -90,57 +69,11 @@ 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:
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: out:
return error; return error;
} }
#endif
struct sel_arg_struct { struct sel_arg_struct {
unsigned long n; unsigned long n;
......
...@@ -27,39 +27,6 @@ ...@@ -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) ...@@ -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;
} }
......
...@@ -210,7 +210,7 @@ ENTRY(sys_call_table) ...@@ -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 */
......
...@@ -62,46 +62,14 @@ asmlinkage long microblaze_execve(char __user *filenamei, char __user *__user *a ...@@ -62,46 +62,14 @@ asmlinkage long microblaze_execve(char __user *filenamei, char __user *__user *a
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) {
printk(KERN_INFO "no pagemask in mmap\r\n");
goto out;
}
err = sys_mmap2(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT); return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT);
out:
return err;
} }
/* /*
......
...@@ -196,7 +196,7 @@ ENTRY(sys_call_table) ...@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment