Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) 1995, 1996, 1997, 2000, 2001, 05 by Ralf Baechle |
| 7 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. |
| 8 | * Copyright (C) 2001 MIPS Technologies, Inc. |
| 9 | */ |
Randy Dunlap | a941564 | 2006-01-11 12:17:48 -0800 | [diff] [blame] | 10 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/errno.h> |
| 12 | #include <linux/linkage.h> |
| 13 | #include <linux/mm.h> |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 14 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/mman.h> |
| 17 | #include <linux/ptrace.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/string.h> |
| 20 | #include <linux/syscalls.h> |
| 21 | #include <linux/file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/utsname.h> |
| 23 | #include <linux/unistd.h> |
| 24 | #include <linux/sem.h> |
| 25 | #include <linux/msg.h> |
| 26 | #include <linux/shm.h> |
| 27 | #include <linux/compiler.h> |
Ralf Baechle | 9ff77c4 | 2005-03-08 14:39:39 +0000 | [diff] [blame] | 28 | #include <linux/module.h> |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 29 | #include <linux/ipc.h> |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 30 | #include <linux/uaccess.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
David Daney | 1091458 | 2010-07-19 13:14:56 -0700 | [diff] [blame] | 32 | #include <linux/random.h> |
David Daney | 652b14a | 2010-07-19 13:14:57 -0700 | [diff] [blame] | 33 | #include <linux/elf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 35 | #include <asm/asm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/branch.h> |
| 37 | #include <asm/cachectl.h> |
| 38 | #include <asm/cacheflush.h> |
Sam Ravnborg | 048eb58 | 2005-09-09 22:32:31 +0200 | [diff] [blame] | 39 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/signal.h> |
| 41 | #include <asm/sim.h> |
| 42 | #include <asm/shmparam.h> |
| 43 | #include <asm/sysmips.h> |
| 44 | #include <asm/uaccess.h> |
| 45 | |
Ralf Baechle | 8213bbf | 2008-07-20 13:16:46 +0100 | [diff] [blame] | 46 | /* |
| 47 | * For historic reasons the pipe(2) syscall on MIPS has an unusual calling |
| 48 | * convention. It returns results in registers $v0 / $v1 which means there |
| 49 | * is no need for it to do verify the validity of a userspace pointer |
| 50 | * argument. Historically that used to be expensive in Linux. These days |
| 51 | * the performance advantage is negligible. |
| 52 | */ |
| 53 | asmlinkage int sysm_pipe(nabi_no_regargs volatile struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | int fd[2]; |
| 56 | int error, res; |
| 57 | |
Ulrich Drepper | ed8cae8 | 2008-07-23 21:29:30 -0700 | [diff] [blame] | 58 | error = do_pipe_flags(fd, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | if (error) { |
| 60 | res = error; |
| 61 | goto out; |
| 62 | } |
| 63 | regs.regs[3] = fd[1]; |
| 64 | res = fd[0]; |
| 65 | out: |
| 66 | return res; |
| 67 | } |
| 68 | |
| 69 | unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ |
| 70 | |
Ralf Baechle | 9ff77c4 | 2005-03-08 14:39:39 +0000 | [diff] [blame] | 71 | EXPORT_SYMBOL(shm_align_mask); |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Ralf Baechle | 9c1e8a9 | 2011-05-17 16:18:09 +0100 | [diff] [blame^] | 83 | if (len > TASK_SIZE) |
David Daney | 098362e | 2007-10-27 23:10:20 -0700 | [diff] [blame] | 84 | return -ENOMEM; |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | if (flags & MAP_FIXED) { |
Ralf Baechle | 9c1e8a9 | 2011-05-17 16:18:09 +0100 | [diff] [blame^] | 87 | /* Even MAP_FIXED mappings must reside within TASK_SIZE. */ |
| 88 | if (TASK_SIZE - len < addr) |
David Daney | 098362e | 2007-10-27 23:10:20 -0700 | [diff] [blame] | 89 | return -EINVAL; |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* |
| 92 | * We do not accept a shared mapping if it would violate |
| 93 | * cache aliasing constraints. |
| 94 | */ |
Al Viro | e77414e | 2009-12-05 15:10:44 -0500 | [diff] [blame] | 95 | if ((flags & MAP_SHARED) && |
| 96 | ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | return -EINVAL; |
| 98 | return addr; |
| 99 | } |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Ralf Baechle | 9c1e8a9 | 2011-05-17 16:18:09 +0100 | [diff] [blame^] | 110 | if (TASK_SIZE - len >= addr && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | (!vmm || addr + len <= vmm->vm_start)) |
| 112 | return addr; |
| 113 | } |
David Daney | 1091458 | 2010-07-19 13:14:56 -0700 | [diff] [blame] | 114 | addr = current->mm->mmap_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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). */ |
Ralf Baechle | 9c1e8a9 | 2011-05-17 16:18:09 +0100 | [diff] [blame^] | 122 | if (TASK_SIZE - len < addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
David Daney | 1091458 | 2010-07-19 13:14:56 -0700 | [diff] [blame] | 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 | |
David Daney | 652b14a | 2010-07-19 13:14:57 -0700 | [diff] [blame] | 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 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 177 | SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, |
| 178 | unsigned long, prot, unsigned long, flags, unsigned long, |
| 179 | fd, off_t, offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
| 181 | unsigned long result; |
| 182 | |
| 183 | result = -EINVAL; |
| 184 | if (offset & ~PAGE_MASK) |
| 185 | goto out; |
| 186 | |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 187 | result = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | out: |
| 190 | return result; |
| 191 | } |
| 192 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 193 | SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len, |
| 194 | unsigned long, prot, unsigned long, flags, unsigned long, fd, |
| 195 | unsigned long, pgoff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
H. Peter Anvin | 947df17 | 2006-02-24 21:20:29 -0800 | [diff] [blame] | 197 | if (pgoff & (~PAGE_MASK >> 12)) |
| 198 | return -EINVAL; |
| 199 | |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 200 | return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | save_static_function(sys_fork); |
David Rientjes | f5dbeaf | 2007-07-22 01:01:39 -0700 | [diff] [blame] | 204 | static int __used noinline |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | _sys_fork(nabi_no_regargs struct pt_regs regs) |
| 206 | { |
| 207 | return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL); |
| 208 | } |
| 209 | |
| 210 | save_static_function(sys_clone); |
David Rientjes | f5dbeaf | 2007-07-22 01:01:39 -0700 | [diff] [blame] | 211 | static int __used noinline |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | _sys_clone(nabi_no_regargs struct pt_regs regs) |
| 213 | { |
| 214 | unsigned long clone_flags; |
| 215 | unsigned long newsp; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 216 | int __user *parent_tidptr, *child_tidptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | clone_flags = regs.regs[4]; |
| 219 | newsp = regs.regs[5]; |
| 220 | if (!newsp) |
| 221 | newsp = regs.regs[29]; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 222 | parent_tidptr = (int __user *) regs.regs[6]; |
| 223 | #ifdef CONFIG_32BIT |
| 224 | /* We need to fetch the fifth argument off the stack. */ |
| 225 | child_tidptr = NULL; |
| 226 | if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) { |
| 227 | int __user *__user *usp = (int __user *__user *) regs.regs[29]; |
| 228 | if (regs.regs[2] == __NR_syscall) { |
| 229 | if (get_user (child_tidptr, &usp[5])) |
| 230 | return -EFAULT; |
| 231 | } |
| 232 | else if (get_user (child_tidptr, &usp[4])) |
| 233 | return -EFAULT; |
| 234 | } |
| 235 | #else |
| 236 | child_tidptr = (int __user *) regs.regs[8]; |
| 237 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | return do_fork(clone_flags, newsp, ®s, 0, |
| 239 | parent_tidptr, child_tidptr); |
| 240 | } |
| 241 | |
| 242 | /* |
| 243 | * sys_execve() executes a new program. |
| 244 | */ |
| 245 | asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs) |
| 246 | { |
| 247 | int error; |
| 248 | char * filename; |
| 249 | |
David Howells | c788732 | 2010-08-11 11:26:22 +0100 | [diff] [blame] | 250 | filename = getname((const char __user *) (long)regs.regs[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | error = PTR_ERR(filename); |
| 252 | if (IS_ERR(filename)) |
| 253 | goto out; |
David Howells | d762746 | 2010-08-17 23:52:56 +0100 | [diff] [blame] | 254 | error = do_execve(filename, |
| 255 | (const char __user *const __user *) (long)regs.regs[5], |
| 256 | (const char __user *const __user *) (long)regs.regs[6], |
| 257 | ®s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | putname(filename); |
| 259 | |
| 260 | out: |
| 261 | return error; |
| 262 | } |
| 263 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 264 | SYSCALL_DEFINE1(set_thread_area, unsigned long, addr) |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 265 | { |
Al Viro | dc8f602 | 2006-01-12 01:06:07 -0800 | [diff] [blame] | 266 | struct thread_info *ti = task_thread_info(current); |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 267 | |
| 268 | ti->tp_value = addr; |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 269 | if (cpu_has_userlocal) |
| 270 | write_c0_userlocal(addr); |
Ralf Baechle | 06be375 | 2006-09-19 17:18:53 +0100 | [diff] [blame] | 271 | |
| 272 | return 0; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 275 | static inline int mips_atomic_set(struct pt_regs *regs, |
| 276 | unsigned long addr, unsigned long new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 278 | unsigned long old, tmp; |
| 279 | unsigned int err; |
| 280 | |
| 281 | if (unlikely(addr & 3)) |
| 282 | return -EINVAL; |
| 283 | |
| 284 | if (unlikely(!access_ok(VERIFY_WRITE, addr, 4))) |
| 285 | return -EINVAL; |
| 286 | |
| 287 | if (cpu_has_llsc && R10000_LLSC_WAR) { |
| 288 | __asm__ __volatile__ ( |
Ralf Baechle | a91be9e | 2009-12-02 11:33:03 +0000 | [diff] [blame] | 289 | " .set mips3 \n" |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 290 | " li %[err], 0 \n" |
| 291 | "1: ll %[old], (%[addr]) \n" |
| 292 | " move %[tmp], %[new] \n" |
| 293 | "2: sc %[tmp], (%[addr]) \n" |
| 294 | " beqzl %[tmp], 1b \n" |
| 295 | "3: \n" |
| 296 | " .section .fixup,\"ax\" \n" |
| 297 | "4: li %[err], %[efault] \n" |
| 298 | " j 3b \n" |
| 299 | " .previous \n" |
| 300 | " .section __ex_table,\"a\" \n" |
| 301 | " "STR(PTR)" 1b, 4b \n" |
| 302 | " "STR(PTR)" 2b, 4b \n" |
| 303 | " .previous \n" |
Ralf Baechle | a91be9e | 2009-12-02 11:33:03 +0000 | [diff] [blame] | 304 | " .set mips0 \n" |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 305 | : [old] "=&r" (old), |
| 306 | [err] "=&r" (err), |
| 307 | [tmp] "=&r" (tmp) |
| 308 | : [addr] "r" (addr), |
| 309 | [new] "r" (new), |
| 310 | [efault] "i" (-EFAULT) |
| 311 | : "memory"); |
| 312 | } else if (cpu_has_llsc) { |
| 313 | __asm__ __volatile__ ( |
Ralf Baechle | a91be9e | 2009-12-02 11:33:03 +0000 | [diff] [blame] | 314 | " .set mips3 \n" |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 315 | " li %[err], 0 \n" |
| 316 | "1: ll %[old], (%[addr]) \n" |
| 317 | " move %[tmp], %[new] \n" |
| 318 | "2: sc %[tmp], (%[addr]) \n" |
| 319 | " bnez %[tmp], 4f \n" |
| 320 | "3: \n" |
| 321 | " .subsection 2 \n" |
| 322 | "4: b 1b \n" |
| 323 | " .previous \n" |
| 324 | " \n" |
| 325 | " .section .fixup,\"ax\" \n" |
| 326 | "5: li %[err], %[efault] \n" |
| 327 | " j 3b \n" |
| 328 | " .previous \n" |
| 329 | " .section __ex_table,\"a\" \n" |
| 330 | " "STR(PTR)" 1b, 5b \n" |
| 331 | " "STR(PTR)" 2b, 5b \n" |
| 332 | " .previous \n" |
Ralf Baechle | a91be9e | 2009-12-02 11:33:03 +0000 | [diff] [blame] | 333 | " .set mips0 \n" |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 334 | : [old] "=&r" (old), |
| 335 | [err] "=&r" (err), |
| 336 | [tmp] "=&r" (tmp) |
| 337 | : [addr] "r" (addr), |
| 338 | [new] "r" (new), |
| 339 | [efault] "i" (-EFAULT) |
| 340 | : "memory"); |
| 341 | } else { |
| 342 | do { |
| 343 | preempt_disable(); |
| 344 | ll_bit = 1; |
| 345 | ll_task = current; |
| 346 | preempt_enable(); |
| 347 | |
| 348 | err = __get_user(old, (unsigned int *) addr); |
| 349 | err |= __put_user(new, (unsigned int *) addr); |
| 350 | if (err) |
| 351 | break; |
| 352 | rmb(); |
| 353 | } while (!ll_bit); |
| 354 | } |
| 355 | |
| 356 | if (unlikely(err)) |
| 357 | return err; |
| 358 | |
| 359 | regs->regs[2] = old; |
| 360 | regs->regs[7] = 0; /* No error */ |
| 361 | |
| 362 | /* |
| 363 | * Don't let your children do this ... |
| 364 | */ |
| 365 | __asm__ __volatile__( |
| 366 | " move $29, %0 \n" |
| 367 | " j syscall_exit \n" |
| 368 | : /* no outputs */ |
| 369 | : "r" (regs)); |
| 370 | |
| 371 | /* unreached. Honestly. */ |
| 372 | while (1); |
| 373 | } |
| 374 | |
| 375 | save_static_function(sys_sysmips); |
| 376 | static int __used noinline |
| 377 | _sys_sysmips(nabi_no_regargs struct pt_regs regs) |
| 378 | { |
David Daney | 7a6e4ca | 2011-01-24 14:51:35 -0800 | [diff] [blame] | 379 | long cmd, arg1, arg2; |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 380 | |
| 381 | cmd = regs.regs[4]; |
| 382 | arg1 = regs.regs[5]; |
| 383 | arg2 = regs.regs[6]; |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 384 | |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 385 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | case MIPS_ATOMIC_SET: |
Ralf Baechle | f1e39a4 | 2009-09-17 02:25:05 +0200 | [diff] [blame] | 387 | return mips_atomic_set(®s, arg1, arg2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | case MIPS_FIXADE: |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 390 | if (arg1 & ~3) |
| 391 | return -EINVAL; |
| 392 | |
| 393 | if (arg1 & 1) |
| 394 | set_thread_flag(TIF_FIXADE); |
| 395 | else |
| 396 | clear_thread_flag(TIF_FIXADE); |
| 397 | if (arg1 & 2) |
| 398 | set_thread_flag(TIF_LOGADE); |
| 399 | else |
Stefan Oberhumer | e56293b | 2011-01-17 09:19:53 +0100 | [diff] [blame] | 400 | clear_thread_flag(TIF_LOGADE); |
Ralf Baechle | 293c5bd | 2007-07-25 16:19:33 +0100 | [diff] [blame] | 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return 0; |
| 403 | |
| 404 | case FLUSH_CACHE: |
| 405 | __flush_cache_all(); |
| 406 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | return -EINVAL; |
| 410 | } |
| 411 | |
| 412 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | * No implemented yet ... |
| 414 | */ |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 415 | SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
| 417 | return -ENOSYS; |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * If we ever come here the user sp is bad. Zap the process right away. |
| 422 | * Due to the bad stack signaling wouldn't work. |
| 423 | */ |
| 424 | asmlinkage void bad_stack(void) |
| 425 | { |
| 426 | do_exit(SIGSEGV); |
| 427 | } |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 428 | |
| 429 | /* |
| 430 | * Do a system call from kernel instead of calling sys_execve so we |
| 431 | * end up with proper pt_regs. |
| 432 | */ |
David Howells | d762746 | 2010-08-17 23:52:56 +0100 | [diff] [blame] | 433 | int kernel_execve(const char *filename, |
| 434 | const char *const argv[], |
| 435 | const char *const envp[]) |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 436 | { |
| 437 | register unsigned long __a0 asm("$4") = (unsigned long) filename; |
| 438 | register unsigned long __a1 asm("$5") = (unsigned long) argv; |
| 439 | register unsigned long __a2 asm("$6") = (unsigned long) envp; |
| 440 | register unsigned long __a3 asm("$7"); |
| 441 | unsigned long __v0; |
| 442 | |
| 443 | __asm__ volatile (" \n" |
| 444 | " .set noreorder \n" |
| 445 | " li $2, %5 # __NR_execve \n" |
| 446 | " syscall \n" |
| 447 | " move %0, $2 \n" |
| 448 | " .set reorder \n" |
| 449 | : "=&r" (__v0), "=r" (__a3) |
| 450 | : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve) |
| 451 | : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", |
| 452 | "memory"); |
| 453 | |
| 454 | if (__a3 == 0) |
| 455 | return __v0; |
| 456 | |
| 457 | return -__v0; |
| 458 | } |