blob: fe0d7980560368056e187dcc9f852b3218a08951 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Dunlapa9415642006-01-11 12:17:48 -080010#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/errno.h>
12#include <linux/linkage.h>
13#include <linux/mm.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040014#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#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>
22#include <linux/slab.h>
23#include <linux/utsname.h>
24#include <linux/unistd.h>
25#include <linux/sem.h>
26#include <linux/msg.h>
27#include <linux/shm.h>
28#include <linux/compiler.h>
Ralf Baechle9ff77c42005-03-08 14:39:39 +000029#include <linux/module.h>
Adrian Bunkcba4fbb2007-10-16 23:29:24 -070030#include <linux/ipc.h>
Ralf Baechlef1e39a42009-09-17 02:25:05 +020031#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Ralf Baechlef1e39a42009-09-17 02:25:05 +020033#include <asm/asm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/branch.h>
35#include <asm/cachectl.h>
36#include <asm/cacheflush.h>
Sam Ravnborg048eb582005-09-09 22:32:31 +020037#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/signal.h>
39#include <asm/sim.h>
40#include <asm/shmparam.h>
41#include <asm/sysmips.h>
42#include <asm/uaccess.h>
43
Ralf Baechle8213bbf2008-07-20 13:16:46 +010044/*
45 * For historic reasons the pipe(2) syscall on MIPS has an unusual calling
46 * convention. It returns results in registers $v0 / $v1 which means there
47 * is no need for it to do verify the validity of a userspace pointer
48 * argument. Historically that used to be expensive in Linux. These days
49 * the performance advantage is negligible.
50 */
51asmlinkage int sysm_pipe(nabi_no_regargs volatile struct pt_regs regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
53 int fd[2];
54 int error, res;
55
Ulrich Dreppered8cae82008-07-23 21:29:30 -070056 error = do_pipe_flags(fd, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 if (error) {
58 res = error;
59 goto out;
60 }
61 regs.regs[3] = fd[1];
62 res = fd[0];
63out:
64 return res;
65}
66
67unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
68
Ralf Baechle9ff77c42005-03-08 14:39:39 +000069EXPORT_SYMBOL(shm_align_mask);
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#define COLOUR_ALIGN(addr,pgoff) \
72 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
73 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
74
75unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
76 unsigned long len, unsigned long pgoff, unsigned long flags)
77{
78 struct vm_area_struct * vmm;
79 int do_color_align;
80 unsigned long task_size;
81
82 task_size = STACK_TOP;
83
David Daney098362e2007-10-27 23:10:20 -070084 if (len > task_size)
85 return -ENOMEM;
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 if (flags & MAP_FIXED) {
David Daney098362e2007-10-27 23:10:20 -070088 /* Even MAP_FIXED mappings must reside within task_size. */
89 if (task_size - len < addr)
90 return -EINVAL;
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 /*
93 * We do not accept a shared mapping if it would violate
94 * cache aliasing constraints.
95 */
96 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
97 return -EINVAL;
98 return addr;
99 }
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 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 = TASK_UNMAPPED_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/* common code for old and new mmaps */
133static inline unsigned long
134do_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(&current->mm->mmap_sem);
148 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
149 up_write(&current->mm->mmap_sem);
150
151 if (file)
152 fput(file);
153out:
154 return error;
155}
156
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000157SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
158 unsigned long, prot, unsigned long, flags, unsigned long,
159 fd, off_t, offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
161 unsigned long result;
162
163 result = -EINVAL;
164 if (offset & ~PAGE_MASK)
165 goto out;
166
167 result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
168
169out:
170 return result;
171}
172
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000173SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
174 unsigned long, prot, unsigned long, flags, unsigned long, fd,
175 unsigned long, pgoff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
H. Peter Anvin947df172006-02-24 21:20:29 -0800177 if (pgoff & (~PAGE_MASK >> 12))
178 return -EINVAL;
179
180 return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
183save_static_function(sys_fork);
David Rientjesf5dbeaf2007-07-22 01:01:39 -0700184static int __used noinline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185_sys_fork(nabi_no_regargs struct pt_regs regs)
186{
187 return do_fork(SIGCHLD, regs.regs[29], &regs, 0, NULL, NULL);
188}
189
190save_static_function(sys_clone);
David Rientjesf5dbeaf2007-07-22 01:01:39 -0700191static int __used noinline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192_sys_clone(nabi_no_regargs struct pt_regs regs)
193{
194 unsigned long clone_flags;
195 unsigned long newsp;
Ralf Baechle3c370262005-04-13 17:43:59 +0000196 int __user *parent_tidptr, *child_tidptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 clone_flags = regs.regs[4];
199 newsp = regs.regs[5];
200 if (!newsp)
201 newsp = regs.regs[29];
Ralf Baechle3c370262005-04-13 17:43:59 +0000202 parent_tidptr = (int __user *) regs.regs[6];
203#ifdef CONFIG_32BIT
204 /* We need to fetch the fifth argument off the stack. */
205 child_tidptr = NULL;
206 if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
207 int __user *__user *usp = (int __user *__user *) regs.regs[29];
208 if (regs.regs[2] == __NR_syscall) {
209 if (get_user (child_tidptr, &usp[5]))
210 return -EFAULT;
211 }
212 else if (get_user (child_tidptr, &usp[4]))
213 return -EFAULT;
214 }
215#else
216 child_tidptr = (int __user *) regs.regs[8];
217#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 return do_fork(clone_flags, newsp, &regs, 0,
219 parent_tidptr, child_tidptr);
220}
221
222/*
223 * sys_execve() executes a new program.
224 */
225asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
226{
227 int error;
228 char * filename;
229
Atsushi Nemotobe6e5182006-02-08 23:39:49 +0900230 filename = getname((char __user *) (long)regs.regs[4]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 error = PTR_ERR(filename);
232 if (IS_ERR(filename))
233 goto out;
Atsushi Nemotobe6e5182006-02-08 23:39:49 +0900234 error = do_execve(filename, (char __user *__user *) (long)regs.regs[5],
235 (char __user *__user *) (long)regs.regs[6], &regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 putname(filename);
237
238out:
239 return error;
240}
241
242/*
243 * Compacrapability ...
244 */
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000245SYSCALL_DEFINE1(uname, struct old_utsname __user *, name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700247 if (name && !copy_to_user(name, utsname(), sizeof (*name)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return 0;
249 return -EFAULT;
250}
251
252/*
253 * Compacrapability ...
254 */
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000255SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
257 int error;
258
259 if (!name)
260 return -EFAULT;
Ralf Baechle21a151d2007-10-11 23:46:15 +0100261 if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 return -EFAULT;
263
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700264 error = __copy_to_user(&name->sysname, &utsname()->sysname,
265 __OLD_UTS_LEN);
266 error -= __put_user(0, name->sysname + __OLD_UTS_LEN);
267 error -= __copy_to_user(&name->nodename, &utsname()->nodename,
268 __OLD_UTS_LEN);
269 error -= __put_user(0, name->nodename + __OLD_UTS_LEN);
270 error -= __copy_to_user(&name->release, &utsname()->release,
271 __OLD_UTS_LEN);
272 error -= __put_user(0, name->release + __OLD_UTS_LEN);
273 error -= __copy_to_user(&name->version, &utsname()->version,
274 __OLD_UTS_LEN);
275 error -= __put_user(0, name->version + __OLD_UTS_LEN);
276 error -= __copy_to_user(&name->machine, &utsname()->machine,
277 __OLD_UTS_LEN);
278 error = __put_user(0, name->machine + __OLD_UTS_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 error = error ? -EFAULT : 0;
280
281 return error;
282}
283
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000284SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
Ralf Baechle3c370262005-04-13 17:43:59 +0000285{
Al Virodc8f6022006-01-12 01:06:07 -0800286 struct thread_info *ti = task_thread_info(current);
Ralf Baechle3c370262005-04-13 17:43:59 +0000287
288 ti->tp_value = addr;
Ralf Baechlea3692022007-07-10 17:33:02 +0100289 if (cpu_has_userlocal)
290 write_c0_userlocal(addr);
Ralf Baechle06be3752006-09-19 17:18:53 +0100291
292 return 0;
Ralf Baechle3c370262005-04-13 17:43:59 +0000293}
294
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200295static inline int mips_atomic_set(struct pt_regs *regs,
296 unsigned long addr, unsigned long new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200298 unsigned long old, tmp;
299 unsigned int err;
300
301 if (unlikely(addr & 3))
302 return -EINVAL;
303
304 if (unlikely(!access_ok(VERIFY_WRITE, addr, 4)))
305 return -EINVAL;
306
307 if (cpu_has_llsc && R10000_LLSC_WAR) {
308 __asm__ __volatile__ (
Ralf Baechlea91be9e2009-12-02 11:33:03 +0000309 " .set mips3 \n"
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200310 " li %[err], 0 \n"
311 "1: ll %[old], (%[addr]) \n"
312 " move %[tmp], %[new] \n"
313 "2: sc %[tmp], (%[addr]) \n"
314 " beqzl %[tmp], 1b \n"
315 "3: \n"
316 " .section .fixup,\"ax\" \n"
317 "4: li %[err], %[efault] \n"
318 " j 3b \n"
319 " .previous \n"
320 " .section __ex_table,\"a\" \n"
321 " "STR(PTR)" 1b, 4b \n"
322 " "STR(PTR)" 2b, 4b \n"
323 " .previous \n"
Ralf Baechlea91be9e2009-12-02 11:33:03 +0000324 " .set mips0 \n"
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200325 : [old] "=&r" (old),
326 [err] "=&r" (err),
327 [tmp] "=&r" (tmp)
328 : [addr] "r" (addr),
329 [new] "r" (new),
330 [efault] "i" (-EFAULT)
331 : "memory");
332 } else if (cpu_has_llsc) {
333 __asm__ __volatile__ (
Ralf Baechlea91be9e2009-12-02 11:33:03 +0000334 " .set mips3 \n"
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200335 " li %[err], 0 \n"
336 "1: ll %[old], (%[addr]) \n"
337 " move %[tmp], %[new] \n"
338 "2: sc %[tmp], (%[addr]) \n"
339 " bnez %[tmp], 4f \n"
340 "3: \n"
341 " .subsection 2 \n"
342 "4: b 1b \n"
343 " .previous \n"
344 " \n"
345 " .section .fixup,\"ax\" \n"
346 "5: li %[err], %[efault] \n"
347 " j 3b \n"
348 " .previous \n"
349 " .section __ex_table,\"a\" \n"
350 " "STR(PTR)" 1b, 5b \n"
351 " "STR(PTR)" 2b, 5b \n"
352 " .previous \n"
Ralf Baechlea91be9e2009-12-02 11:33:03 +0000353 " .set mips0 \n"
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200354 : [old] "=&r" (old),
355 [err] "=&r" (err),
356 [tmp] "=&r" (tmp)
357 : [addr] "r" (addr),
358 [new] "r" (new),
359 [efault] "i" (-EFAULT)
360 : "memory");
361 } else {
362 do {
363 preempt_disable();
364 ll_bit = 1;
365 ll_task = current;
366 preempt_enable();
367
368 err = __get_user(old, (unsigned int *) addr);
369 err |= __put_user(new, (unsigned int *) addr);
370 if (err)
371 break;
372 rmb();
373 } while (!ll_bit);
374 }
375
376 if (unlikely(err))
377 return err;
378
379 regs->regs[2] = old;
380 regs->regs[7] = 0; /* No error */
381
382 /*
383 * Don't let your children do this ...
384 */
385 __asm__ __volatile__(
386 " move $29, %0 \n"
387 " j syscall_exit \n"
388 : /* no outputs */
389 : "r" (regs));
390
391 /* unreached. Honestly. */
392 while (1);
393}
394
395save_static_function(sys_sysmips);
396static int __used noinline
397_sys_sysmips(nabi_no_regargs struct pt_regs regs)
398{
399 long cmd, arg1, arg2, arg3;
400
401 cmd = regs.regs[4];
402 arg1 = regs.regs[5];
403 arg2 = regs.regs[6];
404 arg3 = regs.regs[7];
405
Ralf Baechle293c5bd2007-07-25 16:19:33 +0100406 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 case MIPS_ATOMIC_SET:
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200408 return mips_atomic_set(&regs, arg1, arg2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 case MIPS_FIXADE:
Ralf Baechle293c5bd2007-07-25 16:19:33 +0100411 if (arg1 & ~3)
412 return -EINVAL;
413
414 if (arg1 & 1)
415 set_thread_flag(TIF_FIXADE);
416 else
417 clear_thread_flag(TIF_FIXADE);
418 if (arg1 & 2)
419 set_thread_flag(TIF_LOGADE);
420 else
421 clear_thread_flag(TIF_FIXADE);
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 return 0;
424
425 case FLUSH_CACHE:
426 __flush_cache_all();
427 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429
430 return -EINVAL;
431}
432
433/*
434 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
435 *
436 * This is really horribly ugly.
437 */
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000438SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, int, second,
439 unsigned long, third, void __user *, ptr, long, fifth)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 int version, ret;
442
443 version = call >> 16; /* hack for backward compatibility */
444 call &= 0xffff;
445
446 switch (call) {
447 case SEMOP:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100448 return sys_semtimedop(first, (struct sembuf __user *)ptr,
449 second, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 case SEMTIMEDOP:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100451 return sys_semtimedop(first, (struct sembuf __user *)ptr,
452 second,
453 (const struct timespec __user *)fifth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 case SEMGET:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100455 return sys_semget(first, second, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 case SEMCTL: {
457 union semun fourth;
458 if (!ptr)
459 return -EINVAL;
Atsushi Nemoto219ac732006-02-21 16:05:11 +0900460 if (get_user(fourth.__pad, (void __user *__user *) ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return -EFAULT;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100462 return sys_semctl(first, second, third, fourth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 }
464
465 case MSGSND:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100466 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
467 second, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 case MSGRCV:
469 switch (version) {
470 case 0: {
471 struct ipc_kludge tmp;
472 if (!ptr)
473 return -EINVAL;
474
475 if (copy_from_user(&tmp,
Atsushi Nemotobe6e5182006-02-08 23:39:49 +0900476 (struct ipc_kludge __user *) ptr,
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100477 sizeof(tmp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return -EFAULT;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100479 return sys_msgrcv(first, tmp.msgp, second,
480 tmp.msgtyp, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482 default:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100483 return sys_msgrcv(first,
484 (struct msgbuf __user *) ptr,
485 second, fifth, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
487 case MSGGET:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100488 return sys_msgget((key_t) first, second);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 case MSGCTL:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100490 return sys_msgctl(first, second,
491 (struct msqid_ds __user *) ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 case SHMAT:
494 switch (version) {
495 default: {
Ralf Baechlefc103342006-06-28 11:24:12 +0100496 unsigned long raddr;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100497 ret = do_shmat(first, (char __user *) ptr, second,
498 &raddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 if (ret)
500 return ret;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100501 return put_user(raddr, (unsigned long __user *) third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503 case 1: /* iBCS2 emulator entry point */
504 if (!segment_eq(get_fs(), get_ds()))
505 return -EINVAL;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100506 return do_shmat(first, (char __user *) ptr, second,
507 (unsigned long *) third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509 case SHMDT:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100510 return sys_shmdt((char __user *)ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 case SHMGET:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100512 return sys_shmget(first, second, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 case SHMCTL:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100514 return sys_shmctl(first, second,
515 (struct shmid_ds __user *) ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 default:
517 return -ENOSYS;
518 }
519}
520
521/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 * No implemented yet ...
523 */
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000524SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
526 return -ENOSYS;
527}
528
529/*
530 * If we ever come here the user sp is bad. Zap the process right away.
531 * Due to the bad stack signaling wouldn't work.
532 */
533asmlinkage void bad_stack(void)
534{
535 do_exit(SIGSEGV);
536}
Arnd Bergmannfe742902006-10-02 02:18:34 -0700537
538/*
539 * Do a system call from kernel instead of calling sys_execve so we
540 * end up with proper pt_regs.
541 */
542int kernel_execve(const char *filename, char *const argv[], char *const envp[])
543{
544 register unsigned long __a0 asm("$4") = (unsigned long) filename;
545 register unsigned long __a1 asm("$5") = (unsigned long) argv;
546 register unsigned long __a2 asm("$6") = (unsigned long) envp;
547 register unsigned long __a3 asm("$7");
548 unsigned long __v0;
549
550 __asm__ volatile (" \n"
551 " .set noreorder \n"
552 " li $2, %5 # __NR_execve \n"
553 " syscall \n"
554 " move %0, $2 \n"
555 " .set reorder \n"
556 : "=&r" (__v0), "=r" (__a3)
557 : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
558 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
559 "memory");
560
561 if (__a3 == 0)
562 return __v0;
563
564 return -__v0;
565}