diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2011-05-19 04:21:33 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2011-05-19 04:55:49 -0400 |
commit | 6f6c3c33c027f2c83d53e8562cd9daa73fe8108b (patch) | |
tree | 51cff15bb4f6e4f8263833c74aec6cda4782d4d5 /arch/mips/kernel/syscall.c | |
parent | 9c1e8a9138ff92a4ff816ea8a1884ad2461a993a (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>
Diffstat (limited to 'arch/mips/kernel/syscall.c')
-rw-r--r-- | arch/mips/kernel/syscall.c | 113 |
1 files changed, 0 insertions, 113 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 | ||
69 | unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ | ||
70 | |||
71 | EXPORT_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 | |||
77 | unsigned 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 | |||
132 | void 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 | |||
150 | static 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 | |||
164 | unsigned 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 | |||
177 | SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, | 64 | SYSCALL_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) |