diff options
59 files changed, 343 insertions, 1202 deletions
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c index 9a3334ae282e..62619f25132f 100644 --- a/arch/alpha/kernel/osf_sys.c +++ b/arch/alpha/kernel/osf_sys.c | |||
@@ -178,25 +178,18 @@ SYSCALL_DEFINE6(osf_mmap, unsigned long, addr, unsigned long, len, | |||
178 | unsigned long, prot, unsigned long, flags, unsigned long, fd, | 178 | unsigned long, prot, unsigned long, flags, unsigned long, fd, |
179 | unsigned long, off) | 179 | unsigned long, off) |
180 | { | 180 | { |
181 | struct file *file = NULL; | 181 | unsigned long ret = -EINVAL; |
182 | unsigned long ret = -EBADF; | ||
183 | 182 | ||
184 | #if 0 | 183 | #if 0 |
185 | if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED)) | 184 | if (flags & (_MAP_HASSEMAPHORE | _MAP_INHERIT | _MAP_UNALIGNED)) |
186 | printk("%s: unimplemented OSF mmap flags %04lx\n", | 185 | printk("%s: unimplemented OSF mmap flags %04lx\n", |
187 | current->comm, flags); | 186 | current->comm, flags); |
188 | #endif | 187 | #endif |
189 | if (!(flags & MAP_ANONYMOUS)) { | 188 | if ((off + PAGE_ALIGN(len)) < off) |
190 | file = fget(fd); | 189 | goto out; |
191 | if (!file) | 190 | if (off & ~PAGE_MASK) |
192 | goto out; | 191 | goto out; |
193 | } | 192 | ret = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); |
194 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
195 | down_write(¤t->mm->mmap_sem); | ||
196 | ret = do_mmap(file, addr, len, prot, flags, off); | ||
197 | up_write(¤t->mm->mmap_sem); | ||
198 | if (file) | ||
199 | fput(file); | ||
200 | out: | 193 | out: |
201 | return ret; | 194 | return ret; |
202 | } | 195 | } |
diff --git a/arch/arm/include/asm/mman.h b/arch/arm/include/asm/mman.h index 8eebf89f5ab1..41f99c573b93 100644 --- a/arch/arm/include/asm/mman.h +++ b/arch/arm/include/asm/mman.h | |||
@@ -1 +1,4 @@ | |||
1 | #include <asm-generic/mman.h> | 1 | #include <asm-generic/mman.h> |
2 | |||
3 | #define arch_mmap_check(addr, len, flags) \ | ||
4 | (((flags) & MAP_FIXED && (addr) < FIRST_USER_ADDRESS) ? -EINVAL : 0) | ||
diff --git a/arch/arm/kernel/calls.S b/arch/arm/kernel/calls.S index f58c1156e779..9314a2d681f1 100644 --- a/arch/arm/kernel/calls.S +++ b/arch/arm/kernel/calls.S | |||
@@ -172,7 +172,7 @@ | |||
172 | /* 160 */ CALL(sys_sched_get_priority_min) | 172 | /* 160 */ CALL(sys_sched_get_priority_min) |
173 | CALL(sys_sched_rr_get_interval) | 173 | CALL(sys_sched_rr_get_interval) |
174 | CALL(sys_nanosleep) | 174 | CALL(sys_nanosleep) |
175 | CALL(sys_arm_mremap) | 175 | CALL(sys_mremap) |
176 | CALL(sys_setresuid16) | 176 | CALL(sys_setresuid16) |
177 | /* 165 */ CALL(sys_getresuid16) | 177 | /* 165 */ CALL(sys_getresuid16) |
178 | CALL(sys_ni_syscall) /* vm86 */ | 178 | CALL(sys_ni_syscall) /* vm86 */ |
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index f0fe95b7085d..2c1db77d7848 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S | |||
@@ -416,12 +416,12 @@ sys_mmap2: | |||
416 | tst r5, #PGOFF_MASK | 416 | tst r5, #PGOFF_MASK |
417 | moveq r5, r5, lsr #PAGE_SHIFT - 12 | 417 | moveq r5, r5, lsr #PAGE_SHIFT - 12 |
418 | streq r5, [sp, #4] | 418 | streq r5, [sp, #4] |
419 | beq do_mmap2 | 419 | beq sys_mmap_pgoff |
420 | mov r0, #-EINVAL | 420 | mov r0, #-EINVAL |
421 | mov pc, lr | 421 | mov pc, lr |
422 | #else | 422 | #else |
423 | str r5, [sp, #4] | 423 | str r5, [sp, #4] |
424 | b do_mmap2 | 424 | b sys_mmap_pgoff |
425 | #endif | 425 | #endif |
426 | ENDPROC(sys_mmap2) | 426 | ENDPROC(sys_mmap2) |
427 | 427 | ||
diff --git a/arch/arm/kernel/sys_arm.c b/arch/arm/kernel/sys_arm.c index 78ecaac65206..ae4027bd01bd 100644 --- a/arch/arm/kernel/sys_arm.c +++ b/arch/arm/kernel/sys_arm.c | |||
@@ -28,41 +28,6 @@ | |||
28 | #include <linux/ipc.h> | 28 | #include <linux/ipc.h> |
29 | #include <linux/uaccess.h> | 29 | #include <linux/uaccess.h> |
30 | 30 | ||
31 | extern unsigned long do_mremap(unsigned long addr, unsigned long old_len, | ||
32 | unsigned long new_len, unsigned long flags, | ||
33 | unsigned long new_addr); | ||
34 | |||
35 | /* common code for old and new mmaps */ | ||
36 | inline long do_mmap2( | ||
37 | unsigned long addr, unsigned long len, | ||
38 | unsigned long prot, unsigned long flags, | ||
39 | unsigned long fd, unsigned long pgoff) | ||
40 | { | ||
41 | int error = -EINVAL; | ||
42 | struct file * file = NULL; | ||
43 | |||
44 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
45 | |||
46 | if (flags & MAP_FIXED && addr < FIRST_USER_ADDRESS) | ||
47 | goto out; | ||
48 | |||
49 | error = -EBADF; | ||
50 | if (!(flags & MAP_ANONYMOUS)) { | ||
51 | file = fget(fd); | ||
52 | if (!file) | ||
53 | goto out; | ||
54 | } | ||
55 | |||
56 | down_write(¤t->mm->mmap_sem); | ||
57 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
58 | up_write(¤t->mm->mmap_sem); | ||
59 | |||
60 | if (file) | ||
61 | fput(file); | ||
62 | out: | ||
63 | return error; | ||
64 | } | ||
65 | |||
66 | struct mmap_arg_struct { | 31 | struct mmap_arg_struct { |
67 | unsigned long addr; | 32 | unsigned long addr; |
68 | unsigned long len; | 33 | unsigned long len; |
@@ -84,29 +49,11 @@ asmlinkage int old_mmap(struct mmap_arg_struct __user *arg) | |||
84 | if (a.offset & ~PAGE_MASK) | 49 | if (a.offset & ~PAGE_MASK) |
85 | goto out; | 50 | goto out; |
86 | 51 | ||
87 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); | 52 | error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); |
88 | out: | 53 | out: |
89 | return error; | 54 | return error; |
90 | } | 55 | } |
91 | 56 | ||
92 | asmlinkage unsigned long | ||
93 | sys_arm_mremap(unsigned long addr, unsigned long old_len, | ||
94 | unsigned long new_len, unsigned long flags, | ||
95 | unsigned long new_addr) | ||
96 | { | ||
97 | unsigned long ret = -EINVAL; | ||
98 | |||
99 | if (flags & MREMAP_FIXED && new_addr < FIRST_USER_ADDRESS) | ||
100 | goto out; | ||
101 | |||
102 | down_write(¤t->mm->mmap_sem); | ||
103 | ret = do_mremap(addr, old_len, new_len, flags, new_addr); | ||
104 | up_write(¤t->mm->mmap_sem); | ||
105 | |||
106 | out: | ||
107 | return ret; | ||
108 | } | ||
109 | |||
110 | /* | 57 | /* |
111 | * Perform the select(nd, in, out, ex, tv) and mmap() system | 58 | * Perform the select(nd, in, out, ex, tv) and mmap() system |
112 | * calls. | 59 | * calls. |
diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index 2b7996401b0f..f5abc51c5a07 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c | |||
@@ -54,7 +54,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, | |||
54 | * We enforce the MAP_FIXED case. | 54 | * We enforce the MAP_FIXED case. |
55 | */ | 55 | */ |
56 | if (flags & MAP_FIXED) { | 56 | if (flags & MAP_FIXED) { |
57 | if (aliasing && flags & MAP_SHARED && addr & (SHMLBA - 1)) | 57 | if (aliasing && flags & MAP_SHARED && |
58 | (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)) | ||
58 | return -EINVAL; | 59 | return -EINVAL; |
59 | return addr; | 60 | return addr; |
60 | } | 61 | } |
diff --git a/arch/avr32/include/asm/syscalls.h b/arch/avr32/include/asm/syscalls.h index 483d666c27c0..66a197266637 100644 --- a/arch/avr32/include/asm/syscalls.h +++ b/arch/avr32/include/asm/syscalls.h | |||
@@ -29,10 +29,6 @@ asmlinkage int sys_sigaltstack(const stack_t __user *, stack_t __user *, | |||
29 | struct pt_regs *); | 29 | struct pt_regs *); |
30 | asmlinkage int sys_rt_sigreturn(struct pt_regs *); | 30 | asmlinkage int sys_rt_sigreturn(struct pt_regs *); |
31 | 31 | ||
32 | /* kernel/sys_avr32.c */ | ||
33 | asmlinkage long sys_mmap2(unsigned long, unsigned long, unsigned long, | ||
34 | unsigned long, unsigned long, off_t); | ||
35 | |||
36 | /* mm/cache.c */ | 32 | /* mm/cache.c */ |
37 | asmlinkage int sys_cacheflush(int, void __user *, size_t); | 33 | asmlinkage int sys_cacheflush(int, void __user *, size_t); |
38 | 34 | ||
diff --git a/arch/avr32/kernel/sys_avr32.c b/arch/avr32/kernel/sys_avr32.c index 5d2daeaf356f..459349b5ed5a 100644 --- a/arch/avr32/kernel/sys_avr32.c +++ b/arch/avr32/kernel/sys_avr32.c | |||
@@ -5,39 +5,8 @@ | |||
5 | * it under the terms of the GNU General Public License version 2 as | 5 | * it under the terms of the GNU General Public License version 2 as |
6 | * published by the Free Software Foundation. | 6 | * published by the Free Software Foundation. |
7 | */ | 7 | */ |
8 | #include <linux/errno.h> | ||
9 | #include <linux/fs.h> | ||
10 | #include <linux/file.h> | ||
11 | #include <linux/mm.h> | ||
12 | #include <linux/unistd.h> | 8 | #include <linux/unistd.h> |
13 | 9 | ||
14 | #include <asm/mman.h> | ||
15 | #include <asm/uaccess.h> | ||
16 | #include <asm/syscalls.h> | ||
17 | |||
18 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | ||
19 | unsigned long prot, unsigned long flags, | ||
20 | unsigned long fd, off_t offset) | ||
21 | { | ||
22 | int error = -EBADF; | ||
23 | struct file *file = NULL; | ||
24 | |||
25 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
26 | if (!(flags & MAP_ANONYMOUS)) { | ||
27 | file = fget(fd); | ||
28 | if (!file) | ||
29 | return error; | ||
30 | } | ||
31 | |||
32 | down_write(¤t->mm->mmap_sem); | ||
33 | error = do_mmap_pgoff(file, addr, len, prot, flags, offset); | ||
34 | up_write(¤t->mm->mmap_sem); | ||
35 | |||
36 | if (file) | ||
37 | fput(file); | ||
38 | return error; | ||
39 | } | ||
40 | |||
41 | int kernel_execve(const char *file, char **argv, char **envp) | 10 | int kernel_execve(const char *file, char **argv, char **envp) |
42 | { | 11 | { |
43 | register long scno asm("r8") = __NR_execve; | 12 | register long scno asm("r8") = __NR_execve; |
diff --git a/arch/avr32/kernel/syscall-stubs.S b/arch/avr32/kernel/syscall-stubs.S index f7244cd02fbb..0447a3e2ba64 100644 --- a/arch/avr32/kernel/syscall-stubs.S +++ b/arch/avr32/kernel/syscall-stubs.S | |||
@@ -61,7 +61,7 @@ __sys_execve: | |||
61 | __sys_mmap2: | 61 | __sys_mmap2: |
62 | pushm lr | 62 | pushm lr |
63 | st.w --sp, ARG6 | 63 | st.w --sp, ARG6 |
64 | call sys_mmap2 | 64 | call sys_mmap_pgoff |
65 | sub sp, -4 | 65 | sub sp, -4 |
66 | popm pc | 66 | popm pc |
67 | 67 | ||
diff --git a/arch/blackfin/kernel/sys_bfin.c b/arch/blackfin/kernel/sys_bfin.c index afcef129d4e8..2e7f8e10bf87 100644 --- a/arch/blackfin/kernel/sys_bfin.c +++ b/arch/blackfin/kernel/sys_bfin.c | |||
@@ -22,39 +22,6 @@ | |||
22 | #include <asm/cacheflush.h> | 22 | #include <asm/cacheflush.h> |
23 | #include <asm/dma.h> | 23 | #include <asm/dma.h> |
24 | 24 | ||
25 | /* common code for old and new mmaps */ | ||
26 | static inline long | ||
27 | do_mmap2(unsigned long addr, unsigned long len, | ||
28 | unsigned long prot, unsigned long flags, | ||
29 | unsigned long fd, unsigned long pgoff) | ||
30 | { | ||
31 | int error = -EBADF; | ||
32 | struct file *file = NULL; | ||
33 | |||
34 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
35 | if (!(flags & MAP_ANONYMOUS)) { | ||
36 | file = fget(fd); | ||
37 | if (!file) | ||
38 | goto out; | ||
39 | } | ||
40 | |||
41 | down_write(¤t->mm->mmap_sem); | ||
42 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
43 | up_write(¤t->mm->mmap_sem); | ||
44 | |||
45 | if (file) | ||
46 | fput(file); | ||
47 | out: | ||
48 | return error; | ||
49 | } | ||
50 | |||
51 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | ||
52 | unsigned long prot, unsigned long flags, | ||
53 | unsigned long fd, unsigned long pgoff) | ||
54 | { | ||
55 | return do_mmap2(addr, len, prot, flags, fd, pgoff); | ||
56 | } | ||
57 | |||
58 | asmlinkage void *sys_sram_alloc(size_t size, unsigned long flags) | 25 | asmlinkage void *sys_sram_alloc(size_t size, unsigned long flags) |
59 | { | 26 | { |
60 | return sram_alloc_with_lsl(size, flags); | 27 | return sram_alloc_with_lsl(size, flags); |
diff --git a/arch/blackfin/mach-common/entry.S b/arch/blackfin/mach-common/entry.S index a50637a8b9bd..f3f8bb46b517 100644 --- a/arch/blackfin/mach-common/entry.S +++ b/arch/blackfin/mach-common/entry.S | |||
@@ -1422,7 +1422,7 @@ ENTRY(_sys_call_table) | |||
1422 | .long _sys_ni_syscall /* streams2 */ | 1422 | .long _sys_ni_syscall /* streams2 */ |
1423 | .long _sys_vfork /* 190 */ | 1423 | .long _sys_vfork /* 190 */ |
1424 | .long _sys_getrlimit | 1424 | .long _sys_getrlimit |
1425 | .long _sys_mmap2 | 1425 | .long _sys_mmap_pgoff |
1426 | .long _sys_truncate64 | 1426 | .long _sys_truncate64 |
1427 | .long _sys_ftruncate64 | 1427 | .long _sys_ftruncate64 |
1428 | .long _sys_stat64 /* 195 */ | 1428 | .long _sys_stat64 /* 195 */ |
diff --git a/arch/cris/kernel/sys_cris.c b/arch/cris/kernel/sys_cris.c index 2ad962c7e88e..c2bbb1ac98a9 100644 --- a/arch/cris/kernel/sys_cris.c +++ b/arch/cris/kernel/sys_cris.c | |||
@@ -26,31 +26,6 @@ | |||
26 | #include <asm/uaccess.h> | 26 | #include <asm/uaccess.h> |
27 | #include <asm/segment.h> | 27 | #include <asm/segment.h> |
28 | 28 | ||
29 | /* common code for old and new mmaps */ | ||
30 | static inline long | ||
31 | do_mmap2(unsigned long addr, unsigned long len, unsigned long prot, | ||
32 | unsigned long flags, unsigned long fd, unsigned long pgoff) | ||
33 | { | ||
34 | int error = -EBADF; | ||
35 | struct file * file = NULL; | ||
36 | |||
37 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
38 | if (!(flags & MAP_ANONYMOUS)) { | ||
39 | file = fget(fd); | ||
40 | if (!file) | ||
41 | goto out; | ||
42 | } | ||
43 | |||
44 | down_write(¤t->mm->mmap_sem); | ||
45 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
46 | up_write(¤t->mm->mmap_sem); | ||
47 | |||
48 | if (file) | ||
49 | fput(file); | ||
50 | out: | ||
51 | return error; | ||
52 | } | ||
53 | |||
54 | asmlinkage unsigned long old_mmap(unsigned long __user *args) | 29 | asmlinkage unsigned long old_mmap(unsigned long __user *args) |
55 | { | 30 | { |
56 | unsigned long buffer[6]; | 31 | unsigned long buffer[6]; |
@@ -63,7 +38,7 @@ asmlinkage unsigned long old_mmap(unsigned long __user *args) | |||
63 | if (buffer[5] & ~PAGE_MASK) /* verify that offset is on page boundary */ | 38 | if (buffer[5] & ~PAGE_MASK) /* verify that offset is on page boundary */ |
64 | goto out; | 39 | goto out; |
65 | 40 | ||
66 | err = do_mmap2(buffer[0], buffer[1], buffer[2], buffer[3], | 41 | err = sys_mmap_pgoff(buffer[0], buffer[1], buffer[2], buffer[3], |
67 | buffer[4], buffer[5] >> PAGE_SHIFT); | 42 | buffer[4], buffer[5] >> PAGE_SHIFT); |
68 | out: | 43 | out: |
69 | return err; | 44 | return err; |
@@ -73,7 +48,8 @@ asmlinkage long | |||
73 | sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, | 48 | sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, |
74 | unsigned long flags, unsigned long fd, unsigned long pgoff) | 49 | unsigned long flags, unsigned long fd, unsigned long pgoff) |
75 | { | 50 | { |
76 | return do_mmap2(addr, len, prot, flags, fd, pgoff); | 51 | /* bug(?): 8Kb pages here */ |
52 | return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff); | ||
77 | } | 53 | } |
78 | 54 | ||
79 | /* | 55 | /* |
diff --git a/arch/frv/kernel/sys_frv.c b/arch/frv/kernel/sys_frv.c index 2b6b5289cdcc..1d3d4c9e2521 100644 --- a/arch/frv/kernel/sys_frv.c +++ b/arch/frv/kernel/sys_frv.c | |||
@@ -31,9 +31,6 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | |||
31 | unsigned long prot, unsigned long flags, | 31 | unsigned long prot, unsigned long flags, |
32 | unsigned long fd, unsigned long pgoff) | 32 | unsigned long fd, unsigned long pgoff) |
33 | { | 33 | { |
34 | int error = -EBADF; | ||
35 | struct file * file = NULL; | ||
36 | |||
37 | /* As with sparc32, make sure the shift for mmap2 is constant | 34 | /* As with sparc32, make sure the shift for mmap2 is constant |
38 | (12), no matter what PAGE_SIZE we have.... */ | 35 | (12), no matter what PAGE_SIZE we have.... */ |
39 | 36 | ||
@@ -41,69 +38,10 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | |||
41 | trying to map something we can't */ | 38 | trying to map something we can't */ |
42 | if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1)) | 39 | if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1)) |
43 | return -EINVAL; | 40 | return -EINVAL; |
44 | pgoff >>= PAGE_SHIFT - 12; | ||
45 | |||
46 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
47 | if (!(flags & MAP_ANONYMOUS)) { | ||
48 | file = fget(fd); | ||
49 | if (!file) | ||
50 | goto out; | ||
51 | } | ||
52 | |||
53 | down_write(¤t->mm->mmap_sem); | ||
54 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
55 | up_write(¤t->mm->mmap_sem); | ||
56 | |||
57 | if (file) | ||
58 | fput(file); | ||
59 | out: | ||
60 | return error; | ||
61 | } | ||
62 | |||
63 | #if 0 /* DAVIDM - do we want this */ | ||
64 | struct mmap_arg_struct64 { | ||
65 | __u32 addr; | ||
66 | __u32 len; | ||
67 | __u32 prot; | ||
68 | __u32 flags; | ||
69 | __u64 offset; /* 64 bits */ | ||
70 | __u32 fd; | ||
71 | }; | ||
72 | |||
73 | asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg) | ||
74 | { | ||
75 | int error = -EFAULT; | ||
76 | struct file * file = NULL; | ||
77 | struct mmap_arg_struct64 a; | ||
78 | unsigned long pgoff; | ||
79 | |||
80 | if (copy_from_user(&a, arg, sizeof(a))) | ||
81 | return -EFAULT; | ||
82 | |||
83 | if ((long)a.offset & ~PAGE_MASK) | ||
84 | return -EINVAL; | ||
85 | |||
86 | pgoff = a.offset >> PAGE_SHIFT; | ||
87 | if ((a.offset >> PAGE_SHIFT) != pgoff) | ||
88 | return -EINVAL; | ||
89 | |||
90 | if (!(a.flags & MAP_ANONYMOUS)) { | ||
91 | error = -EBADF; | ||
92 | file = fget(a.fd); | ||
93 | if (!file) | ||
94 | goto out; | ||
95 | } | ||
96 | a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
97 | 41 | ||
98 | down_write(¤t->mm->mmap_sem); | 42 | return sys_mmap_pgoff(addr, len, prot, flags, fd, |
99 | error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff); | 43 | pgoff >> (PAGE_SHIFT - 12)); |
100 | up_write(¤t->mm->mmap_sem); | ||
101 | if (file) | ||
102 | fput(file); | ||
103 | out: | ||
104 | return error; | ||
105 | } | 44 | } |
106 | #endif | ||
107 | 45 | ||
108 | /* | 46 | /* |
109 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. | 47 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
diff --git a/arch/h8300/kernel/sys_h8300.c b/arch/h8300/kernel/sys_h8300.c index 8cb5d73a0e35..b5969db0ca10 100644 --- a/arch/h8300/kernel/sys_h8300.c +++ b/arch/h8300/kernel/sys_h8300.c | |||
@@ -26,39 +26,6 @@ | |||
26 | #include <asm/traps.h> | 26 | #include <asm/traps.h> |
27 | #include <asm/unistd.h> | 27 | #include <asm/unistd.h> |
28 | 28 | ||
29 | /* common code for old and new mmaps */ | ||
30 | static inline long do_mmap2( | ||
31 | unsigned long addr, unsigned long len, | ||
32 | unsigned long prot, unsigned long flags, | ||
33 | unsigned long fd, unsigned long pgoff) | ||
34 | { | ||
35 | int error = -EBADF; | ||
36 | struct file * file = NULL; | ||
37 | |||
38 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
39 | if (!(flags & MAP_ANONYMOUS)) { | ||
40 | file = fget(fd); | ||
41 | if (!file) | ||
42 | goto out; | ||
43 | } | ||
44 | |||
45 | down_write(¤t->mm->mmap_sem); | ||
46 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
47 | up_write(¤t->mm->mmap_sem); | ||
48 | |||
49 | if (file) | ||
50 | fput(file); | ||
51 | out: | ||
52 | return error; | ||
53 | } | ||
54 | |||
55 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | ||
56 | unsigned long prot, unsigned long flags, | ||
57 | unsigned long fd, unsigned long pgoff) | ||
58 | { | ||
59 | return do_mmap2(addr, len, prot, flags, fd, pgoff); | ||
60 | } | ||
61 | |||
62 | /* | 29 | /* |
63 | * Perform the select(nd, in, out, ex, tv) and mmap() system | 30 | * Perform the select(nd, in, out, ex, tv) and mmap() system |
64 | * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to | 31 | * 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 | if (a.offset & ~PAGE_MASK) | 54 | if (a.offset & ~PAGE_MASK) |
88 | goto out; | 55 | goto out; |
89 | 56 | ||
90 | a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | 57 | error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, |
91 | 58 | a.offset >> PAGE_SHIFT); | |
92 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); | ||
93 | out: | ||
94 | return error; | ||
95 | } | ||
96 | |||
97 | #if 0 /* DAVIDM - do we want this */ | ||
98 | struct mmap_arg_struct64 { | ||
99 | __u32 addr; | ||
100 | __u32 len; | ||
101 | __u32 prot; | ||
102 | __u32 flags; | ||
103 | __u64 offset; /* 64 bits */ | ||
104 | __u32 fd; | ||
105 | }; | ||
106 | |||
107 | asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg) | ||
108 | { | ||
109 | int error = -EFAULT; | ||
110 | struct file * file = NULL; | ||
111 | struct mmap_arg_struct64 a; | ||
112 | unsigned long pgoff; | ||
113 | |||
114 | if (copy_from_user(&a, arg, sizeof(a))) | ||
115 | return -EFAULT; | ||
116 | |||
117 | if ((long)a.offset & ~PAGE_MASK) | ||
118 | return -EINVAL; | ||
119 | |||
120 | pgoff = a.offset >> PAGE_SHIFT; | ||
121 | if ((a.offset >> PAGE_SHIFT) != pgoff) | ||
122 | return -EINVAL; | ||
123 | |||
124 | if (!(a.flags & MAP_ANONYMOUS)) { | ||
125 | error = -EBADF; | ||
126 | file = fget(a.fd); | ||
127 | if (!file) | ||
128 | goto out; | ||
129 | } | ||
130 | a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
131 | |||
132 | down_write(¤t->mm->mmap_sem); | ||
133 | error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff); | ||
134 | up_write(¤t->mm->mmap_sem); | ||
135 | if (file) | ||
136 | fput(file); | ||
137 | out: | 59 | out: |
138 | return error; | 60 | return error; |
139 | } | 61 | } |
140 | #endif | ||
141 | 62 | ||
142 | struct sel_arg_struct { | 63 | struct sel_arg_struct { |
143 | unsigned long n; | 64 | unsigned long n; |
diff --git a/arch/h8300/kernel/syscalls.S b/arch/h8300/kernel/syscalls.S index 4eb67faac633..2d69881eda6a 100644 --- a/arch/h8300/kernel/syscalls.S +++ b/arch/h8300/kernel/syscalls.S | |||
@@ -206,7 +206,7 @@ SYMBOL_NAME_LABEL(sys_call_table) | |||
206 | .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */ | 206 | .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */ |
207 | .long SYMBOL_NAME(sys_vfork) /* 190 */ | 207 | .long SYMBOL_NAME(sys_vfork) /* 190 */ |
208 | .long SYMBOL_NAME(sys_getrlimit) | 208 | .long SYMBOL_NAME(sys_getrlimit) |
209 | .long SYMBOL_NAME(sys_mmap2) | 209 | .long SYMBOL_NAME(sys_mmap_pgoff) |
210 | .long SYMBOL_NAME(sys_truncate64) | 210 | .long SYMBOL_NAME(sys_truncate64) |
211 | .long SYMBOL_NAME(sys_ftruncate64) | 211 | .long SYMBOL_NAME(sys_ftruncate64) |
212 | .long SYMBOL_NAME(sys_stat64) /* 195 */ | 212 | .long SYMBOL_NAME(sys_stat64) /* 195 */ |
diff --git a/arch/ia64/ia32/sys_ia32.c b/arch/ia64/ia32/sys_ia32.c index 429ec968c9ee..045b746b9808 100644 --- a/arch/ia64/ia32/sys_ia32.c +++ b/arch/ia64/ia32/sys_ia32.c | |||
@@ -858,6 +858,9 @@ ia32_do_mmap (struct file *file, unsigned long addr, unsigned long len, int prot | |||
858 | 858 | ||
859 | prot = get_prot32(prot); | 859 | prot = get_prot32(prot); |
860 | 860 | ||
861 | if (flags & MAP_HUGETLB) | ||
862 | return -ENOMEM; | ||
863 | |||
861 | #if PAGE_SHIFT > IA32_PAGE_SHIFT | 864 | #if PAGE_SHIFT > IA32_PAGE_SHIFT |
862 | mutex_lock(&ia32_mmap_mutex); | 865 | mutex_lock(&ia32_mmap_mutex); |
863 | { | 866 | { |
diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c index 92ed83f34036..609d50056a6c 100644 --- a/arch/ia64/kernel/sys_ia64.c +++ b/arch/ia64/kernel/sys_ia64.c | |||
@@ -100,51 +100,7 @@ sys_getpagesize (void) | |||
100 | asmlinkage unsigned long | 100 | asmlinkage unsigned long |
101 | ia64_brk (unsigned long brk) | 101 | ia64_brk (unsigned long brk) |
102 | { | 102 | { |
103 | unsigned long rlim, retval, newbrk, oldbrk; | 103 | unsigned long retval = sys_brk(brk); |
104 | struct mm_struct *mm = current->mm; | ||
105 | |||
106 | /* | ||
107 | * Most of this replicates the code in sys_brk() except for an additional safety | ||
108 | * check and the clearing of r8. However, we can't call sys_brk() because we need | ||
109 | * to acquire the mmap_sem before we can do the test... | ||
110 | */ | ||
111 | down_write(&mm->mmap_sem); | ||
112 | |||
113 | if (brk < mm->end_code) | ||
114 | goto out; | ||
115 | newbrk = PAGE_ALIGN(brk); | ||
116 | oldbrk = PAGE_ALIGN(mm->brk); | ||
117 | if (oldbrk == newbrk) | ||
118 | goto set_brk; | ||
119 | |||
120 | /* Always allow shrinking brk. */ | ||
121 | if (brk <= mm->brk) { | ||
122 | if (!do_munmap(mm, newbrk, oldbrk-newbrk)) | ||
123 | goto set_brk; | ||
124 | goto out; | ||
125 | } | ||
126 | |||
127 | /* Check against unimplemented/unmapped addresses: */ | ||
128 | if ((newbrk - oldbrk) > RGN_MAP_LIMIT || REGION_OFFSET(newbrk) > RGN_MAP_LIMIT) | ||
129 | goto out; | ||
130 | |||
131 | /* Check against rlimit.. */ | ||
132 | rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur; | ||
133 | if (rlim < RLIM_INFINITY && brk - mm->start_data > rlim) | ||
134 | goto out; | ||
135 | |||
136 | /* Check against existing mmap mappings. */ | ||
137 | if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE)) | ||
138 | goto out; | ||
139 | |||
140 | /* Ok, looks good - let it rip. */ | ||
141 | if (do_brk(oldbrk, newbrk-oldbrk) != oldbrk) | ||
142 | goto out; | ||
143 | set_brk: | ||
144 | mm->brk = brk; | ||
145 | out: | ||
146 | retval = mm->brk; | ||
147 | up_write(&mm->mmap_sem); | ||
148 | force_successful_syscall_return(); | 104 | force_successful_syscall_return(); |
149 | return retval; | 105 | return retval; |
150 | } | 106 | } |
@@ -185,39 +141,6 @@ int ia64_mmap_check(unsigned long addr, unsigned long len, | |||
185 | return 0; | 141 | return 0; |
186 | } | 142 | } |
187 | 143 | ||
188 | static inline unsigned long | ||
189 | do_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, unsigned long pgoff) | ||
190 | { | ||
191 | struct file *file = NULL; | ||
192 | |||
193 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
194 | if (!(flags & MAP_ANONYMOUS)) { | ||
195 | file = fget(fd); | ||
196 | if (!file) | ||
197 | return -EBADF; | ||
198 | |||
199 | if (!file->f_op || !file->f_op->mmap) { | ||
200 | addr = -ENODEV; | ||
201 | goto out; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | /* Careful about overflows.. */ | ||
206 | len = PAGE_ALIGN(len); | ||
207 | if (!len || len > TASK_SIZE) { | ||
208 | addr = -EINVAL; | ||
209 | goto out; | ||
210 | } | ||
211 | |||
212 | down_write(¤t->mm->mmap_sem); | ||
213 | addr = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
214 | up_write(¤t->mm->mmap_sem); | ||
215 | |||
216 | out: if (file) | ||
217 | fput(file); | ||
218 | return addr; | ||
219 | } | ||
220 | |||
221 | /* | 144 | /* |
222 | * mmap2() is like mmap() except that the offset is expressed in units | 145 | * mmap2() is like mmap() except that the offset is expressed in units |
223 | * of PAGE_SIZE (instead of bytes). This allows to mmap2() (pieces | 146 | * of PAGE_SIZE (instead of bytes). This allows to mmap2() (pieces |
@@ -226,7 +149,7 @@ out: if (file) | |||
226 | asmlinkage unsigned long | 149 | asmlinkage unsigned long |
227 | sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff) | 150 | sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff) |
228 | { | 151 | { |
229 | addr = do_mmap2(addr, len, prot, flags, fd, pgoff); | 152 | addr = sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff); |
230 | if (!IS_ERR((void *) addr)) | 153 | if (!IS_ERR((void *) addr)) |
231 | force_successful_syscall_return(); | 154 | force_successful_syscall_return(); |
232 | return addr; | 155 | return addr; |
@@ -238,7 +161,7 @@ sys_mmap (unsigned long addr, unsigned long len, int prot, int flags, int fd, lo | |||
238 | if (offset_in_page(off) != 0) | 161 | if (offset_in_page(off) != 0) |
239 | return -EINVAL; | 162 | return -EINVAL; |
240 | 163 | ||
241 | addr = do_mmap2(addr, len, prot, flags, fd, off >> PAGE_SHIFT); | 164 | addr = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); |
242 | if (!IS_ERR((void *) addr)) | 165 | if (!IS_ERR((void *) addr)) |
243 | force_successful_syscall_return(); | 166 | force_successful_syscall_return(); |
244 | return addr; | 167 | return addr; |
diff --git a/arch/m32r/kernel/sys_m32r.c b/arch/m32r/kernel/sys_m32r.c index 305ac852bbed..d3c865c5a6ba 100644 --- a/arch/m32r/kernel/sys_m32r.c +++ b/arch/m32r/kernel/sys_m32r.c | |||
@@ -76,30 +76,6 @@ asmlinkage int sys_tas(int __user *addr) | |||
76 | return oldval; | 76 | return oldval; |
77 | } | 77 | } |
78 | 78 | ||
79 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | ||
80 | unsigned long prot, unsigned long flags, | ||
81 | unsigned long fd, unsigned long pgoff) | ||
82 | { | ||
83 | int error = -EBADF; | ||
84 | struct file *file = NULL; | ||
85 | |||
86 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
87 | if (!(flags & MAP_ANONYMOUS)) { | ||
88 | file = fget(fd); | ||
89 | if (!file) | ||
90 | goto out; | ||
91 | } | ||
92 | |||
93 | down_write(¤t->mm->mmap_sem); | ||
94 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
95 | up_write(¤t->mm->mmap_sem); | ||
96 | |||
97 | if (file) | ||
98 | fput(file); | ||
99 | out: | ||
100 | return error; | ||
101 | } | ||
102 | |||
103 | /* | 79 | /* |
104 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. | 80 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
105 | * | 81 | * |
diff --git a/arch/m32r/kernel/syscall_table.S b/arch/m32r/kernel/syscall_table.S index aa3bf4cfab37..60536e271233 100644 --- a/arch/m32r/kernel/syscall_table.S +++ b/arch/m32r/kernel/syscall_table.S | |||
@@ -191,7 +191,7 @@ ENTRY(sys_call_table) | |||
191 | .long sys_ni_syscall /* streams2 */ | 191 | .long sys_ni_syscall /* streams2 */ |
192 | .long sys_vfork /* 190 */ | 192 | .long sys_vfork /* 190 */ |
193 | .long sys_getrlimit | 193 | .long sys_getrlimit |
194 | .long sys_mmap2 | 194 | .long sys_mmap_pgoff |
195 | .long sys_truncate64 | 195 | .long sys_truncate64 |
196 | .long sys_ftruncate64 | 196 | .long sys_ftruncate64 |
197 | .long sys_stat64 /* 195 */ | 197 | .long sys_stat64 /* 195 */ |
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c index 7deb402bfc75..218f441de667 100644 --- a/arch/m68k/kernel/sys_m68k.c +++ b/arch/m68k/kernel/sys_m68k.c | |||
@@ -29,37 +29,16 @@ | |||
29 | #include <asm/page.h> | 29 | #include <asm/page.h> |
30 | #include <asm/unistd.h> | 30 | #include <asm/unistd.h> |
31 | 31 | ||
32 | /* common code for old and new mmaps */ | ||
33 | static inline long do_mmap2( | ||
34 | unsigned long addr, unsigned long len, | ||
35 | unsigned long prot, unsigned long flags, | ||
36 | unsigned long fd, unsigned long pgoff) | ||
37 | { | ||
38 | int error = -EBADF; | ||
39 | struct file * file = NULL; | ||
40 | |||
41 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
42 | if (!(flags & MAP_ANONYMOUS)) { | ||
43 | file = fget(fd); | ||
44 | if (!file) | ||
45 | goto out; | ||
46 | } | ||
47 | |||
48 | down_write(¤t->mm->mmap_sem); | ||
49 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
50 | up_write(¤t->mm->mmap_sem); | ||
51 | |||
52 | if (file) | ||
53 | fput(file); | ||
54 | out: | ||
55 | return error; | ||
56 | } | ||
57 | |||
58 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | 32 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, |
59 | unsigned long prot, unsigned long flags, | 33 | unsigned long prot, unsigned long flags, |
60 | unsigned long fd, unsigned long pgoff) | 34 | unsigned long fd, unsigned long pgoff) |
61 | { | 35 | { |
62 | return do_mmap2(addr, len, prot, flags, fd, pgoff); | 36 | /* |
37 | * This is wrong for sun3 - there PAGE_SIZE is 8Kb, | ||
38 | * so we need to shift the argument down by 1; m68k mmap64(3) | ||
39 | * (in libc) expects the last argument of mmap2 in 4Kb units. | ||
40 | */ | ||
41 | return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff); | ||
63 | } | 42 | } |
64 | 43 | ||
65 | /* | 44 | /* |
@@ -90,57 +69,11 @@ asmlinkage int old_mmap(struct mmap_arg_struct __user *arg) | |||
90 | if (a.offset & ~PAGE_MASK) | 69 | if (a.offset & ~PAGE_MASK) |
91 | goto out; | 70 | goto out; |
92 | 71 | ||
93 | a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | 72 | error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, |
94 | 73 | a.offset >> PAGE_SHIFT); | |
95 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); | ||
96 | out: | ||
97 | return error; | ||
98 | } | ||
99 | |||
100 | #if 0 | ||
101 | struct mmap_arg_struct64 { | ||
102 | __u32 addr; | ||
103 | __u32 len; | ||
104 | __u32 prot; | ||
105 | __u32 flags; | ||
106 | __u64 offset; /* 64 bits */ | ||
107 | __u32 fd; | ||
108 | }; | ||
109 | |||
110 | asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg) | ||
111 | { | ||
112 | int error = -EFAULT; | ||
113 | struct file * file = NULL; | ||
114 | struct mmap_arg_struct64 a; | ||
115 | unsigned long pgoff; | ||
116 | |||
117 | if (copy_from_user(&a, arg, sizeof(a))) | ||
118 | return -EFAULT; | ||
119 | |||
120 | if ((long)a.offset & ~PAGE_MASK) | ||
121 | return -EINVAL; | ||
122 | |||
123 | pgoff = a.offset >> PAGE_SHIFT; | ||
124 | if ((a.offset >> PAGE_SHIFT) != pgoff) | ||
125 | return -EINVAL; | ||
126 | |||
127 | if (!(a.flags & MAP_ANONYMOUS)) { | ||
128 | error = -EBADF; | ||
129 | file = fget(a.fd); | ||
130 | if (!file) | ||
131 | goto out; | ||
132 | } | ||
133 | a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
134 | |||
135 | down_write(¤t->mm->mmap_sem); | ||
136 | error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff); | ||
137 | up_write(¤t->mm->mmap_sem); | ||
138 | if (file) | ||
139 | fput(file); | ||
140 | out: | 74 | out: |
141 | return error; | 75 | return error; |
142 | } | 76 | } |
143 | #endif | ||
144 | 77 | ||
145 | struct sel_arg_struct { | 78 | struct sel_arg_struct { |
146 | unsigned long n; | 79 | unsigned long n; |
diff --git a/arch/m68knommu/kernel/sys_m68k.c b/arch/m68knommu/kernel/sys_m68k.c index efdd090778a3..b67cbc735a9b 100644 --- a/arch/m68knommu/kernel/sys_m68k.c +++ b/arch/m68knommu/kernel/sys_m68k.c | |||
@@ -27,39 +27,6 @@ | |||
27 | #include <asm/cacheflush.h> | 27 | #include <asm/cacheflush.h> |
28 | #include <asm/unistd.h> | 28 | #include <asm/unistd.h> |
29 | 29 | ||
30 | /* common code for old and new mmaps */ | ||
31 | static inline long do_mmap2( | ||
32 | unsigned long addr, unsigned long len, | ||
33 | unsigned long prot, unsigned long flags, | ||
34 | unsigned long fd, unsigned long pgoff) | ||
35 | { | ||
36 | int error = -EBADF; | ||
37 | struct file * file = NULL; | ||
38 | |||
39 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
40 | if (!(flags & MAP_ANONYMOUS)) { | ||
41 | file = fget(fd); | ||
42 | if (!file) | ||
43 | goto out; | ||
44 | } | ||
45 | |||
46 | down_write(¤t->mm->mmap_sem); | ||
47 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
48 | up_write(¤t->mm->mmap_sem); | ||
49 | |||
50 | if (file) | ||
51 | fput(file); | ||
52 | out: | ||
53 | return error; | ||
54 | } | ||
55 | |||
56 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | ||
57 | unsigned long prot, unsigned long flags, | ||
58 | unsigned long fd, unsigned long pgoff) | ||
59 | { | ||
60 | return do_mmap2(addr, len, prot, flags, fd, pgoff); | ||
61 | } | ||
62 | |||
63 | /* | 30 | /* |
64 | * Perform the select(nd, in, out, ex, tv) and mmap() system | 31 | * Perform the select(nd, in, out, ex, tv) and mmap() system |
65 | * calls. Linux/m68k cloned Linux/i386, which didn't use to be able to | 32 | * 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 | if (a.offset & ~PAGE_MASK) | 55 | if (a.offset & ~PAGE_MASK) |
89 | goto out; | 56 | goto out; |
90 | 57 | ||
91 | a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | 58 | error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, |
92 | 59 | a.offset >> PAGE_SHIFT); | |
93 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); | ||
94 | out: | 60 | out: |
95 | return error; | 61 | return error; |
96 | } | 62 | } |
diff --git a/arch/m68knommu/kernel/syscalltable.S b/arch/m68knommu/kernel/syscalltable.S index 23535cc415ae..486837efa3d7 100644 --- a/arch/m68knommu/kernel/syscalltable.S +++ b/arch/m68knommu/kernel/syscalltable.S | |||
@@ -210,7 +210,7 @@ ENTRY(sys_call_table) | |||
210 | .long sys_ni_syscall /* streams2 */ | 210 | .long sys_ni_syscall /* streams2 */ |
211 | .long sys_vfork /* 190 */ | 211 | .long sys_vfork /* 190 */ |
212 | .long sys_getrlimit | 212 | .long sys_getrlimit |
213 | .long sys_mmap2 | 213 | .long sys_mmap_pgoff |
214 | .long sys_truncate64 | 214 | .long sys_truncate64 |
215 | .long sys_ftruncate64 | 215 | .long sys_ftruncate64 |
216 | .long sys_stat64 /* 195 */ | 216 | .long sys_stat64 /* 195 */ |
diff --git a/arch/microblaze/kernel/sys_microblaze.c b/arch/microblaze/kernel/sys_microblaze.c index 07cabed4b947..9f3c205fb75b 100644 --- a/arch/microblaze/kernel/sys_microblaze.c +++ b/arch/microblaze/kernel/sys_microblaze.c | |||
@@ -62,46 +62,14 @@ out: | |||
62 | return error; | 62 | return error; |
63 | } | 63 | } |
64 | 64 | ||
65 | asmlinkage long | ||
66 | sys_mmap2(unsigned long addr, unsigned long len, | ||
67 | unsigned long prot, unsigned long flags, | ||
68 | unsigned long fd, unsigned long pgoff) | ||
69 | { | ||
70 | struct file *file = NULL; | ||
71 | int ret = -EBADF; | ||
72 | |||
73 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
74 | if (!(flags & MAP_ANONYMOUS)) { | ||
75 | file = fget(fd); | ||
76 | if (!file) { | ||
77 | printk(KERN_INFO "no fd in mmap\r\n"); | ||
78 | goto out; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | down_write(¤t->mm->mmap_sem); | ||
83 | ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
84 | up_write(¤t->mm->mmap_sem); | ||
85 | if (file) | ||
86 | fput(file); | ||
87 | out: | ||
88 | return ret; | ||
89 | } | ||
90 | |||
91 | asmlinkage long sys_mmap(unsigned long addr, unsigned long len, | 65 | asmlinkage long sys_mmap(unsigned long addr, unsigned long len, |
92 | unsigned long prot, unsigned long flags, | 66 | unsigned long prot, unsigned long flags, |
93 | unsigned long fd, off_t pgoff) | 67 | unsigned long fd, off_t pgoff) |
94 | { | 68 | { |
95 | int err = -EINVAL; | 69 | if (pgoff & ~PAGE_MASK) |
96 | 70 | return -EINVAL; | |
97 | if (pgoff & ~PAGE_MASK) { | ||
98 | printk(KERN_INFO "no pagemask in mmap\r\n"); | ||
99 | goto out; | ||
100 | } | ||
101 | 71 | ||
102 | err = sys_mmap2(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT); | 72 | return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT); |
103 | out: | ||
104 | return err; | ||
105 | } | 73 | } |
106 | 74 | ||
107 | /* | 75 | /* |
diff --git a/arch/microblaze/kernel/syscall_table.S b/arch/microblaze/kernel/syscall_table.S index c1ab1dc10898..b96f365ea6b1 100644 --- a/arch/microblaze/kernel/syscall_table.S +++ b/arch/microblaze/kernel/syscall_table.S | |||
@@ -196,7 +196,7 @@ ENTRY(sys_call_table) | |||
196 | .long sys_ni_syscall /* reserved for streams2 */ | 196 | .long sys_ni_syscall /* reserved for streams2 */ |
197 | .long sys_vfork /* 190 */ | 197 | .long sys_vfork /* 190 */ |
198 | .long sys_getrlimit | 198 | .long sys_getrlimit |
199 | .long sys_mmap2 /* mmap2 */ | 199 | .long sys_mmap_pgoff /* mmap2 */ |
200 | .long sys_truncate64 | 200 | .long sys_truncate64 |
201 | .long sys_ftruncate64 | 201 | .long sys_ftruncate64 |
202 | .long sys_stat64 /* 195 */ | 202 | .long sys_stat64 /* 195 */ |
diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c index 1a2793efdc4e..f042563c924f 100644 --- a/arch/mips/kernel/linux32.c +++ b/arch/mips/kernel/linux32.c | |||
@@ -67,28 +67,13 @@ SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len, | |||
67 | unsigned long, prot, unsigned long, flags, unsigned long, fd, | 67 | unsigned long, prot, unsigned long, flags, unsigned long, fd, |
68 | unsigned long, pgoff) | 68 | unsigned long, pgoff) |
69 | { | 69 | { |
70 | struct file * file = NULL; | ||
71 | unsigned long error; | 70 | unsigned long error; |
72 | 71 | ||
73 | error = -EINVAL; | 72 | error = -EINVAL; |
74 | if (pgoff & (~PAGE_MASK >> 12)) | 73 | if (pgoff & (~PAGE_MASK >> 12)) |
75 | goto out; | 74 | goto out; |
76 | pgoff >>= PAGE_SHIFT-12; | 75 | error = sys_mmap_pgoff(addr, len, prot, flags, fd, |
77 | 76 | pgoff >> (PAGE_SHIFT-12)); | |
78 | if (!(flags & MAP_ANONYMOUS)) { | ||
79 | error = -EBADF; | ||
80 | file = fget(fd); | ||
81 | if (!file) | ||
82 | goto out; | ||
83 | } | ||
84 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
85 | |||
86 | down_write(¤t->mm->mmap_sem); | ||
87 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
88 | up_write(¤t->mm->mmap_sem); | ||
89 | if (file) | ||
90 | fput(file); | ||
91 | |||
92 | out: | 77 | out: |
93 | return error; | 78 | return error; |
94 | } | 79 | } |
diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c index fe0d79805603..3f7f466190b4 100644 --- a/arch/mips/kernel/syscall.c +++ b/arch/mips/kernel/syscall.c | |||
@@ -93,7 +93,8 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, | |||
93 | * We do not accept a shared mapping if it would violate | 93 | * We do not accept a shared mapping if it would violate |
94 | * cache aliasing constraints. | 94 | * cache aliasing constraints. |
95 | */ | 95 | */ |
96 | if ((flags & MAP_SHARED) && (addr & shm_align_mask)) | 96 | if ((flags & MAP_SHARED) && |
97 | ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask)) | ||
97 | return -EINVAL; | 98 | return -EINVAL; |
98 | return addr; | 99 | return addr; |
99 | } | 100 | } |
@@ -129,31 +130,6 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, | |||
129 | } | 130 | } |
130 | } | 131 | } |
131 | 132 | ||
132 | /* common code for old and new mmaps */ | ||
133 | static inline unsigned long | ||
134 | do_mmap2(unsigned long addr, unsigned long len, unsigned long prot, | ||
135 | unsigned long flags, unsigned long fd, unsigned long pgoff) | ||
136 | { | ||
137 | unsigned long error = -EBADF; | ||
138 | struct file * file = NULL; | ||
139 | |||
140 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
141 | if (!(flags & MAP_ANONYMOUS)) { | ||
142 | file = fget(fd); | ||
143 | if (!file) | ||
144 | goto out; | ||
145 | } | ||
146 | |||
147 | down_write(¤t->mm->mmap_sem); | ||
148 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
149 | up_write(¤t->mm->mmap_sem); | ||
150 | |||
151 | if (file) | ||
152 | fput(file); | ||
153 | out: | ||
154 | return error; | ||
155 | } | ||
156 | |||
157 | SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, | 133 | SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, |
158 | unsigned long, prot, unsigned long, flags, unsigned long, | 134 | unsigned long, prot, unsigned long, flags, unsigned long, |
159 | fd, off_t, offset) | 135 | fd, off_t, offset) |
@@ -164,7 +140,7 @@ SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, | |||
164 | if (offset & ~PAGE_MASK) | 140 | if (offset & ~PAGE_MASK) |
165 | goto out; | 141 | goto out; |
166 | 142 | ||
167 | result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); | 143 | result = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
168 | 144 | ||
169 | out: | 145 | out: |
170 | return result; | 146 | return result; |
@@ -177,7 +153,7 @@ SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len, | |||
177 | if (pgoff & (~PAGE_MASK >> 12)) | 153 | if (pgoff & (~PAGE_MASK >> 12)) |
178 | return -EINVAL; | 154 | return -EINVAL; |
179 | 155 | ||
180 | return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12)); | 156 | return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12)); |
181 | } | 157 | } |
182 | 158 | ||
183 | save_static_function(sys_fork); | 159 | save_static_function(sys_fork); |
diff --git a/arch/mn10300/include/asm/mman.h b/arch/mn10300/include/asm/mman.h index 8eebf89f5ab1..db5c53da73ce 100644 --- a/arch/mn10300/include/asm/mman.h +++ b/arch/mn10300/include/asm/mman.h | |||
@@ -1 +1,6 @@ | |||
1 | #include <asm-generic/mman.h> | 1 | #include <asm-generic/mman.h> |
2 | |||
3 | #define MIN_MAP_ADDR PAGE_SIZE /* minimum fixed mmap address */ | ||
4 | |||
5 | #define arch_mmap_check(addr, len, flags) \ | ||
6 | (((flags) & MAP_FIXED && (addr) < MIN_MAP_ADDR) ? -EINVAL : 0) | ||
diff --git a/arch/mn10300/kernel/entry.S b/arch/mn10300/kernel/entry.S index a94e7ea3faa6..c9ee6c009d79 100644 --- a/arch/mn10300/kernel/entry.S +++ b/arch/mn10300/kernel/entry.S | |||
@@ -578,7 +578,7 @@ ENTRY(sys_call_table) | |||
578 | .long sys_ni_syscall /* reserved for streams2 */ | 578 | .long sys_ni_syscall /* reserved for streams2 */ |
579 | .long sys_vfork /* 190 */ | 579 | .long sys_vfork /* 190 */ |
580 | .long sys_getrlimit | 580 | .long sys_getrlimit |
581 | .long sys_mmap2 | 581 | .long sys_mmap_pgoff |
582 | .long sys_truncate64 | 582 | .long sys_truncate64 |
583 | .long sys_ftruncate64 | 583 | .long sys_ftruncate64 |
584 | .long sys_stat64 /* 195 */ | 584 | .long sys_stat64 /* 195 */ |
diff --git a/arch/mn10300/kernel/sys_mn10300.c b/arch/mn10300/kernel/sys_mn10300.c index 8ca5af00334c..17cc6ce04e84 100644 --- a/arch/mn10300/kernel/sys_mn10300.c +++ b/arch/mn10300/kernel/sys_mn10300.c | |||
@@ -23,47 +23,13 @@ | |||
23 | 23 | ||
24 | #include <asm/uaccess.h> | 24 | #include <asm/uaccess.h> |
25 | 25 | ||
26 | #define MIN_MAP_ADDR PAGE_SIZE /* minimum fixed mmap address */ | ||
27 | |||
28 | /* | ||
29 | * memory mapping syscall | ||
30 | */ | ||
31 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | ||
32 | unsigned long prot, unsigned long flags, | ||
33 | unsigned long fd, unsigned long pgoff) | ||
34 | { | ||
35 | struct file *file = NULL; | ||
36 | long error = -EINVAL; | ||
37 | |||
38 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
39 | |||
40 | if (flags & MAP_FIXED && addr < MIN_MAP_ADDR) | ||
41 | goto out; | ||
42 | |||
43 | error = -EBADF; | ||
44 | if (!(flags & MAP_ANONYMOUS)) { | ||
45 | file = fget(fd); | ||
46 | if (!file) | ||
47 | goto out; | ||
48 | } | ||
49 | |||
50 | down_write(¤t->mm->mmap_sem); | ||
51 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
52 | up_write(¤t->mm->mmap_sem); | ||
53 | |||
54 | if (file) | ||
55 | fput(file); | ||
56 | out: | ||
57 | return error; | ||
58 | } | ||
59 | |||
60 | asmlinkage long old_mmap(unsigned long addr, unsigned long len, | 26 | asmlinkage long old_mmap(unsigned long addr, unsigned long len, |
61 | unsigned long prot, unsigned long flags, | 27 | unsigned long prot, unsigned long flags, |
62 | unsigned long fd, unsigned long offset) | 28 | unsigned long fd, unsigned long offset) |
63 | { | 29 | { |
64 | if (offset & ~PAGE_MASK) | 30 | if (offset & ~PAGE_MASK) |
65 | return -EINVAL; | 31 | return -EINVAL; |
66 | return sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); | 32 | return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
67 | } | 33 | } |
68 | 34 | ||
69 | struct sel_arg_struct { | 35 | struct sel_arg_struct { |
diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c index 71b31957c8f1..9147391afb03 100644 --- a/arch/parisc/kernel/sys_parisc.c +++ b/arch/parisc/kernel/sys_parisc.c | |||
@@ -110,37 +110,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, | |||
110 | return addr; | 110 | return addr; |
111 | } | 111 | } |
112 | 112 | ||
113 | static unsigned long do_mmap2(unsigned long addr, unsigned long len, | ||
114 | unsigned long prot, unsigned long flags, unsigned long fd, | ||
115 | unsigned long pgoff) | ||
116 | { | ||
117 | struct file * file = NULL; | ||
118 | unsigned long error = -EBADF; | ||
119 | if (!(flags & MAP_ANONYMOUS)) { | ||
120 | file = fget(fd); | ||
121 | if (!file) | ||
122 | goto out; | ||
123 | } | ||
124 | |||
125 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
126 | |||
127 | down_write(¤t->mm->mmap_sem); | ||
128 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
129 | up_write(¤t->mm->mmap_sem); | ||
130 | |||
131 | if (file != NULL) | ||
132 | fput(file); | ||
133 | out: | ||
134 | return error; | ||
135 | } | ||
136 | |||
137 | asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, | 113 | asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, |
138 | unsigned long prot, unsigned long flags, unsigned long fd, | 114 | unsigned long prot, unsigned long flags, unsigned long fd, |
139 | unsigned long pgoff) | 115 | unsigned long pgoff) |
140 | { | 116 | { |
141 | /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE | 117 | /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE |
142 | we have. */ | 118 | we have. */ |
143 | return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT - 12)); | 119 | return sys_mmap_pgoff(addr, len, prot, flags, fd, |
120 | pgoff >> (PAGE_SHIFT - 12)); | ||
144 | } | 121 | } |
145 | 122 | ||
146 | asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, | 123 | 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, | |||
148 | unsigned long offset) | 125 | unsigned long offset) |
149 | { | 126 | { |
150 | if (!(offset & ~PAGE_MASK)) { | 127 | if (!(offset & ~PAGE_MASK)) { |
151 | return do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); | 128 | return sys_mmap_pgoff(addr, len, prot, flags, fd, |
129 | offset >> PAGE_SHIFT); | ||
152 | } else { | 130 | } else { |
153 | return -EINVAL; | 131 | return -EINVAL; |
154 | } | 132 | } |
diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c index c04832c4a02e..3370e62e43d4 100644 --- a/arch/powerpc/kernel/syscalls.c +++ b/arch/powerpc/kernel/syscalls.c | |||
@@ -140,7 +140,6 @@ static inline unsigned long do_mmap2(unsigned long addr, size_t len, | |||
140 | unsigned long prot, unsigned long flags, | 140 | unsigned long prot, unsigned long flags, |
141 | unsigned long fd, unsigned long off, int shift) | 141 | unsigned long fd, unsigned long off, int shift) |
142 | { | 142 | { |
143 | struct file * file = NULL; | ||
144 | unsigned long ret = -EINVAL; | 143 | unsigned long ret = -EINVAL; |
145 | 144 | ||
146 | if (!arch_validate_prot(prot)) | 145 | if (!arch_validate_prot(prot)) |
@@ -151,20 +150,8 @@ static inline unsigned long do_mmap2(unsigned long addr, size_t len, | |||
151 | goto out; | 150 | goto out; |
152 | off >>= shift; | 151 | off >>= shift; |
153 | } | 152 | } |
154 | |||
155 | ret = -EBADF; | ||
156 | if (!(flags & MAP_ANONYMOUS)) { | ||
157 | if (!(file = fget(fd))) | ||
158 | goto out; | ||
159 | } | ||
160 | |||
161 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
162 | 153 | ||
163 | down_write(¤t->mm->mmap_sem); | 154 | ret = sys_mmap_pgoff(addr, len, prot, flags, fd, off); |
164 | ret = do_mmap_pgoff(file, addr, len, prot, flags, off); | ||
165 | up_write(¤t->mm->mmap_sem); | ||
166 | if (file) | ||
167 | fput(file); | ||
168 | out: | 155 | out: |
169 | return ret; | 156 | return ret; |
170 | } | 157 | } |
diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c index 25c31d681402..22c9e557bb22 100644 --- a/arch/s390/kernel/compat_linux.c +++ b/arch/s390/kernel/compat_linux.c | |||
@@ -624,38 +624,6 @@ struct mmap_arg_struct_emu31 { | |||
624 | u32 offset; | 624 | u32 offset; |
625 | }; | 625 | }; |
626 | 626 | ||
627 | /* common code for old and new mmaps */ | ||
628 | static inline long do_mmap2( | ||
629 | unsigned long addr, unsigned long len, | ||
630 | unsigned long prot, unsigned long flags, | ||
631 | unsigned long fd, unsigned long pgoff) | ||
632 | { | ||
633 | struct file * file = NULL; | ||
634 | unsigned long error = -EBADF; | ||
635 | |||
636 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
637 | if (!(flags & MAP_ANONYMOUS)) { | ||
638 | file = fget(fd); | ||
639 | if (!file) | ||
640 | goto out; | ||
641 | } | ||
642 | |||
643 | down_write(¤t->mm->mmap_sem); | ||
644 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
645 | if (!IS_ERR((void *) error) && error + len >= 0x80000000ULL) { | ||
646 | /* Result is out of bounds. */ | ||
647 | do_munmap(current->mm, addr, len); | ||
648 | error = -ENOMEM; | ||
649 | } | ||
650 | up_write(¤t->mm->mmap_sem); | ||
651 | |||
652 | if (file) | ||
653 | fput(file); | ||
654 | out: | ||
655 | return error; | ||
656 | } | ||
657 | |||
658 | |||
659 | asmlinkage unsigned long | 627 | asmlinkage unsigned long |
660 | old32_mmap(struct mmap_arg_struct_emu31 __user *arg) | 628 | old32_mmap(struct mmap_arg_struct_emu31 __user *arg) |
661 | { | 629 | { |
@@ -669,7 +637,8 @@ old32_mmap(struct mmap_arg_struct_emu31 __user *arg) | |||
669 | if (a.offset & ~PAGE_MASK) | 637 | if (a.offset & ~PAGE_MASK) |
670 | goto out; | 638 | goto out; |
671 | 639 | ||
672 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); | 640 | error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, |
641 | a.offset >> PAGE_SHIFT); | ||
673 | out: | 642 | out: |
674 | return error; | 643 | return error; |
675 | } | 644 | } |
@@ -682,7 +651,7 @@ sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg) | |||
682 | 651 | ||
683 | if (copy_from_user(&a, arg, sizeof(a))) | 652 | if (copy_from_user(&a, arg, sizeof(a))) |
684 | goto out; | 653 | goto out; |
685 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); | 654 | error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); |
686 | out: | 655 | out: |
687 | return error; | 656 | return error; |
688 | } | 657 | } |
diff --git a/arch/s390/kernel/sys_s390.c b/arch/s390/kernel/sys_s390.c index e9d94f61d500..86a74c9c9e63 100644 --- a/arch/s390/kernel/sys_s390.c +++ b/arch/s390/kernel/sys_s390.c | |||
@@ -32,32 +32,6 @@ | |||
32 | #include <asm/uaccess.h> | 32 | #include <asm/uaccess.h> |
33 | #include "entry.h" | 33 | #include "entry.h" |
34 | 34 | ||
35 | /* common code for old and new mmaps */ | ||
36 | static inline long do_mmap2( | ||
37 | unsigned long addr, unsigned long len, | ||
38 | unsigned long prot, unsigned long flags, | ||
39 | unsigned long fd, unsigned long pgoff) | ||
40 | { | ||
41 | long error = -EBADF; | ||
42 | struct file * file = NULL; | ||
43 | |||
44 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
45 | if (!(flags & MAP_ANONYMOUS)) { | ||
46 | file = fget(fd); | ||
47 | if (!file) | ||
48 | goto out; | ||
49 | } | ||
50 | |||
51 | down_write(¤t->mm->mmap_sem); | ||
52 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
53 | up_write(¤t->mm->mmap_sem); | ||
54 | |||
55 | if (file) | ||
56 | fput(file); | ||
57 | out: | ||
58 | return error; | ||
59 | } | ||
60 | |||
61 | /* | 35 | /* |
62 | * Perform the select(nd, in, out, ex, tv) and mmap() system | 36 | * Perform the select(nd, in, out, ex, tv) and mmap() system |
63 | * calls. Linux for S/390 isn't able to handle more than 5 | 37 | * 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) | |||
81 | 55 | ||
82 | if (copy_from_user(&a, arg, sizeof(a))) | 56 | if (copy_from_user(&a, arg, sizeof(a))) |
83 | goto out; | 57 | goto out; |
84 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); | 58 | error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); |
85 | out: | 59 | out: |
86 | return error; | 60 | return error; |
87 | } | 61 | } |
@@ -98,7 +72,7 @@ SYSCALL_DEFINE1(s390_old_mmap, struct mmap_arg_struct __user *, arg) | |||
98 | if (a.offset & ~PAGE_MASK) | 72 | if (a.offset & ~PAGE_MASK) |
99 | goto out; | 73 | goto out; |
100 | 74 | ||
101 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); | 75 | error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); |
102 | out: | 76 | out: |
103 | return error; | 77 | return error; |
104 | } | 78 | } |
diff --git a/arch/score/kernel/sys_score.c b/arch/score/kernel/sys_score.c index 001249469866..856ed68a58e6 100644 --- a/arch/score/kernel/sys_score.c +++ b/arch/score/kernel/sys_score.c | |||
@@ -36,34 +36,16 @@ asmlinkage long | |||
36 | sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, | 36 | sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, |
37 | unsigned long flags, unsigned long fd, unsigned long pgoff) | 37 | unsigned long flags, unsigned long fd, unsigned long pgoff) |
38 | { | 38 | { |
39 | int error = -EBADF; | 39 | return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff); |
40 | struct file *file = NULL; | ||
41 | |||
42 | if (pgoff & (~PAGE_MASK >> 12)) | ||
43 | return -EINVAL; | ||
44 | |||
45 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
46 | if (!(flags & MAP_ANONYMOUS)) { | ||
47 | file = fget(fd); | ||
48 | if (!file) | ||
49 | return error; | ||
50 | } | ||
51 | |||
52 | down_write(¤t->mm->mmap_sem); | ||
53 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
54 | up_write(¤t->mm->mmap_sem); | ||
55 | |||
56 | if (file) | ||
57 | fput(file); | ||
58 | |||
59 | return error; | ||
60 | } | 40 | } |
61 | 41 | ||
62 | asmlinkage long | 42 | asmlinkage long |
63 | sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, | 43 | sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, |
64 | unsigned long flags, unsigned long fd, off_t pgoff) | 44 | unsigned long flags, unsigned long fd, off_t offset) |
65 | { | 45 | { |
66 | return sys_mmap2(addr, len, prot, flags, fd, pgoff >> PAGE_SHIFT); | 46 | if (unlikely(offset & ~PAGE_MASK)) |
47 | return -EINVAL; | ||
48 | return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); | ||
67 | } | 49 | } |
68 | 50 | ||
69 | asmlinkage long | 51 | asmlinkage long |
diff --git a/arch/sh/kernel/sys_sh.c b/arch/sh/kernel/sys_sh.c index 8aa5d1ceaf14..71399cde03b5 100644 --- a/arch/sh/kernel/sys_sh.c +++ b/arch/sh/kernel/sys_sh.c | |||
@@ -28,37 +28,13 @@ | |||
28 | #include <asm/cacheflush.h> | 28 | #include <asm/cacheflush.h> |
29 | #include <asm/cachectl.h> | 29 | #include <asm/cachectl.h> |
30 | 30 | ||
31 | static inline long | ||
32 | do_mmap2(unsigned long addr, unsigned long len, unsigned long prot, | ||
33 | unsigned long flags, int fd, unsigned long pgoff) | ||
34 | { | ||
35 | int error = -EBADF; | ||
36 | struct file *file = NULL; | ||
37 | |||
38 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
39 | if (!(flags & MAP_ANONYMOUS)) { | ||
40 | file = fget(fd); | ||
41 | if (!file) | ||
42 | goto out; | ||
43 | } | ||
44 | |||
45 | down_write(¤t->mm->mmap_sem); | ||
46 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
47 | up_write(¤t->mm->mmap_sem); | ||
48 | |||
49 | if (file) | ||
50 | fput(file); | ||
51 | out: | ||
52 | return error; | ||
53 | } | ||
54 | |||
55 | asmlinkage int old_mmap(unsigned long addr, unsigned long len, | 31 | asmlinkage int old_mmap(unsigned long addr, unsigned long len, |
56 | unsigned long prot, unsigned long flags, | 32 | unsigned long prot, unsigned long flags, |
57 | int fd, unsigned long off) | 33 | int fd, unsigned long off) |
58 | { | 34 | { |
59 | if (off & ~PAGE_MASK) | 35 | if (off & ~PAGE_MASK) |
60 | return -EINVAL; | 36 | return -EINVAL; |
61 | return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT); | 37 | return sys_mmap_pgoff(addr, len, prot, flags, fd, off>>PAGE_SHIFT); |
62 | } | 38 | } |
63 | 39 | ||
64 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | 40 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, |
@@ -74,7 +50,7 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | |||
74 | 50 | ||
75 | pgoff >>= PAGE_SHIFT - 12; | 51 | pgoff >>= PAGE_SHIFT - 12; |
76 | 52 | ||
77 | return do_mmap2(addr, len, prot, flags, fd, pgoff); | 53 | return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff); |
78 | } | 54 | } |
79 | 55 | ||
80 | /* | 56 | /* |
diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c index d2984fa42d3d..afeb710ec5c3 100644 --- a/arch/sh/mm/mmap.c +++ b/arch/sh/mm/mmap.c | |||
@@ -54,7 +54,8 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, | |||
54 | /* We do not accept a shared mapping if it would violate | 54 | /* We do not accept a shared mapping if it would violate |
55 | * cache aliasing constraints. | 55 | * cache aliasing constraints. |
56 | */ | 56 | */ |
57 | if ((flags & MAP_SHARED) && (addr & shm_align_mask)) | 57 | if ((flags & MAP_SHARED) && |
58 | ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask)) | ||
58 | return -EINVAL; | 59 | return -EINVAL; |
59 | return addr; | 60 | return addr; |
60 | } | 61 | } |
diff --git a/arch/sparc/kernel/sys_sparc32.c b/arch/sparc/kernel/sys_sparc32.c index 00abe87e5b51..dc0ac197e7e2 100644 --- a/arch/sparc/kernel/sys_sparc32.c +++ b/arch/sparc/kernel/sys_sparc32.c | |||
@@ -564,28 +564,6 @@ asmlinkage long sparc32_open(const char __user *filename, | |||
564 | return do_sys_open(AT_FDCWD, filename, flags, mode); | 564 | return do_sys_open(AT_FDCWD, filename, flags, mode); |
565 | } | 565 | } |
566 | 566 | ||
567 | extern unsigned long do_mremap(unsigned long addr, | ||
568 | unsigned long old_len, unsigned long new_len, | ||
569 | unsigned long flags, unsigned long new_addr); | ||
570 | |||
571 | asmlinkage unsigned long sys32_mremap(unsigned long addr, | ||
572 | unsigned long old_len, unsigned long new_len, | ||
573 | unsigned long flags, u32 __new_addr) | ||
574 | { | ||
575 | unsigned long ret = -EINVAL; | ||
576 | unsigned long new_addr = __new_addr; | ||
577 | |||
578 | if (unlikely(sparc_mmap_check(addr, old_len))) | ||
579 | goto out; | ||
580 | if (unlikely(sparc_mmap_check(new_addr, new_len))) | ||
581 | goto out; | ||
582 | down_write(¤t->mm->mmap_sem); | ||
583 | ret = do_mremap(addr, old_len, new_len, flags, new_addr); | ||
584 | up_write(¤t->mm->mmap_sem); | ||
585 | out: | ||
586 | return ret; | ||
587 | } | ||
588 | |||
589 | long sys32_lookup_dcookie(unsigned long cookie_high, | 567 | long sys32_lookup_dcookie(unsigned long cookie_high, |
590 | unsigned long cookie_low, | 568 | unsigned long cookie_low, |
591 | char __user *buf, size_t len) | 569 | char __user *buf, size_t len) |
diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c index 03035c852a43..3a82e65d8db2 100644 --- a/arch/sparc/kernel/sys_sparc_32.c +++ b/arch/sparc/kernel/sys_sparc_32.c | |||
@@ -45,7 +45,8 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi | |||
45 | /* We do not accept a shared mapping if it would violate | 45 | /* We do not accept a shared mapping if it would violate |
46 | * cache aliasing constraints. | 46 | * cache aliasing constraints. |
47 | */ | 47 | */ |
48 | if ((flags & MAP_SHARED) && (addr & (SHMLBA - 1))) | 48 | if ((flags & MAP_SHARED) && |
49 | ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) | ||
49 | return -EINVAL; | 50 | return -EINVAL; |
50 | return addr; | 51 | return addr; |
51 | } | 52 | } |
@@ -79,15 +80,6 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi | |||
79 | } | 80 | } |
80 | } | 81 | } |
81 | 82 | ||
82 | asmlinkage unsigned long sparc_brk(unsigned long brk) | ||
83 | { | ||
84 | if(ARCH_SUN4C) { | ||
85 | if ((brk & 0xe0000000) != (current->mm->brk & 0xe0000000)) | ||
86 | return current->mm->brk; | ||
87 | } | ||
88 | return sys_brk(brk); | ||
89 | } | ||
90 | |||
91 | /* | 83 | /* |
92 | * sys_pipe() is the normal C calling standard for creating | 84 | * sys_pipe() is the normal C calling standard for creating |
93 | * a pipe. It's not the way unix traditionally does this, though. | 85 | * a pipe. It's not the way unix traditionally does this, though. |
@@ -234,31 +226,6 @@ int sparc_mmap_check(unsigned long addr, unsigned long len) | |||
234 | } | 226 | } |
235 | 227 | ||
236 | /* Linux version of mmap */ | 228 | /* Linux version of mmap */ |
237 | static unsigned long do_mmap2(unsigned long addr, unsigned long len, | ||
238 | unsigned long prot, unsigned long flags, unsigned long fd, | ||
239 | unsigned long pgoff) | ||
240 | { | ||
241 | struct file * file = NULL; | ||
242 | unsigned long retval = -EBADF; | ||
243 | |||
244 | if (!(flags & MAP_ANONYMOUS)) { | ||
245 | file = fget(fd); | ||
246 | if (!file) | ||
247 | goto out; | ||
248 | } | ||
249 | |||
250 | len = PAGE_ALIGN(len); | ||
251 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
252 | |||
253 | down_write(¤t->mm->mmap_sem); | ||
254 | retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
255 | up_write(¤t->mm->mmap_sem); | ||
256 | |||
257 | if (file) | ||
258 | fput(file); | ||
259 | out: | ||
260 | return retval; | ||
261 | } | ||
262 | 229 | ||
263 | asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, | 230 | asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, |
264 | unsigned long prot, unsigned long flags, unsigned long fd, | 231 | unsigned long prot, unsigned long flags, unsigned long fd, |
@@ -266,14 +233,16 @@ asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, | |||
266 | { | 233 | { |
267 | /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE | 234 | /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE |
268 | we have. */ | 235 | we have. */ |
269 | return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT - 12)); | 236 | return sys_mmap_pgoff(addr, len, prot, flags, fd, |
237 | pgoff >> (PAGE_SHIFT - 12)); | ||
270 | } | 238 | } |
271 | 239 | ||
272 | asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, | 240 | asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, |
273 | unsigned long prot, unsigned long flags, unsigned long fd, | 241 | unsigned long prot, unsigned long flags, unsigned long fd, |
274 | unsigned long off) | 242 | unsigned long off) |
275 | { | 243 | { |
276 | return do_mmap2(addr, len, prot, flags, fd, off >> PAGE_SHIFT); | 244 | /* no alignment check? */ |
245 | return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); | ||
277 | } | 246 | } |
278 | 247 | ||
279 | long sparc_remap_file_pages(unsigned long start, unsigned long size, | 248 | long sparc_remap_file_pages(unsigned long start, unsigned long size, |
@@ -287,27 +256,6 @@ long sparc_remap_file_pages(unsigned long start, unsigned long size, | |||
287 | (pgoff >> (PAGE_SHIFT - 12)), flags); | 256 | (pgoff >> (PAGE_SHIFT - 12)), flags); |
288 | } | 257 | } |
289 | 258 | ||
290 | extern unsigned long do_mremap(unsigned long addr, | ||
291 | unsigned long old_len, unsigned long new_len, | ||
292 | unsigned long flags, unsigned long new_addr); | ||
293 | |||
294 | asmlinkage unsigned long sparc_mremap(unsigned long addr, | ||
295 | unsigned long old_len, unsigned long new_len, | ||
296 | unsigned long flags, unsigned long new_addr) | ||
297 | { | ||
298 | unsigned long ret = -EINVAL; | ||
299 | |||
300 | if (unlikely(sparc_mmap_check(addr, old_len))) | ||
301 | goto out; | ||
302 | if (unlikely(sparc_mmap_check(new_addr, new_len))) | ||
303 | goto out; | ||
304 | down_write(¤t->mm->mmap_sem); | ||
305 | ret = do_mremap(addr, old_len, new_len, flags, new_addr); | ||
306 | up_write(¤t->mm->mmap_sem); | ||
307 | out: | ||
308 | return ret; | ||
309 | } | ||
310 | |||
311 | /* we come to here via sys_nis_syscall so it can setup the regs argument */ | 259 | /* we come to here via sys_nis_syscall so it can setup the regs argument */ |
312 | asmlinkage unsigned long | 260 | asmlinkage unsigned long |
313 | c_sys_nis_syscall (struct pt_regs *regs) | 261 | c_sys_nis_syscall (struct pt_regs *regs) |
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index e2d102447a43..cfa0e19abe3b 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c | |||
@@ -317,10 +317,14 @@ bottomup: | |||
317 | unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags) | 317 | unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags) |
318 | { | 318 | { |
319 | unsigned long align_goal, addr = -ENOMEM; | 319 | unsigned long align_goal, addr = -ENOMEM; |
320 | unsigned long (*get_area)(struct file *, unsigned long, | ||
321 | unsigned long, unsigned long, unsigned long); | ||
322 | |||
323 | get_area = current->mm->get_unmapped_area; | ||
320 | 324 | ||
321 | if (flags & MAP_FIXED) { | 325 | if (flags & MAP_FIXED) { |
322 | /* Ok, don't mess with it. */ | 326 | /* Ok, don't mess with it. */ |
323 | return get_unmapped_area(NULL, orig_addr, len, pgoff, flags); | 327 | return get_area(NULL, orig_addr, len, pgoff, flags); |
324 | } | 328 | } |
325 | flags &= ~MAP_SHARED; | 329 | flags &= ~MAP_SHARED; |
326 | 330 | ||
@@ -333,7 +337,7 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u | |||
333 | align_goal = (64UL * 1024); | 337 | align_goal = (64UL * 1024); |
334 | 338 | ||
335 | do { | 339 | do { |
336 | addr = get_unmapped_area(NULL, orig_addr, len + (align_goal - PAGE_SIZE), pgoff, flags); | 340 | addr = get_area(NULL, orig_addr, len + (align_goal - PAGE_SIZE), pgoff, flags); |
337 | if (!(addr & ~PAGE_MASK)) { | 341 | if (!(addr & ~PAGE_MASK)) { |
338 | addr = (addr + (align_goal - 1UL)) & ~(align_goal - 1UL); | 342 | addr = (addr + (align_goal - 1UL)) & ~(align_goal - 1UL); |
339 | break; | 343 | break; |
@@ -351,7 +355,7 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u | |||
351 | * be obtained. | 355 | * be obtained. |
352 | */ | 356 | */ |
353 | if (addr & ~PAGE_MASK) | 357 | if (addr & ~PAGE_MASK) |
354 | addr = get_unmapped_area(NULL, orig_addr, len, pgoff, flags); | 358 | addr = get_area(NULL, orig_addr, len, pgoff, flags); |
355 | 359 | ||
356 | return addr; | 360 | return addr; |
357 | } | 361 | } |
@@ -399,18 +403,6 @@ void arch_pick_mmap_layout(struct mm_struct *mm) | |||
399 | } | 403 | } |
400 | } | 404 | } |
401 | 405 | ||
402 | SYSCALL_DEFINE1(sparc_brk, unsigned long, brk) | ||
403 | { | ||
404 | /* People could try to be nasty and use ta 0x6d in 32bit programs */ | ||
405 | if (test_thread_flag(TIF_32BIT) && brk >= STACK_TOP32) | ||
406 | return current->mm->brk; | ||
407 | |||
408 | if (unlikely(straddles_64bit_va_hole(current->mm->brk, brk))) | ||
409 | return current->mm->brk; | ||
410 | |||
411 | return sys_brk(brk); | ||
412 | } | ||
413 | |||
414 | /* | 406 | /* |
415 | * sys_pipe() is the normal C calling standard for creating | 407 | * sys_pipe() is the normal C calling standard for creating |
416 | * a pipe. It's not the way unix traditionally does this, though. | 408 | * a pipe. It's not the way unix traditionally does this, though. |
@@ -568,23 +560,13 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, | |||
568 | unsigned long, prot, unsigned long, flags, unsigned long, fd, | 560 | unsigned long, prot, unsigned long, flags, unsigned long, fd, |
569 | unsigned long, off) | 561 | unsigned long, off) |
570 | { | 562 | { |
571 | struct file * file = NULL; | 563 | unsigned long retval = -EINVAL; |
572 | unsigned long retval = -EBADF; | ||
573 | |||
574 | if (!(flags & MAP_ANONYMOUS)) { | ||
575 | file = fget(fd); | ||
576 | if (!file) | ||
577 | goto out; | ||
578 | } | ||
579 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
580 | len = PAGE_ALIGN(len); | ||
581 | 564 | ||
582 | down_write(¤t->mm->mmap_sem); | 565 | if ((off + PAGE_ALIGN(len)) < off) |
583 | retval = do_mmap(file, addr, len, prot, flags, off); | 566 | goto out; |
584 | up_write(¤t->mm->mmap_sem); | 567 | if (off & ~PAGE_MASK) |
585 | 568 | goto out; | |
586 | if (file) | 569 | retval = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); |
587 | fput(file); | ||
588 | out: | 570 | out: |
589 | return retval; | 571 | return retval; |
590 | } | 572 | } |
@@ -614,12 +596,6 @@ SYSCALL_DEFINE5(64_mremap, unsigned long, addr, unsigned long, old_len, | |||
614 | 596 | ||
615 | if (test_thread_flag(TIF_32BIT)) | 597 | if (test_thread_flag(TIF_32BIT)) |
616 | goto out; | 598 | goto out; |
617 | if (unlikely(new_len >= VA_EXCLUDE_START)) | ||
618 | goto out; | ||
619 | if (unlikely(sparc_mmap_check(addr, old_len))) | ||
620 | goto out; | ||
621 | if (unlikely(sparc_mmap_check(new_addr, new_len))) | ||
622 | goto out; | ||
623 | 599 | ||
624 | down_write(¤t->mm->mmap_sem); | 600 | down_write(¤t->mm->mmap_sem); |
625 | ret = do_mremap(addr, old_len, new_len, flags, new_addr); | 601 | ret = do_mremap(addr, old_len, new_len, flags, new_addr); |
diff --git a/arch/sparc/kernel/systbls.h b/arch/sparc/kernel/systbls.h index a63c5d2d9849..d2f999ae2b85 100644 --- a/arch/sparc/kernel/systbls.h +++ b/arch/sparc/kernel/systbls.h | |||
@@ -9,7 +9,6 @@ | |||
9 | struct new_utsname; | 9 | struct new_utsname; |
10 | 10 | ||
11 | extern asmlinkage unsigned long sys_getpagesize(void); | 11 | extern asmlinkage unsigned long sys_getpagesize(void); |
12 | extern asmlinkage unsigned long sparc_brk(unsigned long brk); | ||
13 | extern asmlinkage long sparc_pipe(struct pt_regs *regs); | 12 | extern asmlinkage long sparc_pipe(struct pt_regs *regs); |
14 | extern asmlinkage long sys_ipc(unsigned int call, int first, | 13 | extern asmlinkage long sys_ipc(unsigned int call, int first, |
15 | unsigned long second, | 14 | unsigned long second, |
diff --git a/arch/sparc/kernel/systbls_32.S b/arch/sparc/kernel/systbls_32.S index ceb1530f8aa6..801fc8e5a0e8 100644 --- a/arch/sparc/kernel/systbls_32.S +++ b/arch/sparc/kernel/systbls_32.S | |||
@@ -19,7 +19,7 @@ sys_call_table: | |||
19 | /*0*/ .long sys_restart_syscall, sys_exit, sys_fork, sys_read, sys_write | 19 | /*0*/ .long sys_restart_syscall, sys_exit, sys_fork, sys_read, sys_write |
20 | /*5*/ .long sys_open, sys_close, sys_wait4, sys_creat, sys_link | 20 | /*5*/ .long sys_open, sys_close, sys_wait4, sys_creat, sys_link |
21 | /*10*/ .long sys_unlink, sunos_execv, sys_chdir, sys_chown16, sys_mknod | 21 | /*10*/ .long sys_unlink, sunos_execv, sys_chdir, sys_chown16, sys_mknod |
22 | /*15*/ .long sys_chmod, sys_lchown16, sparc_brk, sys_nis_syscall, sys_lseek | 22 | /*15*/ .long sys_chmod, sys_lchown16, sys_brk, sys_nis_syscall, sys_lseek |
23 | /*20*/ .long sys_getpid, sys_capget, sys_capset, sys_setuid16, sys_getuid16 | 23 | /*20*/ .long sys_getpid, sys_capget, sys_capset, sys_setuid16, sys_getuid16 |
24 | /*25*/ .long sys_vmsplice, sys_ptrace, sys_alarm, sys_sigaltstack, sys_pause | 24 | /*25*/ .long sys_vmsplice, sys_ptrace, sys_alarm, sys_sigaltstack, sys_pause |
25 | /*30*/ .long sys_utime, sys_lchown, sys_fchown, sys_access, sys_nice | 25 | /*30*/ .long sys_utime, sys_lchown, sys_fchown, sys_access, sys_nice |
@@ -67,7 +67,7 @@ sys_call_table: | |||
67 | /*235*/ .long sys_fstatfs64, sys_llseek, sys_mlock, sys_munlock, sys_mlockall | 67 | /*235*/ .long sys_fstatfs64, sys_llseek, sys_mlock, sys_munlock, sys_mlockall |
68 | /*240*/ .long sys_munlockall, sys_sched_setparam, sys_sched_getparam, sys_sched_setscheduler, sys_sched_getscheduler | 68 | /*240*/ .long sys_munlockall, sys_sched_setparam, sys_sched_getparam, sys_sched_setscheduler, sys_sched_getscheduler |
69 | /*245*/ .long sys_sched_yield, sys_sched_get_priority_max, sys_sched_get_priority_min, sys_sched_rr_get_interval, sys_nanosleep | 69 | /*245*/ .long sys_sched_yield, sys_sched_get_priority_max, sys_sched_get_priority_min, sys_sched_rr_get_interval, sys_nanosleep |
70 | /*250*/ .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl | 70 | /*250*/ .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl |
71 | /*255*/ .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep | 71 | /*255*/ .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep |
72 | /*260*/ .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun | 72 | /*260*/ .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun |
73 | /*265*/ .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy | 73 | /*265*/ .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy |
diff --git a/arch/sparc/kernel/systbls_64.S b/arch/sparc/kernel/systbls_64.S index cc8e7862e95a..e575b46bd7a9 100644 --- a/arch/sparc/kernel/systbls_64.S +++ b/arch/sparc/kernel/systbls_64.S | |||
@@ -21,7 +21,7 @@ sys_call_table32: | |||
21 | /*0*/ .word sys_restart_syscall, sys32_exit, sys_fork, sys_read, sys_write | 21 | /*0*/ .word sys_restart_syscall, sys32_exit, sys_fork, sys_read, sys_write |
22 | /*5*/ .word sys32_open, sys_close, sys32_wait4, sys32_creat, sys_link | 22 | /*5*/ .word sys32_open, sys_close, sys32_wait4, sys32_creat, sys_link |
23 | /*10*/ .word sys_unlink, sunos_execv, sys_chdir, sys_chown16, sys32_mknod | 23 | /*10*/ .word sys_unlink, sunos_execv, sys_chdir, sys_chown16, sys32_mknod |
24 | /*15*/ .word sys_chmod, sys_lchown16, sys_sparc_brk, sys32_perfctr, sys32_lseek | 24 | /*15*/ .word sys_chmod, sys_lchown16, sys_brk, sys32_perfctr, sys32_lseek |
25 | /*20*/ .word sys_getpid, sys_capget, sys_capset, sys_setuid16, sys_getuid16 | 25 | /*20*/ .word sys_getpid, sys_capget, sys_capset, sys_setuid16, sys_getuid16 |
26 | /*25*/ .word sys32_vmsplice, compat_sys_ptrace, sys_alarm, sys32_sigaltstack, sys_pause | 26 | /*25*/ .word sys32_vmsplice, compat_sys_ptrace, sys_alarm, sys32_sigaltstack, sys_pause |
27 | /*30*/ .word compat_sys_utime, sys_lchown, sys_fchown, sys32_access, sys32_nice | 27 | /*30*/ .word compat_sys_utime, sys_lchown, sys_fchown, sys32_access, sys32_nice |
@@ -68,7 +68,7 @@ sys_call_table32: | |||
68 | .word compat_sys_fstatfs64, sys_llseek, sys_mlock, sys_munlock, sys32_mlockall | 68 | .word compat_sys_fstatfs64, sys_llseek, sys_mlock, sys_munlock, sys32_mlockall |
69 | /*240*/ .word sys_munlockall, sys32_sched_setparam, sys32_sched_getparam, sys32_sched_setscheduler, sys32_sched_getscheduler | 69 | /*240*/ .word sys_munlockall, sys32_sched_setparam, sys32_sched_getparam, sys32_sched_setscheduler, sys32_sched_getscheduler |
70 | .word sys_sched_yield, sys32_sched_get_priority_max, sys32_sched_get_priority_min, sys32_sched_rr_get_interval, compat_sys_nanosleep | 70 | .word sys_sched_yield, sys32_sched_get_priority_max, sys32_sched_get_priority_min, sys32_sched_rr_get_interval, compat_sys_nanosleep |
71 | /*250*/ .word sys32_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl | 71 | /*250*/ .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl |
72 | .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep | 72 | .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep |
73 | /*260*/ .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun | 73 | /*260*/ .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun |
74 | .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy | 74 | .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy |
@@ -96,7 +96,7 @@ sys_call_table: | |||
96 | /*0*/ .word sys_restart_syscall, sparc_exit, sys_fork, sys_read, sys_write | 96 | /*0*/ .word sys_restart_syscall, sparc_exit, sys_fork, sys_read, sys_write |
97 | /*5*/ .word sys_open, sys_close, sys_wait4, sys_creat, sys_link | 97 | /*5*/ .word sys_open, sys_close, sys_wait4, sys_creat, sys_link |
98 | /*10*/ .word sys_unlink, sys_nis_syscall, sys_chdir, sys_chown, sys_mknod | 98 | /*10*/ .word sys_unlink, sys_nis_syscall, sys_chdir, sys_chown, sys_mknod |
99 | /*15*/ .word sys_chmod, sys_lchown, sys_sparc_brk, sys_perfctr, sys_lseek | 99 | /*15*/ .word sys_chmod, sys_lchown, sys_brk, sys_perfctr, sys_lseek |
100 | /*20*/ .word sys_getpid, sys_capget, sys_capset, sys_setuid, sys_getuid | 100 | /*20*/ .word sys_getpid, sys_capget, sys_capset, sys_setuid, sys_getuid |
101 | /*25*/ .word sys_vmsplice, sys_ptrace, sys_alarm, sys_sigaltstack, sys_nis_syscall | 101 | /*25*/ .word sys_vmsplice, sys_ptrace, sys_alarm, sys_sigaltstack, sys_nis_syscall |
102 | /*30*/ .word sys_utime, sys_nis_syscall, sys_nis_syscall, sys_access, sys_nice | 102 | /*30*/ .word sys_utime, sys_nis_syscall, sys_nis_syscall, sys_access, sys_nice |
diff --git a/arch/um/kernel/syscall.c b/arch/um/kernel/syscall.c index a4625c7b2bf9..cccab850c27e 100644 --- a/arch/um/kernel/syscall.c +++ b/arch/um/kernel/syscall.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "linux/mm.h" | 8 | #include "linux/mm.h" |
9 | #include "linux/sched.h" | 9 | #include "linux/sched.h" |
10 | #include "linux/utsname.h" | 10 | #include "linux/utsname.h" |
11 | #include "linux/syscalls.h" | ||
11 | #include "asm/current.h" | 12 | #include "asm/current.h" |
12 | #include "asm/mman.h" | 13 | #include "asm/mman.h" |
13 | #include "asm/uaccess.h" | 14 | #include "asm/uaccess.h" |
@@ -37,31 +38,6 @@ long sys_vfork(void) | |||
37 | return ret; | 38 | return ret; |
38 | } | 39 | } |
39 | 40 | ||
40 | /* common code for old and new mmaps */ | ||
41 | long sys_mmap2(unsigned long addr, unsigned long len, | ||
42 | unsigned long prot, unsigned long flags, | ||
43 | unsigned long fd, unsigned long pgoff) | ||
44 | { | ||
45 | long error = -EBADF; | ||
46 | struct file * file = NULL; | ||
47 | |||
48 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
49 | if (!(flags & MAP_ANONYMOUS)) { | ||
50 | file = fget(fd); | ||
51 | if (!file) | ||
52 | goto out; | ||
53 | } | ||
54 | |||
55 | down_write(¤t->mm->mmap_sem); | ||
56 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
57 | up_write(¤t->mm->mmap_sem); | ||
58 | |||
59 | if (file) | ||
60 | fput(file); | ||
61 | out: | ||
62 | return error; | ||
63 | } | ||
64 | |||
65 | long old_mmap(unsigned long addr, unsigned long len, | 41 | long old_mmap(unsigned long addr, unsigned long len, |
66 | unsigned long prot, unsigned long flags, | 42 | unsigned long prot, unsigned long flags, |
67 | unsigned long fd, unsigned long offset) | 43 | unsigned long fd, unsigned long offset) |
@@ -70,7 +46,7 @@ long old_mmap(unsigned long addr, unsigned long len, | |||
70 | if (offset & ~PAGE_MASK) | 46 | if (offset & ~PAGE_MASK) |
71 | goto out; | 47 | goto out; |
72 | 48 | ||
73 | err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); | 49 | err = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
74 | out: | 50 | out: |
75 | return err; | 51 | return err; |
76 | } | 52 | } |
diff --git a/arch/um/sys-i386/shared/sysdep/syscalls.h b/arch/um/sys-i386/shared/sysdep/syscalls.h index 905698197e35..e7787679e317 100644 --- a/arch/um/sys-i386/shared/sysdep/syscalls.h +++ b/arch/um/sys-i386/shared/sysdep/syscalls.h | |||
@@ -20,7 +20,3 @@ extern syscall_handler_t *sys_call_table[]; | |||
20 | #define EXECUTE_SYSCALL(syscall, regs) \ | 20 | #define EXECUTE_SYSCALL(syscall, regs) \ |
21 | ((long (*)(struct syscall_args)) \ | 21 | ((long (*)(struct syscall_args)) \ |
22 | (*sys_call_table[syscall]))(SYSCALL_ARGS(®s->regs)) | 22 | (*sys_call_table[syscall]))(SYSCALL_ARGS(®s->regs)) |
23 | |||
24 | extern long sys_mmap2(unsigned long addr, unsigned long len, | ||
25 | unsigned long prot, unsigned long flags, | ||
26 | unsigned long fd, unsigned long pgoff); | ||
diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S index 4eefdca9832b..53147ad85b96 100644 --- a/arch/x86/ia32/ia32entry.S +++ b/arch/x86/ia32/ia32entry.S | |||
@@ -696,7 +696,7 @@ ia32_sys_call_table: | |||
696 | .quad quiet_ni_syscall /* streams2 */ | 696 | .quad quiet_ni_syscall /* streams2 */ |
697 | .quad stub32_vfork /* 190 */ | 697 | .quad stub32_vfork /* 190 */ |
698 | .quad compat_sys_getrlimit | 698 | .quad compat_sys_getrlimit |
699 | .quad sys32_mmap2 | 699 | .quad sys_mmap_pgoff |
700 | .quad sys32_truncate64 | 700 | .quad sys32_truncate64 |
701 | .quad sys32_ftruncate64 | 701 | .quad sys32_ftruncate64 |
702 | .quad sys32_stat64 /* 195 */ | 702 | .quad sys32_stat64 /* 195 */ |
diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c index df82c0e48ded..422572c77923 100644 --- a/arch/x86/ia32/sys_ia32.c +++ b/arch/x86/ia32/sys_ia32.c | |||
@@ -155,9 +155,6 @@ struct mmap_arg_struct { | |||
155 | asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg) | 155 | asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg) |
156 | { | 156 | { |
157 | struct mmap_arg_struct a; | 157 | struct mmap_arg_struct a; |
158 | struct file *file = NULL; | ||
159 | unsigned long retval; | ||
160 | struct mm_struct *mm ; | ||
161 | 158 | ||
162 | if (copy_from_user(&a, arg, sizeof(a))) | 159 | if (copy_from_user(&a, arg, sizeof(a))) |
163 | return -EFAULT; | 160 | return -EFAULT; |
@@ -165,22 +162,8 @@ asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg) | |||
165 | if (a.offset & ~PAGE_MASK) | 162 | if (a.offset & ~PAGE_MASK) |
166 | return -EINVAL; | 163 | return -EINVAL; |
167 | 164 | ||
168 | if (!(a.flags & MAP_ANONYMOUS)) { | 165 | return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, |
169 | file = fget(a.fd); | ||
170 | if (!file) | ||
171 | return -EBADF; | ||
172 | } | ||
173 | |||
174 | mm = current->mm; | ||
175 | down_write(&mm->mmap_sem); | ||
176 | retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, | ||
177 | a.offset>>PAGE_SHIFT); | 166 | a.offset>>PAGE_SHIFT); |
178 | if (file) | ||
179 | fput(file); | ||
180 | |||
181 | up_write(&mm->mmap_sem); | ||
182 | |||
183 | return retval; | ||
184 | } | 167 | } |
185 | 168 | ||
186 | asmlinkage long sys32_mprotect(unsigned long start, size_t len, | 169 | asmlinkage long sys32_mprotect(unsigned long start, size_t len, |
@@ -483,30 +466,6 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd, | |||
483 | return ret; | 466 | return ret; |
484 | } | 467 | } |
485 | 468 | ||
486 | asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len, | ||
487 | unsigned long prot, unsigned long flags, | ||
488 | unsigned long fd, unsigned long pgoff) | ||
489 | { | ||
490 | struct mm_struct *mm = current->mm; | ||
491 | unsigned long error; | ||
492 | struct file *file = NULL; | ||
493 | |||
494 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
495 | if (!(flags & MAP_ANONYMOUS)) { | ||
496 | file = fget(fd); | ||
497 | if (!file) | ||
498 | return -EBADF; | ||
499 | } | ||
500 | |||
501 | down_write(&mm->mmap_sem); | ||
502 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
503 | up_write(&mm->mmap_sem); | ||
504 | |||
505 | if (file) | ||
506 | fput(file); | ||
507 | return error; | ||
508 | } | ||
509 | |||
510 | asmlinkage long sys32_olduname(struct oldold_utsname __user *name) | 469 | asmlinkage long sys32_olduname(struct oldold_utsname __user *name) |
511 | { | 470 | { |
512 | char *arch = "x86_64"; | 471 | char *arch = "x86_64"; |
diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h index 9af9decb38c3..4a5a089e1c62 100644 --- a/arch/x86/include/asm/sys_ia32.h +++ b/arch/x86/include/asm/sys_ia32.h | |||
@@ -57,9 +57,6 @@ asmlinkage long sys32_pwrite(unsigned int, char __user *, u32, u32, u32); | |||
57 | asmlinkage long sys32_personality(unsigned long); | 57 | asmlinkage long sys32_personality(unsigned long); |
58 | asmlinkage long sys32_sendfile(int, int, compat_off_t __user *, s32); | 58 | asmlinkage long sys32_sendfile(int, int, compat_off_t __user *, s32); |
59 | 59 | ||
60 | asmlinkage long sys32_mmap2(unsigned long, unsigned long, unsigned long, | ||
61 | unsigned long, unsigned long, unsigned long); | ||
62 | |||
63 | struct oldold_utsname; | 60 | struct oldold_utsname; |
64 | struct old_utsname; | 61 | struct old_utsname; |
65 | asmlinkage long sys32_olduname(struct oldold_utsname __user *); | 62 | asmlinkage long sys32_olduname(struct oldold_utsname __user *); |
diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h index 372b76edd63f..1bb6e395881c 100644 --- a/arch/x86/include/asm/syscalls.h +++ b/arch/x86/include/asm/syscalls.h | |||
@@ -55,8 +55,6 @@ struct sel_arg_struct; | |||
55 | struct oldold_utsname; | 55 | struct oldold_utsname; |
56 | struct old_utsname; | 56 | struct old_utsname; |
57 | 57 | ||
58 | asmlinkage long sys_mmap2(unsigned long, unsigned long, unsigned long, | ||
59 | unsigned long, unsigned long, unsigned long); | ||
60 | asmlinkage int old_mmap(struct mmap_arg_struct __user *); | 58 | asmlinkage int old_mmap(struct mmap_arg_struct __user *); |
61 | asmlinkage int old_select(struct sel_arg_struct __user *); | 59 | asmlinkage int old_select(struct sel_arg_struct __user *); |
62 | asmlinkage int sys_ipc(uint, int, int, int, void __user *, long); | 60 | asmlinkage int sys_ipc(uint, int, int, int, void __user *, long); |
diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c index 1884a8d12bfa..dee1ff7cba58 100644 --- a/arch/x86/kernel/sys_i386_32.c +++ b/arch/x86/kernel/sys_i386_32.c | |||
@@ -24,31 +24,6 @@ | |||
24 | 24 | ||
25 | #include <asm/syscalls.h> | 25 | #include <asm/syscalls.h> |
26 | 26 | ||
27 | asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, | ||
28 | unsigned long prot, unsigned long flags, | ||
29 | unsigned long fd, unsigned long pgoff) | ||
30 | { | ||
31 | int error = -EBADF; | ||
32 | struct file *file = NULL; | ||
33 | struct mm_struct *mm = current->mm; | ||
34 | |||
35 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
36 | if (!(flags & MAP_ANONYMOUS)) { | ||
37 | file = fget(fd); | ||
38 | if (!file) | ||
39 | goto out; | ||
40 | } | ||
41 | |||
42 | down_write(&mm->mmap_sem); | ||
43 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
44 | up_write(&mm->mmap_sem); | ||
45 | |||
46 | if (file) | ||
47 | fput(file); | ||
48 | out: | ||
49 | return error; | ||
50 | } | ||
51 | |||
52 | /* | 27 | /* |
53 | * Perform the select(nd, in, out, ex, tv) and mmap() system | 28 | * Perform the select(nd, in, out, ex, tv) and mmap() system |
54 | * calls. Linux/i386 didn't use to be able to handle more than | 29 | * 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) | |||
77 | if (a.offset & ~PAGE_MASK) | 52 | if (a.offset & ~PAGE_MASK) |
78 | goto out; | 53 | goto out; |
79 | 54 | ||
80 | err = sys_mmap2(a.addr, a.len, a.prot, a.flags, | 55 | err = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, |
81 | a.fd, a.offset >> PAGE_SHIFT); | 56 | a.fd, a.offset >> PAGE_SHIFT); |
82 | out: | 57 | out: |
83 | return err; | 58 | return err; |
diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c index 45e00eb09c3a..8aa2057efd12 100644 --- a/arch/x86/kernel/sys_x86_64.c +++ b/arch/x86/kernel/sys_x86_64.c | |||
@@ -23,26 +23,11 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, | |||
23 | unsigned long, fd, unsigned long, off) | 23 | unsigned long, fd, unsigned long, off) |
24 | { | 24 | { |
25 | long error; | 25 | long error; |
26 | struct file *file; | ||
27 | |||
28 | error = -EINVAL; | 26 | error = -EINVAL; |
29 | if (off & ~PAGE_MASK) | 27 | if (off & ~PAGE_MASK) |
30 | goto out; | 28 | goto out; |
31 | 29 | ||
32 | error = -EBADF; | 30 | error = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); |
33 | file = NULL; | ||
34 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
35 | if (!(flags & MAP_ANONYMOUS)) { | ||
36 | file = fget(fd); | ||
37 | if (!file) | ||
38 | goto out; | ||
39 | } | ||
40 | down_write(¤t->mm->mmap_sem); | ||
41 | error = do_mmap_pgoff(file, addr, len, prot, flags, off >> PAGE_SHIFT); | ||
42 | up_write(¤t->mm->mmap_sem); | ||
43 | |||
44 | if (file) | ||
45 | fput(file); | ||
46 | out: | 31 | out: |
47 | return error; | 32 | return error; |
48 | } | 33 | } |
diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S index 70c2125d55b9..15228b5d3eb7 100644 --- a/arch/x86/kernel/syscall_table_32.S +++ b/arch/x86/kernel/syscall_table_32.S | |||
@@ -191,7 +191,7 @@ ENTRY(sys_call_table) | |||
191 | .long sys_ni_syscall /* reserved for streams2 */ | 191 | .long sys_ni_syscall /* reserved for streams2 */ |
192 | .long ptregs_vfork /* 190 */ | 192 | .long ptregs_vfork /* 190 */ |
193 | .long sys_getrlimit | 193 | .long sys_getrlimit |
194 | .long sys_mmap2 | 194 | .long sys_mmap_pgoff |
195 | .long sys_truncate64 | 195 | .long sys_truncate64 |
196 | .long sys_ftruncate64 | 196 | .long sys_ftruncate64 |
197 | .long sys_stat64 /* 195 */ | 197 | .long sys_stat64 /* 195 */ |
diff --git a/arch/xtensa/include/asm/syscall.h b/arch/xtensa/include/asm/syscall.h index 05cebf8f62b1..4352dbe1186a 100644 --- a/arch/xtensa/include/asm/syscall.h +++ b/arch/xtensa/include/asm/syscall.h | |||
@@ -13,8 +13,6 @@ struct sigaction; | |||
13 | asmlinkage long xtensa_execve(char*, char**, char**, struct pt_regs*); | 13 | asmlinkage long xtensa_execve(char*, char**, char**, struct pt_regs*); |
14 | asmlinkage long xtensa_clone(unsigned long, unsigned long, struct pt_regs*); | 14 | asmlinkage long xtensa_clone(unsigned long, unsigned long, struct pt_regs*); |
15 | asmlinkage long xtensa_pipe(int __user *); | 15 | asmlinkage long xtensa_pipe(int __user *); |
16 | asmlinkage long xtensa_mmap2(unsigned long, unsigned long, unsigned long, | ||
17 | unsigned long, unsigned long, unsigned long); | ||
18 | asmlinkage long xtensa_ptrace(long, long, long, long); | 16 | asmlinkage long xtensa_ptrace(long, long, long, long); |
19 | asmlinkage long xtensa_sigreturn(struct pt_regs*); | 17 | asmlinkage long xtensa_sigreturn(struct pt_regs*); |
20 | asmlinkage long xtensa_rt_sigreturn(struct pt_regs*); | 18 | asmlinkage long xtensa_rt_sigreturn(struct pt_regs*); |
diff --git a/arch/xtensa/include/asm/unistd.h b/arch/xtensa/include/asm/unistd.h index 4e55dc763021..fbf318b3af3e 100644 --- a/arch/xtensa/include/asm/unistd.h +++ b/arch/xtensa/include/asm/unistd.h | |||
@@ -189,7 +189,7 @@ __SYSCALL( 79, sys_fremovexattr, 2) | |||
189 | /* File Map / Shared Memory Operations */ | 189 | /* File Map / Shared Memory Operations */ |
190 | 190 | ||
191 | #define __NR_mmap2 80 | 191 | #define __NR_mmap2 80 |
192 | __SYSCALL( 80, xtensa_mmap2, 6) | 192 | __SYSCALL( 80, sys_mmap_pgoff, 6) |
193 | #define __NR_munmap 81 | 193 | #define __NR_munmap 81 |
194 | __SYSCALL( 81, sys_munmap, 2) | 194 | __SYSCALL( 81, sys_munmap, 2) |
195 | #define __NR_mprotect 82 | 195 | #define __NR_mprotect 82 |
diff --git a/arch/xtensa/kernel/syscall.c b/arch/xtensa/kernel/syscall.c index ac15ecbdf919..1e67bab775c1 100644 --- a/arch/xtensa/kernel/syscall.c +++ b/arch/xtensa/kernel/syscall.c | |||
@@ -57,31 +57,6 @@ asmlinkage long xtensa_pipe(int __user *userfds) | |||
57 | return error; | 57 | return error; |
58 | } | 58 | } |
59 | 59 | ||
60 | |||
61 | asmlinkage long xtensa_mmap2(unsigned long addr, unsigned long len, | ||
62 | unsigned long prot, unsigned long flags, | ||
63 | unsigned long fd, unsigned long pgoff) | ||
64 | { | ||
65 | int error = -EBADF; | ||
66 | struct file * file = NULL; | ||
67 | |||
68 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
69 | if (!(flags & MAP_ANONYMOUS)) { | ||
70 | file = fget(fd); | ||
71 | if (!file) | ||
72 | goto out; | ||
73 | } | ||
74 | |||
75 | down_write(¤t->mm->mmap_sem); | ||
76 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
77 | up_write(¤t->mm->mmap_sem); | ||
78 | |||
79 | if (file) | ||
80 | fput(file); | ||
81 | out: | ||
82 | return error; | ||
83 | } | ||
84 | |||
85 | asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg) | 60 | asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg) |
86 | { | 61 | { |
87 | unsigned long ret; | 62 | unsigned long ret; |
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index bc70c5810fec..939a61507ac5 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h | |||
@@ -834,4 +834,8 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[]); | |||
834 | asmlinkage long sys_perf_event_open( | 834 | asmlinkage long sys_perf_event_open( |
835 | struct perf_event_attr __user *attr_uptr, | 835 | struct perf_event_attr __user *attr_uptr, |
836 | pid_t pid, int cpu, int group_fd, unsigned long flags); | 836 | pid_t pid, int cpu, int group_fd, unsigned long flags); |
837 | |||
838 | asmlinkage long sys_mmap_pgoff(unsigned long addr, unsigned long len, | ||
839 | unsigned long prot, unsigned long flags, | ||
840 | unsigned long fd, unsigned long pgoff); | ||
837 | #endif | 841 | #endif |
@@ -290,28 +290,28 @@ static unsigned long shm_get_unmapped_area(struct file *file, | |||
290 | unsigned long flags) | 290 | unsigned long flags) |
291 | { | 291 | { |
292 | struct shm_file_data *sfd = shm_file_data(file); | 292 | struct shm_file_data *sfd = shm_file_data(file); |
293 | return get_unmapped_area(sfd->file, addr, len, pgoff, flags); | 293 | return sfd->file->f_op->get_unmapped_area(sfd->file, addr, len, |
294 | } | 294 | pgoff, flags); |
295 | |||
296 | int is_file_shm_hugepages(struct file *file) | ||
297 | { | ||
298 | int ret = 0; | ||
299 | |||
300 | if (file->f_op == &shm_file_operations) { | ||
301 | struct shm_file_data *sfd; | ||
302 | sfd = shm_file_data(file); | ||
303 | ret = is_file_hugepages(sfd->file); | ||
304 | } | ||
305 | return ret; | ||
306 | } | 295 | } |
307 | 296 | ||
308 | static const struct file_operations shm_file_operations = { | 297 | static const struct file_operations shm_file_operations = { |
309 | .mmap = shm_mmap, | 298 | .mmap = shm_mmap, |
310 | .fsync = shm_fsync, | 299 | .fsync = shm_fsync, |
311 | .release = shm_release, | 300 | .release = shm_release, |
301 | }; | ||
302 | |||
303 | static const struct file_operations shm_file_operations_huge = { | ||
304 | .mmap = shm_mmap, | ||
305 | .fsync = shm_fsync, | ||
306 | .release = shm_release, | ||
312 | .get_unmapped_area = shm_get_unmapped_area, | 307 | .get_unmapped_area = shm_get_unmapped_area, |
313 | }; | 308 | }; |
314 | 309 | ||
310 | int is_file_shm_hugepages(struct file *file) | ||
311 | { | ||
312 | return file->f_op == &shm_file_operations_huge; | ||
313 | } | ||
314 | |||
315 | static const struct vm_operations_struct shm_vm_ops = { | 315 | static const struct vm_operations_struct shm_vm_ops = { |
316 | .open = shm_open, /* callback for a new vm-area open */ | 316 | .open = shm_open, /* callback for a new vm-area open */ |
317 | .close = shm_close, /* callback for when the vm-area is released */ | 317 | .close = shm_close, /* callback for when the vm-area is released */ |
@@ -889,7 +889,10 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr) | |||
889 | if (!sfd) | 889 | if (!sfd) |
890 | goto out_put_dentry; | 890 | goto out_put_dentry; |
891 | 891 | ||
892 | file = alloc_file(path.mnt, path.dentry, f_mode, &shm_file_operations); | 892 | file = alloc_file(path.mnt, path.dentry, f_mode, |
893 | is_file_hugepages(shp->shm_file) ? | ||
894 | &shm_file_operations_huge : | ||
895 | &shm_file_operations); | ||
893 | if (!file) | 896 | if (!file) |
894 | goto out_free; | 897 | goto out_free; |
895 | ima_counts_get(file); | 898 | ima_counts_get(file); |
@@ -931,13 +931,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, | |||
931 | if (!(flags & MAP_FIXED)) | 931 | if (!(flags & MAP_FIXED)) |
932 | addr = round_hint_to_min(addr); | 932 | addr = round_hint_to_min(addr); |
933 | 933 | ||
934 | error = arch_mmap_check(addr, len, flags); | ||
935 | if (error) | ||
936 | return error; | ||
937 | |||
938 | /* Careful about overflows.. */ | 934 | /* Careful about overflows.. */ |
939 | len = PAGE_ALIGN(len); | 935 | len = PAGE_ALIGN(len); |
940 | if (!len || len > TASK_SIZE) | 936 | if (!len) |
941 | return -ENOMEM; | 937 | return -ENOMEM; |
942 | 938 | ||
943 | /* offset overflow? */ | 939 | /* offset overflow? */ |
@@ -948,24 +944,6 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, | |||
948 | if (mm->map_count > sysctl_max_map_count) | 944 | if (mm->map_count > sysctl_max_map_count) |
949 | return -ENOMEM; | 945 | return -ENOMEM; |
950 | 946 | ||
951 | if (flags & MAP_HUGETLB) { | ||
952 | struct user_struct *user = NULL; | ||
953 | if (file) | ||
954 | return -EINVAL; | ||
955 | |||
956 | /* | ||
957 | * VM_NORESERVE is used because the reservations will be | ||
958 | * taken when vm_ops->mmap() is called | ||
959 | * A dummy user value is used because we are not locking | ||
960 | * memory so no accounting is necessary | ||
961 | */ | ||
962 | len = ALIGN(len, huge_page_size(&default_hstate)); | ||
963 | file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE, | ||
964 | &user, HUGETLB_ANONHUGE_INODE); | ||
965 | if (IS_ERR(file)) | ||
966 | return PTR_ERR(file); | ||
967 | } | ||
968 | |||
969 | /* Obtain the address to map to. we verify (or select) it and ensure | 947 | /* Obtain the address to map to. we verify (or select) it and ensure |
970 | * that it represents a valid section of the address space. | 948 | * that it represents a valid section of the address space. |
971 | */ | 949 | */ |
@@ -1455,6 +1433,14 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, | |||
1455 | unsigned long (*get_area)(struct file *, unsigned long, | 1433 | unsigned long (*get_area)(struct file *, unsigned long, |
1456 | unsigned long, unsigned long, unsigned long); | 1434 | unsigned long, unsigned long, unsigned long); |
1457 | 1435 | ||
1436 | unsigned long error = arch_mmap_check(addr, len, flags); | ||
1437 | if (error) | ||
1438 | return error; | ||
1439 | |||
1440 | /* Careful about overflows.. */ | ||
1441 | if (len > TASK_SIZE) | ||
1442 | return -ENOMEM; | ||
1443 | |||
1458 | get_area = current->mm->get_unmapped_area; | 1444 | get_area = current->mm->get_unmapped_area; |
1459 | if (file && file->f_op && file->f_op->get_unmapped_area) | 1445 | if (file && file->f_op && file->f_op->get_unmapped_area) |
1460 | get_area = file->f_op->get_unmapped_area; | 1446 | get_area = file->f_op->get_unmapped_area; |
@@ -1999,20 +1985,14 @@ unsigned long do_brk(unsigned long addr, unsigned long len) | |||
1999 | if (!len) | 1985 | if (!len) |
2000 | return addr; | 1986 | return addr; |
2001 | 1987 | ||
2002 | if ((addr + len) > TASK_SIZE || (addr + len) < addr) | ||
2003 | return -EINVAL; | ||
2004 | |||
2005 | if (is_hugepage_only_range(mm, addr, len)) | ||
2006 | return -EINVAL; | ||
2007 | |||
2008 | error = security_file_mmap(NULL, 0, 0, 0, addr, 1); | 1988 | error = security_file_mmap(NULL, 0, 0, 0, addr, 1); |
2009 | if (error) | 1989 | if (error) |
2010 | return error; | 1990 | return error; |
2011 | 1991 | ||
2012 | flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags; | 1992 | flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags; |
2013 | 1993 | ||
2014 | error = arch_mmap_check(addr, len, flags); | 1994 | error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED); |
2015 | if (error) | 1995 | if (error & ~PAGE_MASK) |
2016 | return error; | 1996 | return error; |
2017 | 1997 | ||
2018 | /* | 1998 | /* |
diff --git a/mm/mremap.c b/mm/mremap.c index 97bff2547719..845190898d59 100644 --- a/mm/mremap.c +++ b/mm/mremap.c | |||
@@ -261,6 +261,137 @@ static unsigned long move_vma(struct vm_area_struct *vma, | |||
261 | return new_addr; | 261 | return new_addr; |
262 | } | 262 | } |
263 | 263 | ||
264 | static struct vm_area_struct *vma_to_resize(unsigned long addr, | ||
265 | unsigned long old_len, unsigned long new_len, unsigned long *p) | ||
266 | { | ||
267 | struct mm_struct *mm = current->mm; | ||
268 | struct vm_area_struct *vma = find_vma(mm, addr); | ||
269 | |||
270 | if (!vma || vma->vm_start > addr) | ||
271 | goto Efault; | ||
272 | |||
273 | if (is_vm_hugetlb_page(vma)) | ||
274 | goto Einval; | ||
275 | |||
276 | /* We can't remap across vm area boundaries */ | ||
277 | if (old_len > vma->vm_end - addr) | ||
278 | goto Efault; | ||
279 | |||
280 | if (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP)) { | ||
281 | if (new_len > old_len) | ||
282 | goto Efault; | ||
283 | } | ||
284 | |||
285 | if (vma->vm_flags & VM_LOCKED) { | ||
286 | unsigned long locked, lock_limit; | ||
287 | locked = mm->locked_vm << PAGE_SHIFT; | ||
288 | lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur; | ||
289 | locked += new_len - old_len; | ||
290 | if (locked > lock_limit && !capable(CAP_IPC_LOCK)) | ||
291 | goto Eagain; | ||
292 | } | ||
293 | |||
294 | if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) | ||
295 | goto Enomem; | ||
296 | |||
297 | if (vma->vm_flags & VM_ACCOUNT) { | ||
298 | unsigned long charged = (new_len - old_len) >> PAGE_SHIFT; | ||
299 | if (security_vm_enough_memory(charged)) | ||
300 | goto Efault; | ||
301 | *p = charged; | ||
302 | } | ||
303 | |||
304 | return vma; | ||
305 | |||
306 | Efault: /* very odd choice for most of the cases, but... */ | ||
307 | return ERR_PTR(-EFAULT); | ||
308 | Einval: | ||
309 | return ERR_PTR(-EINVAL); | ||
310 | Enomem: | ||
311 | return ERR_PTR(-ENOMEM); | ||
312 | Eagain: | ||
313 | return ERR_PTR(-EAGAIN); | ||
314 | } | ||
315 | |||
316 | static unsigned long mremap_to(unsigned long addr, | ||
317 | unsigned long old_len, unsigned long new_addr, | ||
318 | unsigned long new_len) | ||
319 | { | ||
320 | struct mm_struct *mm = current->mm; | ||
321 | struct vm_area_struct *vma; | ||
322 | unsigned long ret = -EINVAL; | ||
323 | unsigned long charged = 0; | ||
324 | unsigned long map_flags; | ||
325 | |||
326 | if (new_addr & ~PAGE_MASK) | ||
327 | goto out; | ||
328 | |||
329 | if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len) | ||
330 | goto out; | ||
331 | |||
332 | /* Check if the location we're moving into overlaps the | ||
333 | * old location at all, and fail if it does. | ||
334 | */ | ||
335 | if ((new_addr <= addr) && (new_addr+new_len) > addr) | ||
336 | goto out; | ||
337 | |||
338 | if ((addr <= new_addr) && (addr+old_len) > new_addr) | ||
339 | goto out; | ||
340 | |||
341 | ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1); | ||
342 | if (ret) | ||
343 | goto out; | ||
344 | |||
345 | ret = do_munmap(mm, new_addr, new_len); | ||
346 | if (ret) | ||
347 | goto out; | ||
348 | |||
349 | if (old_len >= new_len) { | ||
350 | ret = do_munmap(mm, addr+new_len, old_len - new_len); | ||
351 | if (ret && old_len != new_len) | ||
352 | goto out; | ||
353 | old_len = new_len; | ||
354 | } | ||
355 | |||
356 | vma = vma_to_resize(addr, old_len, new_len, &charged); | ||
357 | if (IS_ERR(vma)) { | ||
358 | ret = PTR_ERR(vma); | ||
359 | goto out; | ||
360 | } | ||
361 | |||
362 | map_flags = MAP_FIXED; | ||
363 | if (vma->vm_flags & VM_MAYSHARE) | ||
364 | map_flags |= MAP_SHARED; | ||
365 | |||
366 | ret = get_unmapped_area(vma->vm_file, new_addr, new_len, vma->vm_pgoff + | ||
367 | ((addr - vma->vm_start) >> PAGE_SHIFT), | ||
368 | map_flags); | ||
369 | if (ret & ~PAGE_MASK) | ||
370 | goto out1; | ||
371 | |||
372 | ret = move_vma(vma, addr, old_len, new_len, new_addr); | ||
373 | if (!(ret & ~PAGE_MASK)) | ||
374 | goto out; | ||
375 | out1: | ||
376 | vm_unacct_memory(charged); | ||
377 | |||
378 | out: | ||
379 | return ret; | ||
380 | } | ||
381 | |||
382 | static int vma_expandable(struct vm_area_struct *vma, unsigned long delta) | ||
383 | { | ||
384 | unsigned long end = vma->vm_end + delta; | ||
385 | if (end < vma->vm_end) /* overflow */ | ||
386 | return 0; | ||
387 | if (vma->vm_next && vma->vm_next->vm_start < end) /* intersection */ | ||
388 | return 0; | ||
389 | if (get_unmapped_area(NULL, vma->vm_start, end - vma->vm_start, | ||
390 | 0, MAP_FIXED) & ~PAGE_MASK) | ||
391 | return 0; | ||
392 | return 1; | ||
393 | } | ||
394 | |||
264 | /* | 395 | /* |
265 | * Expand (or shrink) an existing mapping, potentially moving it at the | 396 | * Expand (or shrink) an existing mapping, potentially moving it at the |
266 | * same time (controlled by the MREMAP_MAYMOVE flag and available VM space) | 397 | * same time (controlled by the MREMAP_MAYMOVE flag and available VM space) |
@@ -294,32 +425,10 @@ unsigned long do_mremap(unsigned long addr, | |||
294 | if (!new_len) | 425 | if (!new_len) |
295 | goto out; | 426 | goto out; |
296 | 427 | ||
297 | /* new_addr is only valid if MREMAP_FIXED is specified */ | ||
298 | if (flags & MREMAP_FIXED) { | 428 | if (flags & MREMAP_FIXED) { |
299 | if (new_addr & ~PAGE_MASK) | 429 | if (flags & MREMAP_MAYMOVE) |
300 | goto out; | 430 | ret = mremap_to(addr, old_len, new_addr, new_len); |
301 | if (!(flags & MREMAP_MAYMOVE)) | 431 | goto out; |
302 | goto out; | ||
303 | |||
304 | if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len) | ||
305 | goto out; | ||
306 | |||
307 | /* Check if the location we're moving into overlaps the | ||
308 | * old location at all, and fail if it does. | ||
309 | */ | ||
310 | if ((new_addr <= addr) && (new_addr+new_len) > addr) | ||
311 | goto out; | ||
312 | |||
313 | if ((addr <= new_addr) && (addr+old_len) > new_addr) | ||
314 | goto out; | ||
315 | |||
316 | ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1); | ||
317 | if (ret) | ||
318 | goto out; | ||
319 | |||
320 | ret = do_munmap(mm, new_addr, new_len); | ||
321 | if (ret) | ||
322 | goto out; | ||
323 | } | 432 | } |
324 | 433 | ||
325 | /* | 434 | /* |
@@ -332,60 +441,23 @@ unsigned long do_mremap(unsigned long addr, | |||
332 | if (ret && old_len != new_len) | 441 | if (ret && old_len != new_len) |
333 | goto out; | 442 | goto out; |
334 | ret = addr; | 443 | ret = addr; |
335 | if (!(flags & MREMAP_FIXED) || (new_addr == addr)) | 444 | goto out; |
336 | goto out; | ||
337 | old_len = new_len; | ||
338 | } | 445 | } |
339 | 446 | ||
340 | /* | 447 | /* |
341 | * Ok, we need to grow.. or relocate. | 448 | * Ok, we need to grow.. |
342 | */ | 449 | */ |
343 | ret = -EFAULT; | 450 | vma = vma_to_resize(addr, old_len, new_len, &charged); |
344 | vma = find_vma(mm, addr); | 451 | if (IS_ERR(vma)) { |
345 | if (!vma || vma->vm_start > addr) | 452 | ret = PTR_ERR(vma); |
346 | goto out; | ||
347 | if (is_vm_hugetlb_page(vma)) { | ||
348 | ret = -EINVAL; | ||
349 | goto out; | ||
350 | } | ||
351 | /* We can't remap across vm area boundaries */ | ||
352 | if (old_len > vma->vm_end - addr) | ||
353 | goto out; | ||
354 | if (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP)) { | ||
355 | if (new_len > old_len) | ||
356 | goto out; | ||
357 | } | ||
358 | if (vma->vm_flags & VM_LOCKED) { | ||
359 | unsigned long locked, lock_limit; | ||
360 | locked = mm->locked_vm << PAGE_SHIFT; | ||
361 | lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur; | ||
362 | locked += new_len - old_len; | ||
363 | ret = -EAGAIN; | ||
364 | if (locked > lock_limit && !capable(CAP_IPC_LOCK)) | ||
365 | goto out; | ||
366 | } | ||
367 | if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) { | ||
368 | ret = -ENOMEM; | ||
369 | goto out; | 453 | goto out; |
370 | } | 454 | } |
371 | 455 | ||
372 | if (vma->vm_flags & VM_ACCOUNT) { | ||
373 | charged = (new_len - old_len) >> PAGE_SHIFT; | ||
374 | if (security_vm_enough_memory(charged)) | ||
375 | goto out_nc; | ||
376 | } | ||
377 | |||
378 | /* old_len exactly to the end of the area.. | 456 | /* old_len exactly to the end of the area.. |
379 | * And we're not relocating the area. | ||
380 | */ | 457 | */ |
381 | if (old_len == vma->vm_end - addr && | 458 | if (old_len == vma->vm_end - addr) { |
382 | !((flags & MREMAP_FIXED) && (addr != new_addr)) && | ||
383 | (old_len != new_len || !(flags & MREMAP_MAYMOVE))) { | ||
384 | unsigned long max_addr = TASK_SIZE; | ||
385 | if (vma->vm_next) | ||
386 | max_addr = vma->vm_next->vm_start; | ||
387 | /* can we just expand the current mapping? */ | 459 | /* can we just expand the current mapping? */ |
388 | if (max_addr - addr >= new_len) { | 460 | if (vma_expandable(vma, new_len - old_len)) { |
389 | int pages = (new_len - old_len) >> PAGE_SHIFT; | 461 | int pages = (new_len - old_len) >> PAGE_SHIFT; |
390 | 462 | ||
391 | vma_adjust(vma, vma->vm_start, | 463 | vma_adjust(vma, vma->vm_start, |
@@ -409,28 +481,27 @@ unsigned long do_mremap(unsigned long addr, | |||
409 | */ | 481 | */ |
410 | ret = -ENOMEM; | 482 | ret = -ENOMEM; |
411 | if (flags & MREMAP_MAYMOVE) { | 483 | if (flags & MREMAP_MAYMOVE) { |
412 | if (!(flags & MREMAP_FIXED)) { | 484 | unsigned long map_flags = 0; |
413 | unsigned long map_flags = 0; | 485 | if (vma->vm_flags & VM_MAYSHARE) |
414 | if (vma->vm_flags & VM_MAYSHARE) | 486 | map_flags |= MAP_SHARED; |
415 | map_flags |= MAP_SHARED; | 487 | |
416 | 488 | new_addr = get_unmapped_area(vma->vm_file, 0, new_len, | |
417 | new_addr = get_unmapped_area(vma->vm_file, 0, new_len, | 489 | vma->vm_pgoff + |
418 | vma->vm_pgoff, map_flags); | 490 | ((addr - vma->vm_start) >> PAGE_SHIFT), |
419 | if (new_addr & ~PAGE_MASK) { | 491 | map_flags); |
420 | ret = new_addr; | 492 | if (new_addr & ~PAGE_MASK) { |
421 | goto out; | 493 | ret = new_addr; |
422 | } | 494 | goto out; |
423 | |||
424 | ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1); | ||
425 | if (ret) | ||
426 | goto out; | ||
427 | } | 495 | } |
496 | |||
497 | ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1); | ||
498 | if (ret) | ||
499 | goto out; | ||
428 | ret = move_vma(vma, addr, old_len, new_len, new_addr); | 500 | ret = move_vma(vma, addr, old_len, new_len, new_addr); |
429 | } | 501 | } |
430 | out: | 502 | out: |
431 | if (ret & ~PAGE_MASK) | 503 | if (ret & ~PAGE_MASK) |
432 | vm_unacct_memory(charged); | 504 | vm_unacct_memory(charged); |
433 | out_nc: | ||
434 | return ret; | 505 | return ret; |
435 | } | 506 | } |
436 | 507 | ||
@@ -4,6 +4,10 @@ | |||
4 | #include <linux/module.h> | 4 | #include <linux/module.h> |
5 | #include <linux/err.h> | 5 | #include <linux/err.h> |
6 | #include <linux/sched.h> | 6 | #include <linux/sched.h> |
7 | #include <linux/hugetlb.h> | ||
8 | #include <linux/syscalls.h> | ||
9 | #include <linux/mman.h> | ||
10 | #include <linux/file.h> | ||
7 | #include <asm/uaccess.h> | 11 | #include <asm/uaccess.h> |
8 | 12 | ||
9 | #define CREATE_TRACE_POINTS | 13 | #define CREATE_TRACE_POINTS |
@@ -268,6 +272,46 @@ int __attribute__((weak)) get_user_pages_fast(unsigned long start, | |||
268 | } | 272 | } |
269 | EXPORT_SYMBOL_GPL(get_user_pages_fast); | 273 | EXPORT_SYMBOL_GPL(get_user_pages_fast); |
270 | 274 | ||
275 | SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, | ||
276 | unsigned long, prot, unsigned long, flags, | ||
277 | unsigned long, fd, unsigned long, pgoff) | ||
278 | { | ||
279 | struct file * file = NULL; | ||
280 | unsigned long retval = -EBADF; | ||
281 | |||
282 | if (!(flags & MAP_ANONYMOUS)) { | ||
283 | if (unlikely(flags & MAP_HUGETLB)) | ||
284 | return -EINVAL; | ||
285 | file = fget(fd); | ||
286 | if (!file) | ||
287 | goto out; | ||
288 | } else if (flags & MAP_HUGETLB) { | ||
289 | struct user_struct *user = NULL; | ||
290 | /* | ||
291 | * VM_NORESERVE is used because the reservations will be | ||
292 | * taken when vm_ops->mmap() is called | ||
293 | * A dummy user value is used because we are not locking | ||
294 | * memory so no accounting is necessary | ||
295 | */ | ||
296 | len = ALIGN(len, huge_page_size(&default_hstate)); | ||
297 | file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, VM_NORESERVE, | ||
298 | &user, HUGETLB_ANONHUGE_INODE); | ||
299 | if (IS_ERR(file)) | ||
300 | return PTR_ERR(file); | ||
301 | } | ||
302 | |||
303 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
304 | |||
305 | down_write(¤t->mm->mmap_sem); | ||
306 | retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
307 | up_write(¤t->mm->mmap_sem); | ||
308 | |||
309 | if (file) | ||
310 | fput(file); | ||
311 | out: | ||
312 | return retval; | ||
313 | } | ||
314 | |||
271 | /* Tracepoints definitions. */ | 315 | /* Tracepoints definitions. */ |
272 | EXPORT_TRACEPOINT_SYMBOL(kmalloc); | 316 | EXPORT_TRACEPOINT_SYMBOL(kmalloc); |
273 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); | 317 | EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); |