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 | */ |
| 10 | #include <linux/a.out.h> |
Randy Dunlap | a941564 | 2006-01-11 12:17:48 -0800 | [diff] [blame] | 11 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/errno.h> |
| 13 | #include <linux/linkage.h> |
| 14 | #include <linux/mm.h> |
| 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> |
| 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 Baechle | 9ff77c4 | 2005-03-08 14:39:39 +0000 | [diff] [blame] | 29 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include <asm/branch.h> |
| 32 | #include <asm/cachectl.h> |
| 33 | #include <asm/cacheflush.h> |
| 34 | #include <asm/ipc.h> |
Sam Ravnborg | 048eb58 | 2005-09-09 22:32:31 +0200 | [diff] [blame] | 35 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/signal.h> |
| 37 | #include <asm/sim.h> |
| 38 | #include <asm/shmparam.h> |
| 39 | #include <asm/sysmips.h> |
| 40 | #include <asm/uaccess.h> |
| 41 | |
| 42 | asmlinkage int sys_pipe(nabi_no_regargs volatile struct pt_regs regs) |
| 43 | { |
| 44 | int fd[2]; |
| 45 | int error, res; |
| 46 | |
| 47 | error = do_pipe(fd); |
| 48 | if (error) { |
| 49 | res = error; |
| 50 | goto out; |
| 51 | } |
| 52 | regs.regs[3] = fd[1]; |
| 53 | res = fd[0]; |
| 54 | out: |
| 55 | return res; |
| 56 | } |
| 57 | |
| 58 | unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ |
| 59 | |
Ralf Baechle | 9ff77c4 | 2005-03-08 14:39:39 +0000 | [diff] [blame] | 60 | EXPORT_SYMBOL(shm_align_mask); |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #define COLOUR_ALIGN(addr,pgoff) \ |
| 63 | ((((addr) + shm_align_mask) & ~shm_align_mask) + \ |
| 64 | (((pgoff) << PAGE_SHIFT) & shm_align_mask)) |
| 65 | |
| 66 | unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, |
| 67 | unsigned long len, unsigned long pgoff, unsigned long flags) |
| 68 | { |
| 69 | struct vm_area_struct * vmm; |
| 70 | int do_color_align; |
| 71 | unsigned long task_size; |
| 72 | |
| 73 | task_size = STACK_TOP; |
| 74 | |
| 75 | if (flags & MAP_FIXED) { |
| 76 | /* |
| 77 | * We do not accept a shared mapping if it would violate |
| 78 | * cache aliasing constraints. |
| 79 | */ |
| 80 | if ((flags & MAP_SHARED) && (addr & shm_align_mask)) |
| 81 | return -EINVAL; |
| 82 | return addr; |
| 83 | } |
| 84 | |
| 85 | if (len > task_size) |
| 86 | return -ENOMEM; |
| 87 | do_color_align = 0; |
| 88 | if (filp || (flags & MAP_SHARED)) |
| 89 | do_color_align = 1; |
| 90 | if (addr) { |
| 91 | if (do_color_align) |
| 92 | addr = COLOUR_ALIGN(addr, pgoff); |
| 93 | else |
| 94 | addr = PAGE_ALIGN(addr); |
| 95 | vmm = find_vma(current->mm, addr); |
| 96 | if (task_size - len >= addr && |
| 97 | (!vmm || addr + len <= vmm->vm_start)) |
| 98 | return addr; |
| 99 | } |
| 100 | addr = TASK_UNMAPPED_BASE; |
| 101 | if (do_color_align) |
| 102 | addr = COLOUR_ALIGN(addr, pgoff); |
| 103 | else |
| 104 | addr = PAGE_ALIGN(addr); |
| 105 | |
| 106 | for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) { |
| 107 | /* At this point: (!vmm || addr < vmm->vm_end). */ |
| 108 | if (task_size - len < addr) |
| 109 | return -ENOMEM; |
| 110 | if (!vmm || addr + len <= vmm->vm_start) |
| 111 | return addr; |
| 112 | addr = vmm->vm_end; |
| 113 | if (do_color_align) |
| 114 | addr = COLOUR_ALIGN(addr, pgoff); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /* common code for old and new mmaps */ |
| 119 | static inline unsigned long |
| 120 | do_mmap2(unsigned long addr, unsigned long len, unsigned long prot, |
| 121 | unsigned long flags, unsigned long fd, unsigned long pgoff) |
| 122 | { |
| 123 | unsigned long error = -EBADF; |
| 124 | struct file * file = NULL; |
| 125 | |
| 126 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 127 | if (!(flags & MAP_ANONYMOUS)) { |
| 128 | file = fget(fd); |
| 129 | if (!file) |
| 130 | goto out; |
| 131 | } |
| 132 | |
| 133 | down_write(¤t->mm->mmap_sem); |
| 134 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
| 135 | up_write(¤t->mm->mmap_sem); |
| 136 | |
| 137 | if (file) |
| 138 | fput(file); |
| 139 | out: |
| 140 | return error; |
| 141 | } |
| 142 | |
| 143 | asmlinkage unsigned long |
| 144 | old_mmap(unsigned long addr, unsigned long len, int prot, |
| 145 | int flags, int fd, off_t offset) |
| 146 | { |
| 147 | unsigned long result; |
| 148 | |
| 149 | result = -EINVAL; |
| 150 | if (offset & ~PAGE_MASK) |
| 151 | goto out; |
| 152 | |
| 153 | result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
| 154 | |
| 155 | out: |
| 156 | return result; |
| 157 | } |
| 158 | |
| 159 | asmlinkage unsigned long |
| 160 | sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot, |
| 161 | unsigned long flags, unsigned long fd, unsigned long pgoff) |
| 162 | { |
H. Peter Anvin | 947df17 | 2006-02-24 21:20:29 -0800 | [diff] [blame] | 163 | if (pgoff & (~PAGE_MASK >> 12)) |
| 164 | return -EINVAL; |
| 165 | |
| 166 | return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | save_static_function(sys_fork); |
David Rientjes | f5dbeaf | 2007-07-22 01:01:39 -0700 | [diff] [blame^] | 170 | static int __used noinline |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | _sys_fork(nabi_no_regargs struct pt_regs regs) |
| 172 | { |
| 173 | return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL); |
| 174 | } |
| 175 | |
| 176 | save_static_function(sys_clone); |
David Rientjes | f5dbeaf | 2007-07-22 01:01:39 -0700 | [diff] [blame^] | 177 | static int __used noinline |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | _sys_clone(nabi_no_regargs struct pt_regs regs) |
| 179 | { |
| 180 | unsigned long clone_flags; |
| 181 | unsigned long newsp; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 182 | int __user *parent_tidptr, *child_tidptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | clone_flags = regs.regs[4]; |
| 185 | newsp = regs.regs[5]; |
| 186 | if (!newsp) |
| 187 | newsp = regs.regs[29]; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 188 | parent_tidptr = (int __user *) regs.regs[6]; |
| 189 | #ifdef CONFIG_32BIT |
| 190 | /* We need to fetch the fifth argument off the stack. */ |
| 191 | child_tidptr = NULL; |
| 192 | if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) { |
| 193 | int __user *__user *usp = (int __user *__user *) regs.regs[29]; |
| 194 | if (regs.regs[2] == __NR_syscall) { |
| 195 | if (get_user (child_tidptr, &usp[5])) |
| 196 | return -EFAULT; |
| 197 | } |
| 198 | else if (get_user (child_tidptr, &usp[4])) |
| 199 | return -EFAULT; |
| 200 | } |
| 201 | #else |
| 202 | child_tidptr = (int __user *) regs.regs[8]; |
| 203 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | return do_fork(clone_flags, newsp, ®s, 0, |
| 205 | parent_tidptr, child_tidptr); |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * sys_execve() executes a new program. |
| 210 | */ |
| 211 | asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs) |
| 212 | { |
| 213 | int error; |
| 214 | char * filename; |
| 215 | |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 216 | filename = getname((char __user *) (long)regs.regs[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | error = PTR_ERR(filename); |
| 218 | if (IS_ERR(filename)) |
| 219 | goto out; |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 220 | error = do_execve(filename, (char __user *__user *) (long)regs.regs[5], |
| 221 | (char __user *__user *) (long)regs.regs[6], ®s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | putname(filename); |
| 223 | |
| 224 | out: |
| 225 | return error; |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Compacrapability ... |
| 230 | */ |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 231 | asmlinkage int sys_uname(struct old_utsname __user * name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 233 | if (name && !copy_to_user(name, utsname(), sizeof (*name))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return 0; |
| 235 | return -EFAULT; |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | * Compacrapability ... |
| 240 | */ |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 241 | asmlinkage int sys_olduname(struct oldold_utsname __user * name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | int error; |
| 244 | |
| 245 | if (!name) |
| 246 | return -EFAULT; |
| 247 | if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) |
| 248 | return -EFAULT; |
| 249 | |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 250 | error = __copy_to_user(&name->sysname, &utsname()->sysname, |
| 251 | __OLD_UTS_LEN); |
| 252 | error -= __put_user(0, name->sysname + __OLD_UTS_LEN); |
| 253 | error -= __copy_to_user(&name->nodename, &utsname()->nodename, |
| 254 | __OLD_UTS_LEN); |
| 255 | error -= __put_user(0, name->nodename + __OLD_UTS_LEN); |
| 256 | error -= __copy_to_user(&name->release, &utsname()->release, |
| 257 | __OLD_UTS_LEN); |
| 258 | error -= __put_user(0, name->release + __OLD_UTS_LEN); |
| 259 | error -= __copy_to_user(&name->version, &utsname()->version, |
| 260 | __OLD_UTS_LEN); |
| 261 | error -= __put_user(0, name->version + __OLD_UTS_LEN); |
| 262 | error -= __copy_to_user(&name->machine, &utsname()->machine, |
| 263 | __OLD_UTS_LEN); |
| 264 | error = __put_user(0, name->machine + __OLD_UTS_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | error = error ? -EFAULT : 0; |
| 266 | |
| 267 | return error; |
| 268 | } |
| 269 | |
Ralf Baechle | 06be375 | 2006-09-19 17:18:53 +0100 | [diff] [blame] | 270 | asmlinkage int sys_set_thread_area(unsigned long addr) |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 271 | { |
Al Viro | dc8f602 | 2006-01-12 01:06:07 -0800 | [diff] [blame] | 272 | struct thread_info *ti = task_thread_info(current); |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 273 | |
| 274 | ti->tp_value = addr; |
Ralf Baechle | a369202 | 2007-07-10 17:33:02 +0100 | [diff] [blame] | 275 | if (cpu_has_userlocal) |
| 276 | write_c0_userlocal(addr); |
Ralf Baechle | 06be375 | 2006-09-19 17:18:53 +0100 | [diff] [blame] | 277 | |
| 278 | return 0; |
Ralf Baechle | 3c37026 | 2005-04-13 17:43:59 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3) |
| 282 | { |
Atsushi Nemoto | ecf52d3 | 2006-06-01 01:00:03 +0900 | [diff] [blame] | 283 | int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | switch(cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | case MIPS_ATOMIC_SET: |
| 287 | printk(KERN_CRIT "How did I get here?\n"); |
| 288 | return -EINVAL; |
| 289 | |
| 290 | case MIPS_FIXADE: |
| 291 | tmp = current->thread.mflags & ~3; |
| 292 | current->thread.mflags = tmp | (arg1 & 3); |
| 293 | return 0; |
| 294 | |
| 295 | case FLUSH_CACHE: |
| 296 | __flush_cache_all(); |
| 297 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | return -EINVAL; |
| 301 | } |
| 302 | |
| 303 | /* |
| 304 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
| 305 | * |
| 306 | * This is really horribly ugly. |
| 307 | */ |
Ralf Baechle | fc10334 | 2006-06-28 11:24:12 +0100 | [diff] [blame] | 308 | asmlinkage int sys_ipc (unsigned int call, int first, int second, |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 309 | unsigned long third, void __user *ptr, long fifth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
| 311 | int version, ret; |
| 312 | |
| 313 | version = call >> 16; /* hack for backward compatibility */ |
| 314 | call &= 0xffff; |
| 315 | |
| 316 | switch (call) { |
| 317 | case SEMOP: |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 318 | return sys_semtimedop (first, (struct sembuf __user *)ptr, |
| 319 | second, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | case SEMTIMEDOP: |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 321 | return sys_semtimedop (first, (struct sembuf __user *)ptr, |
| 322 | second, |
| 323 | (const struct timespec __user *)fifth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | case SEMGET: |
| 325 | return sys_semget (first, second, third); |
| 326 | case SEMCTL: { |
| 327 | union semun fourth; |
| 328 | if (!ptr) |
| 329 | return -EINVAL; |
Atsushi Nemoto | 219ac73 | 2006-02-21 16:05:11 +0900 | [diff] [blame] | 330 | if (get_user(fourth.__pad, (void __user *__user *) ptr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | return -EFAULT; |
| 332 | return sys_semctl (first, second, third, fourth); |
| 333 | } |
| 334 | |
| 335 | case MSGSND: |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 336 | return sys_msgsnd (first, (struct msgbuf __user *) ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | second, third); |
| 338 | case MSGRCV: |
| 339 | switch (version) { |
| 340 | case 0: { |
| 341 | struct ipc_kludge tmp; |
| 342 | if (!ptr) |
| 343 | return -EINVAL; |
| 344 | |
| 345 | if (copy_from_user(&tmp, |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 346 | (struct ipc_kludge __user *) ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | sizeof (tmp))) |
| 348 | return -EFAULT; |
| 349 | return sys_msgrcv (first, tmp.msgp, second, |
| 350 | tmp.msgtyp, third); |
| 351 | } |
| 352 | default: |
| 353 | return sys_msgrcv (first, |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 354 | (struct msgbuf __user *) ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | second, fifth, third); |
| 356 | } |
| 357 | case MSGGET: |
| 358 | return sys_msgget ((key_t) first, second); |
| 359 | case MSGCTL: |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 360 | return sys_msgctl (first, second, |
| 361 | (struct msqid_ds __user *) ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | case SHMAT: |
| 364 | switch (version) { |
| 365 | default: { |
Ralf Baechle | fc10334 | 2006-06-28 11:24:12 +0100 | [diff] [blame] | 366 | unsigned long raddr; |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 367 | ret = do_shmat (first, (char __user *) ptr, second, |
| 368 | &raddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | if (ret) |
| 370 | return ret; |
Ralf Baechle | fc10334 | 2006-06-28 11:24:12 +0100 | [diff] [blame] | 371 | return put_user (raddr, (unsigned long __user *) third); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | case 1: /* iBCS2 emulator entry point */ |
| 374 | if (!segment_eq(get_fs(), get_ds())) |
| 375 | return -EINVAL; |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 376 | return do_shmat (first, (char __user *) ptr, second, |
Ralf Baechle | fc10334 | 2006-06-28 11:24:12 +0100 | [diff] [blame] | 377 | (unsigned long *) third); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | case SHMDT: |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 380 | return sys_shmdt ((char __user *)ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | case SHMGET: |
| 382 | return sys_shmget (first, second, third); |
| 383 | case SHMCTL: |
| 384 | return sys_shmctl (first, second, |
Atsushi Nemoto | be6e518 | 2006-02-08 23:39:49 +0900 | [diff] [blame] | 385 | (struct shmid_ds __user *) ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | default: |
| 387 | return -ENOSYS; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | * No implemented yet ... |
| 393 | */ |
| 394 | asmlinkage int sys_cachectl(char *addr, int nbytes, int op) |
| 395 | { |
| 396 | return -ENOSYS; |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * If we ever come here the user sp is bad. Zap the process right away. |
| 401 | * Due to the bad stack signaling wouldn't work. |
| 402 | */ |
| 403 | asmlinkage void bad_stack(void) |
| 404 | { |
| 405 | do_exit(SIGSEGV); |
| 406 | } |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 407 | |
| 408 | /* |
| 409 | * Do a system call from kernel instead of calling sys_execve so we |
| 410 | * end up with proper pt_regs. |
| 411 | */ |
| 412 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]) |
| 413 | { |
| 414 | register unsigned long __a0 asm("$4") = (unsigned long) filename; |
| 415 | register unsigned long __a1 asm("$5") = (unsigned long) argv; |
| 416 | register unsigned long __a2 asm("$6") = (unsigned long) envp; |
| 417 | register unsigned long __a3 asm("$7"); |
| 418 | unsigned long __v0; |
| 419 | |
| 420 | __asm__ volatile (" \n" |
| 421 | " .set noreorder \n" |
| 422 | " li $2, %5 # __NR_execve \n" |
| 423 | " syscall \n" |
| 424 | " move %0, $2 \n" |
| 425 | " .set reorder \n" |
| 426 | : "=&r" (__v0), "=r" (__a3) |
| 427 | : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve) |
| 428 | : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", |
| 429 | "memory"); |
| 430 | |
| 431 | if (__a3 == 0) |
| 432 | return __v0; |
| 433 | |
| 434 | return -__v0; |
| 435 | } |