aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2011-05-19 04:21:33 -0400
committerRalf Baechle <ralf@linux-mips.org>2011-05-19 04:55:49 -0400
commit6f6c3c33c027f2c83d53e8562cd9daa73fe8108b (patch)
tree51cff15bb4f6e4f8263833c74aec6cda4782d4d5
parent9c1e8a9138ff92a4ff816ea8a1884ad2461a993a (diff)
MIPS: Move arch_get_unmapped_area and gang to new file.
It never really belonged into syscall.c and it's about to become well more complex. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--arch/mips/kernel/syscall.c113
-rw-r--r--arch/mips/mm/Makefile3
-rw-r--r--arch/mips/mm/mmap.c122
3 files changed, 124 insertions, 114 deletions
diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index 0c207e8ee601..d02765708ddb 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -10,12 +10,9 @@
10#include <linux/capability.h> 10#include <linux/capability.h>
11#include <linux/errno.h> 11#include <linux/errno.h>
12#include <linux/linkage.h> 12#include <linux/linkage.h>
13#include <linux/mm.h>
14#include <linux/fs.h> 13#include <linux/fs.h>
15#include <linux/smp.h> 14#include <linux/smp.h>
16#include <linux/mman.h>
17#include <linux/ptrace.h> 15#include <linux/ptrace.h>
18#include <linux/sched.h>
19#include <linux/string.h> 16#include <linux/string.h>
20#include <linux/syscalls.h> 17#include <linux/syscalls.h>
21#include <linux/file.h> 18#include <linux/file.h>
@@ -25,11 +22,9 @@
25#include <linux/msg.h> 22#include <linux/msg.h>
26#include <linux/shm.h> 23#include <linux/shm.h>
27#include <linux/compiler.h> 24#include <linux/compiler.h>
28#include <linux/module.h>
29#include <linux/ipc.h> 25#include <linux/ipc.h>
30#include <linux/uaccess.h> 26#include <linux/uaccess.h>
31#include <linux/slab.h> 27#include <linux/slab.h>
32#include <linux/random.h>
33#include <linux/elf.h> 28#include <linux/elf.h>
34 29
35#include <asm/asm.h> 30#include <asm/asm.h>
@@ -66,114 +61,6 @@ out:
66 return res; 61 return res;
67} 62}
68 63
69unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
70
71EXPORT_SYMBOL(shm_align_mask);
72
73#define COLOUR_ALIGN(addr,pgoff) \
74 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
75 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
76
77unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
78 unsigned long len, unsigned long pgoff, unsigned long flags)
79{
80 struct vm_area_struct * vmm;
81 int do_color_align;
82
83 if (len > TASK_SIZE)
84 return -ENOMEM;
85
86 if (flags & MAP_FIXED) {
87 /* Even MAP_FIXED mappings must reside within TASK_SIZE. */
88 if (TASK_SIZE - len < addr)
89 return -EINVAL;
90
91 /*
92 * We do not accept a shared mapping if it would violate
93 * cache aliasing constraints.
94 */
95 if ((flags & MAP_SHARED) &&
96 ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask))
97 return -EINVAL;
98 return addr;
99 }
100
101 do_color_align = 0;
102 if (filp || (flags & MAP_SHARED))
103 do_color_align = 1;
104 if (addr) {
105 if (do_color_align)
106 addr = COLOUR_ALIGN(addr, pgoff);
107 else
108 addr = PAGE_ALIGN(addr);
109 vmm = find_vma(current->mm, addr);
110 if (TASK_SIZE - len >= addr &&
111 (!vmm || addr + len <= vmm->vm_start))
112 return addr;
113 }
114 addr = current->mm->mmap_base;
115 if (do_color_align)
116 addr = COLOUR_ALIGN(addr, pgoff);
117 else
118 addr = PAGE_ALIGN(addr);
119
120 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
121 /* At this point: (!vmm || addr < vmm->vm_end). */
122 if (TASK_SIZE - len < addr)
123 return -ENOMEM;
124 if (!vmm || addr + len <= vmm->vm_start)
125 return addr;
126 addr = vmm->vm_end;
127 if (do_color_align)
128 addr = COLOUR_ALIGN(addr, pgoff);
129 }
130}
131
132void arch_pick_mmap_layout(struct mm_struct *mm)
133{
134 unsigned long random_factor = 0UL;
135
136 if (current->flags & PF_RANDOMIZE) {
137 random_factor = get_random_int();
138 random_factor = random_factor << PAGE_SHIFT;
139 if (TASK_IS_32BIT_ADDR)
140 random_factor &= 0xfffffful;
141 else
142 random_factor &= 0xffffffful;
143 }
144
145 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
146 mm->get_unmapped_area = arch_get_unmapped_area;
147 mm->unmap_area = arch_unmap_area;
148}
149
150static inline unsigned long brk_rnd(void)
151{
152 unsigned long rnd = get_random_int();
153
154 rnd = rnd << PAGE_SHIFT;
155 /* 8MB for 32bit, 256MB for 64bit */
156 if (TASK_IS_32BIT_ADDR)
157 rnd = rnd & 0x7ffffful;
158 else
159 rnd = rnd & 0xffffffful;
160
161 return rnd;
162}
163
164unsigned long arch_randomize_brk(struct mm_struct *mm)
165{
166 unsigned long base = mm->brk;
167 unsigned long ret;
168
169 ret = PAGE_ALIGN(base + brk_rnd());
170
171 if (ret < mm->brk)
172 return mm->brk;
173
174 return ret;
175}
176
177SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, 64SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
178 unsigned long, prot, unsigned long, flags, unsigned long, 65 unsigned long, prot, unsigned long, flags, unsigned long,
179 fd, off_t, offset) 66 fd, off_t, offset)
diff --git a/arch/mips/mm/Makefile b/arch/mips/mm/Makefile
index eb4463689faa..4d8c1623eee2 100644
--- a/arch/mips/mm/Makefile
+++ b/arch/mips/mm/Makefile
@@ -3,7 +3,8 @@
3# 3#
4 4
5obj-y += cache.o dma-default.o extable.o fault.o \ 5obj-y += cache.o dma-default.o extable.o fault.o \
6 init.o tlbex.o tlbex-fault.o uasm.o page.o 6 init.o mmap.o tlbex.o tlbex-fault.o uasm.o \
7 page.o
7 8
8obj-$(CONFIG_32BIT) += ioremap.o pgtable-32.o 9obj-$(CONFIG_32BIT) += ioremap.o pgtable-32.o
9obj-$(CONFIG_64BIT) += pgtable-64.o 10obj-$(CONFIG_64BIT) += pgtable-64.o
diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
new file mode 100644
index 000000000000..ae3c20a9556e
--- /dev/null
+++ b/arch/mips/mm/mmap.c
@@ -0,0 +1,122 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2011 Wind River Systems,
7 * written by Ralf Baechle <ralf@linux-mips.org>
8 */
9#include <linux/errno.h>
10#include <linux/mm.h>
11#include <linux/mman.h>
12#include <linux/module.h>
13#include <linux/random.h>
14#include <linux/sched.h>
15
16unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
17
18EXPORT_SYMBOL(shm_align_mask);
19
20#define COLOUR_ALIGN(addr,pgoff) \
21 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
22 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
23
24unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
25 unsigned long len, unsigned long pgoff, unsigned long flags)
26{
27 struct vm_area_struct * vmm;
28 int do_color_align;
29
30 if (len > TASK_SIZE)
31 return -ENOMEM;
32
33 if (flags & MAP_FIXED) {
34 /* Even MAP_FIXED mappings must reside within TASK_SIZE. */
35 if (TASK_SIZE - len < addr)
36 return -EINVAL;
37
38 /*
39 * We do not accept a shared mapping if it would violate
40 * cache aliasing constraints.
41 */
42 if ((flags & MAP_SHARED) &&
43 ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask))
44 return -EINVAL;
45 return addr;
46 }
47
48 do_color_align = 0;
49 if (filp || (flags & MAP_SHARED))
50 do_color_align = 1;
51 if (addr) {
52 if (do_color_align)
53 addr = COLOUR_ALIGN(addr, pgoff);
54 else
55 addr = PAGE_ALIGN(addr);
56 vmm = find_vma(current->mm, addr);
57 if (TASK_SIZE - len >= addr &&
58 (!vmm || addr + len <= vmm->vm_start))
59 return addr;
60 }
61 addr = current->mm->mmap_base;
62 if (do_color_align)
63 addr = COLOUR_ALIGN(addr, pgoff);
64 else
65 addr = PAGE_ALIGN(addr);
66
67 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
68 /* At this point: (!vmm || addr < vmm->vm_end). */
69 if (TASK_SIZE - len < addr)
70 return -ENOMEM;
71 if (!vmm || addr + len <= vmm->vm_start)
72 return addr;
73 addr = vmm->vm_end;
74 if (do_color_align)
75 addr = COLOUR_ALIGN(addr, pgoff);
76 }
77}
78
79void arch_pick_mmap_layout(struct mm_struct *mm)
80{
81 unsigned long random_factor = 0UL;
82
83 if (current->flags & PF_RANDOMIZE) {
84 random_factor = get_random_int();
85 random_factor = random_factor << PAGE_SHIFT;
86 if (TASK_IS_32BIT_ADDR)
87 random_factor &= 0xfffffful;
88 else
89 random_factor &= 0xffffffful;
90 }
91
92 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
93 mm->get_unmapped_area = arch_get_unmapped_area;
94 mm->unmap_area = arch_unmap_area;
95}
96
97static inline unsigned long brk_rnd(void)
98{
99 unsigned long rnd = get_random_int();
100
101 rnd = rnd << PAGE_SHIFT;
102 /* 8MB for 32bit, 256MB for 64bit */
103 if (TASK_IS_32BIT_ADDR)
104 rnd = rnd & 0x7ffffful;
105 else
106 rnd = rnd & 0xffffffful;
107
108 return rnd;
109}
110
111unsigned long arch_randomize_brk(struct mm_struct *mm)
112{
113 unsigned long base = mm->brk;
114 unsigned long ret;
115
116 ret = PAGE_ALIGN(base + brk_rnd());
117
118 if (ret < mm->brk)
119 return mm->brk;
120
121 return ret;
122}