Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 6 | #include "linux/stddef.h" |
| 7 | #include "linux/fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include "linux/smp_lock.h" |
| 9 | #include "linux/ptrace.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 10 | #include "linux/sched.h" |
| 11 | #include "asm/current.h" |
| 12 | #include "asm/processor.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "asm/uaccess.h" |
Jeff Dike | 54ae36f | 2007-10-16 01:27:33 -0700 | [diff] [blame] | 14 | #include "as-layout.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include "mem_user.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 16 | #include "skas.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include "os.h" |
Al Viro | ff64b4c | 2008-08-18 04:01:47 -0400 | [diff] [blame] | 18 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | void flush_thread(void) |
| 21 | { |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 22 | void *data = NULL; |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 23 | int ret; |
| 24 | |
Paolo 'Blaisorblade' Giarrusso | aa6758d | 2006-03-31 02:30:22 -0800 | [diff] [blame] | 25 | arch_flush_thread(¤t->thread.arch); |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 26 | |
Jeff Dike | 3963333 | 2008-02-04 22:31:01 -0800 | [diff] [blame] | 27 | ret = unmap(¤t->mm->context.id, 0, STUB_START, 0, &data); |
| 28 | ret = ret || unmap(¤t->mm->context.id, STUB_END, |
Jeff Dike | 536788f | 2008-02-08 04:22:07 -0800 | [diff] [blame] | 29 | host_task_size - STUB_END, 1, &data); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 30 | if (ret) { |
| 31 | printk(KERN_ERR "flush_thread - clearing address space failed, " |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 32 | "err = %d\n", ret); |
| 33 | force_sig(SIGKILL, current); |
| 34 | } |
| 35 | |
Jeff Dike | 6c738ff | 2007-10-16 01:27:06 -0700 | [diff] [blame] | 36 | __switch_mm(¤t->mm->context.id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp) |
| 40 | { |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 41 | set_fs(USER_DS); |
| 42 | PT_REGS_IP(regs) = eip; |
| 43 | PT_REGS_SP(regs) = esp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | static long execve1(char *file, char __user * __user *argv, |
Paolo 'Blaisorblade' Giarrusso | 42947cb | 2006-02-01 03:06:29 -0800 | [diff] [blame] | 47 | char __user *__user *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 49 | long error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 51 | error = do_execve(file, argv, env, ¤t->thread.regs); |
| 52 | if (error == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | task_lock(current); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 54 | current->ptrace &= ~PT_DTRACE; |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 55 | #ifdef SUBARCH_EXECVE1 |
| 56 | SUBARCH_EXECVE1(¤t->thread.regs.regs); |
| 57 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | task_unlock(current); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 59 | } |
| 60 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | long um_execve(char *file, char __user *__user *argv, char __user *__user *env) |
| 64 | { |
| 65 | long err; |
| 66 | |
| 67 | err = execve1(file, argv, env); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 68 | if (!err) |
Jeff Dike | fab95c5 | 2007-10-16 01:27:05 -0700 | [diff] [blame] | 69 | UML_LONGJMP(current->thread.exec_buf, 1); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 70 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 73 | long sys_execve(char __user *file, char __user *__user *argv, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | char __user *__user *env) |
| 75 | { |
| 76 | long error; |
| 77 | char *filename; |
| 78 | |
| 79 | lock_kernel(); |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 80 | filename = getname(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | error = PTR_ERR(filename); |
| 82 | if (IS_ERR(filename)) goto out; |
| 83 | error = execve1(filename, argv, env); |
| 84 | putname(filename); |
| 85 | out: |
| 86 | unlock_kernel(); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 87 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |