blob: c25b2e7dcb7b42a69690505db6bd08e3788e7e30 [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
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000132SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len,
133 unsigned long, prot, unsigned long, flags, unsigned long,
134 fd, off_t, offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 unsigned long result;
137
138 result = -EINVAL;
139 if (offset & ~PAGE_MASK)
140 goto out;
141
Al Virof8b72562009-11-30 17:37:04 -0500142 result = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144out:
145 return result;
146}
147
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000148SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len,
149 unsigned long, prot, unsigned long, flags, unsigned long, fd,
150 unsigned long, pgoff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
H. Peter Anvin947df172006-02-24 21:20:29 -0800152 if (pgoff & (~PAGE_MASK >> 12))
153 return -EINVAL;
154
Al Virof8b72562009-11-30 17:37:04 -0500155 return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
158save_static_function(sys_fork);
David Rientjesf5dbeaf2007-07-22 01:01:39 -0700159static int __used noinline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160_sys_fork(nabi_no_regargs struct pt_regs regs)
161{
162 return do_fork(SIGCHLD, regs.regs[29], &regs, 0, NULL, NULL);
163}
164
165save_static_function(sys_clone);
David Rientjesf5dbeaf2007-07-22 01:01:39 -0700166static int __used noinline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167_sys_clone(nabi_no_regargs struct pt_regs regs)
168{
169 unsigned long clone_flags;
170 unsigned long newsp;
Ralf Baechle3c370262005-04-13 17:43:59 +0000171 int __user *parent_tidptr, *child_tidptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 clone_flags = regs.regs[4];
174 newsp = regs.regs[5];
175 if (!newsp)
176 newsp = regs.regs[29];
Ralf Baechle3c370262005-04-13 17:43:59 +0000177 parent_tidptr = (int __user *) regs.regs[6];
178#ifdef CONFIG_32BIT
179 /* We need to fetch the fifth argument off the stack. */
180 child_tidptr = NULL;
181 if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
182 int __user *__user *usp = (int __user *__user *) regs.regs[29];
183 if (regs.regs[2] == __NR_syscall) {
184 if (get_user (child_tidptr, &usp[5]))
185 return -EFAULT;
186 }
187 else if (get_user (child_tidptr, &usp[4]))
188 return -EFAULT;
189 }
190#else
191 child_tidptr = (int __user *) regs.regs[8];
192#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return do_fork(clone_flags, newsp, &regs, 0,
194 parent_tidptr, child_tidptr);
195}
196
197/*
198 * sys_execve() executes a new program.
199 */
200asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
201{
202 int error;
203 char * filename;
204
Atsushi Nemotobe6e5182006-02-08 23:39:49 +0900205 filename = getname((char __user *) (long)regs.regs[4]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 error = PTR_ERR(filename);
207 if (IS_ERR(filename))
208 goto out;
Atsushi Nemotobe6e5182006-02-08 23:39:49 +0900209 error = do_execve(filename, (char __user *__user *) (long)regs.regs[5],
210 (char __user *__user *) (long)regs.regs[6], &regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 putname(filename);
212
213out:
214 return error;
215}
216
217/*
218 * Compacrapability ...
219 */
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000220SYSCALL_DEFINE1(uname, struct old_utsname __user *, name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700222 if (name && !copy_to_user(name, utsname(), sizeof (*name)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return 0;
224 return -EFAULT;
225}
226
227/*
228 * Compacrapability ...
229 */
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000230SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
232 int error;
233
234 if (!name)
235 return -EFAULT;
Ralf Baechle21a151d2007-10-11 23:46:15 +0100236 if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return -EFAULT;
238
Serge E. Hallyne9ff3992006-10-02 02:18:11 -0700239 error = __copy_to_user(&name->sysname, &utsname()->sysname,
240 __OLD_UTS_LEN);
241 error -= __put_user(0, name->sysname + __OLD_UTS_LEN);
242 error -= __copy_to_user(&name->nodename, &utsname()->nodename,
243 __OLD_UTS_LEN);
244 error -= __put_user(0, name->nodename + __OLD_UTS_LEN);
245 error -= __copy_to_user(&name->release, &utsname()->release,
246 __OLD_UTS_LEN);
247 error -= __put_user(0, name->release + __OLD_UTS_LEN);
248 error -= __copy_to_user(&name->version, &utsname()->version,
249 __OLD_UTS_LEN);
250 error -= __put_user(0, name->version + __OLD_UTS_LEN);
251 error -= __copy_to_user(&name->machine, &utsname()->machine,
252 __OLD_UTS_LEN);
253 error = __put_user(0, name->machine + __OLD_UTS_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 error = error ? -EFAULT : 0;
255
256 return error;
257}
258
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000259SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
Ralf Baechle3c370262005-04-13 17:43:59 +0000260{
Al Virodc8f6022006-01-12 01:06:07 -0800261 struct thread_info *ti = task_thread_info(current);
Ralf Baechle3c370262005-04-13 17:43:59 +0000262
263 ti->tp_value = addr;
Ralf Baechlea3692022007-07-10 17:33:02 +0100264 if (cpu_has_userlocal)
265 write_c0_userlocal(addr);
Ralf Baechle06be3752006-09-19 17:18:53 +0100266
267 return 0;
Ralf Baechle3c370262005-04-13 17:43:59 +0000268}
269
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200270static inline int mips_atomic_set(struct pt_regs *regs,
271 unsigned long addr, unsigned long new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200273 unsigned long old, tmp;
274 unsigned int err;
275
276 if (unlikely(addr & 3))
277 return -EINVAL;
278
279 if (unlikely(!access_ok(VERIFY_WRITE, addr, 4)))
280 return -EINVAL;
281
282 if (cpu_has_llsc && R10000_LLSC_WAR) {
283 __asm__ __volatile__ (
Ralf Baechlea91be9e2009-12-02 11:33:03 +0000284 " .set mips3 \n"
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200285 " li %[err], 0 \n"
286 "1: ll %[old], (%[addr]) \n"
287 " move %[tmp], %[new] \n"
288 "2: sc %[tmp], (%[addr]) \n"
289 " beqzl %[tmp], 1b \n"
290 "3: \n"
291 " .section .fixup,\"ax\" \n"
292 "4: li %[err], %[efault] \n"
293 " j 3b \n"
294 " .previous \n"
295 " .section __ex_table,\"a\" \n"
296 " "STR(PTR)" 1b, 4b \n"
297 " "STR(PTR)" 2b, 4b \n"
298 " .previous \n"
Ralf Baechlea91be9e2009-12-02 11:33:03 +0000299 " .set mips0 \n"
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200300 : [old] "=&r" (old),
301 [err] "=&r" (err),
302 [tmp] "=&r" (tmp)
303 : [addr] "r" (addr),
304 [new] "r" (new),
305 [efault] "i" (-EFAULT)
306 : "memory");
307 } else if (cpu_has_llsc) {
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 " bnez %[tmp], 4f \n"
315 "3: \n"
316 " .subsection 2 \n"
317 "4: b 1b \n"
318 " .previous \n"
319 " \n"
320 " .section .fixup,\"ax\" \n"
321 "5: li %[err], %[efault] \n"
322 " j 3b \n"
323 " .previous \n"
324 " .section __ex_table,\"a\" \n"
325 " "STR(PTR)" 1b, 5b \n"
326 " "STR(PTR)" 2b, 5b \n"
327 " .previous \n"
Ralf Baechlea91be9e2009-12-02 11:33:03 +0000328 " .set mips0 \n"
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200329 : [old] "=&r" (old),
330 [err] "=&r" (err),
331 [tmp] "=&r" (tmp)
332 : [addr] "r" (addr),
333 [new] "r" (new),
334 [efault] "i" (-EFAULT)
335 : "memory");
336 } else {
337 do {
338 preempt_disable();
339 ll_bit = 1;
340 ll_task = current;
341 preempt_enable();
342
343 err = __get_user(old, (unsigned int *) addr);
344 err |= __put_user(new, (unsigned int *) addr);
345 if (err)
346 break;
347 rmb();
348 } while (!ll_bit);
349 }
350
351 if (unlikely(err))
352 return err;
353
354 regs->regs[2] = old;
355 regs->regs[7] = 0; /* No error */
356
357 /*
358 * Don't let your children do this ...
359 */
360 __asm__ __volatile__(
361 " move $29, %0 \n"
362 " j syscall_exit \n"
363 : /* no outputs */
364 : "r" (regs));
365
366 /* unreached. Honestly. */
367 while (1);
368}
369
370save_static_function(sys_sysmips);
371static int __used noinline
372_sys_sysmips(nabi_no_regargs struct pt_regs regs)
373{
374 long cmd, arg1, arg2, arg3;
375
376 cmd = regs.regs[4];
377 arg1 = regs.regs[5];
378 arg2 = regs.regs[6];
379 arg3 = regs.regs[7];
380
Ralf Baechle293c5bd2007-07-25 16:19:33 +0100381 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 case MIPS_ATOMIC_SET:
Ralf Baechlef1e39a42009-09-17 02:25:05 +0200383 return mips_atomic_set(&regs, arg1, arg2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 case MIPS_FIXADE:
Ralf Baechle293c5bd2007-07-25 16:19:33 +0100386 if (arg1 & ~3)
387 return -EINVAL;
388
389 if (arg1 & 1)
390 set_thread_flag(TIF_FIXADE);
391 else
392 clear_thread_flag(TIF_FIXADE);
393 if (arg1 & 2)
394 set_thread_flag(TIF_LOGADE);
395 else
396 clear_thread_flag(TIF_FIXADE);
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return 0;
399
400 case FLUSH_CACHE:
401 __flush_cache_all();
402 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404
405 return -EINVAL;
406}
407
408/*
409 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
410 *
411 * This is really horribly ugly.
412 */
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000413SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, int, second,
414 unsigned long, third, void __user *, ptr, long, fifth)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
416 int version, ret;
417
418 version = call >> 16; /* hack for backward compatibility */
419 call &= 0xffff;
420
421 switch (call) {
422 case SEMOP:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100423 return sys_semtimedop(first, (struct sembuf __user *)ptr,
424 second, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 case SEMTIMEDOP:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100426 return sys_semtimedop(first, (struct sembuf __user *)ptr,
427 second,
428 (const struct timespec __user *)fifth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 case SEMGET:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100430 return sys_semget(first, second, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 case SEMCTL: {
432 union semun fourth;
433 if (!ptr)
434 return -EINVAL;
Atsushi Nemoto219ac732006-02-21 16:05:11 +0900435 if (get_user(fourth.__pad, (void __user *__user *) ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return -EFAULT;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100437 return sys_semctl(first, second, third, fourth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
439
440 case MSGSND:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100441 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
442 second, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 case MSGRCV:
444 switch (version) {
445 case 0: {
446 struct ipc_kludge tmp;
447 if (!ptr)
448 return -EINVAL;
449
450 if (copy_from_user(&tmp,
Atsushi Nemotobe6e5182006-02-08 23:39:49 +0900451 (struct ipc_kludge __user *) ptr,
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100452 sizeof(tmp)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 return -EFAULT;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100454 return sys_msgrcv(first, tmp.msgp, second,
455 tmp.msgtyp, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
457 default:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100458 return sys_msgrcv(first,
459 (struct msgbuf __user *) ptr,
460 second, fifth, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462 case MSGGET:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100463 return sys_msgget((key_t) first, second);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 case MSGCTL:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100465 return sys_msgctl(first, second,
466 (struct msqid_ds __user *) ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 case SHMAT:
469 switch (version) {
470 default: {
Ralf Baechlefc103342006-06-28 11:24:12 +0100471 unsigned long raddr;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100472 ret = do_shmat(first, (char __user *) ptr, second,
473 &raddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 if (ret)
475 return ret;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100476 return put_user(raddr, (unsigned long __user *) third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
478 case 1: /* iBCS2 emulator entry point */
479 if (!segment_eq(get_fs(), get_ds()))
480 return -EINVAL;
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100481 return do_shmat(first, (char __user *) ptr, second,
482 (unsigned long *) third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 }
484 case SHMDT:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100485 return sys_shmdt((char __user *)ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 case SHMGET:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100487 return sys_shmget(first, second, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 case SHMCTL:
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100489 return sys_shmctl(first, second,
490 (struct shmid_ds __user *) ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 default:
492 return -ENOSYS;
493 }
494}
495
496/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 * No implemented yet ...
498 */
Ralf Baechledbda6ac2009-02-08 16:00:26 +0000499SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
501 return -ENOSYS;
502}
503
504/*
505 * If we ever come here the user sp is bad. Zap the process right away.
506 * Due to the bad stack signaling wouldn't work.
507 */
508asmlinkage void bad_stack(void)
509{
510 do_exit(SIGSEGV);
511}
Arnd Bergmannfe742902006-10-02 02:18:34 -0700512
513/*
514 * Do a system call from kernel instead of calling sys_execve so we
515 * end up with proper pt_regs.
516 */
517int kernel_execve(const char *filename, char *const argv[], char *const envp[])
518{
519 register unsigned long __a0 asm("$4") = (unsigned long) filename;
520 register unsigned long __a1 asm("$5") = (unsigned long) argv;
521 register unsigned long __a2 asm("$6") = (unsigned long) envp;
522 register unsigned long __a3 asm("$7");
523 unsigned long __v0;
524
525 __asm__ volatile (" \n"
526 " .set noreorder \n"
527 " li $2, %5 # __NR_execve \n"
528 " syscall \n"
529 " move %0, $2 \n"
530 " .set reorder \n"
531 : "=&r" (__v0), "=r" (__a3)
532 : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
533 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
534 "memory");
535
536 if (__a3 == 0)
537 return __v0;
538
539 return -__v0;
540}