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