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 | |
Al Viro | 73395a0 | 2011-08-18 20:14:10 +0100 | [diff] [blame] | 6 | #include <linux/stddef.h> |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/fs.h> |
| 9 | #include <linux/ptrace.h> |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <asm/current.h> |
| 13 | #include <asm/processor.h> |
| 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 | { |
Al Viro | bf56d57 | 2012-09-05 23:20:33 -0400 | [diff] [blame^] | 42 | get_safe_registers(regs->regs.gp, regs->regs.fp); |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 43 | PT_REGS_IP(regs) = eip; |
| 44 | PT_REGS_SP(regs) = esp; |
Al Viro | 4245979 | 2012-09-03 03:24:18 -0400 | [diff] [blame] | 45 | current->ptrace &= ~PT_DTRACE; |
| 46 | #ifdef SUBARCH_EXECVE1 |
| 47 | SUBARCH_EXECVE1(regs->regs); |
| 48 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
Al Viro | 73395a0 | 2011-08-18 20:14:10 +0100 | [diff] [blame] | 50 | EXPORT_SYMBOL(start_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Richard Weinberger | cb1dcc0 | 2010-09-22 13:05:07 -0700 | [diff] [blame] | 52 | 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] | 53 | { |
| 54 | long err; |
| 55 | |
Al Viro | 4245979 | 2012-09-03 03:24:18 -0400 | [diff] [blame] | 56 | err = do_execve(file, argv, env, ¤t->thread.regs); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 57 | if (!err) |
Jeff Dike | fab95c5 | 2007-10-16 01:27:05 -0700 | [diff] [blame] | 58 | UML_LONGJMP(current->thread.exec_buf, 1); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 59 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Richard Weinberger | cb1dcc0 | 2010-09-22 13:05:07 -0700 | [diff] [blame] | 62 | long sys_execve(const char __user *file, const char __user *const __user *argv, |
| 63 | const char __user *const __user *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 65 | long error; |
| 66 | char *filename; |
| 67 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 68 | filename = getname(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | error = PTR_ERR(filename); |
| 70 | if (IS_ERR(filename)) goto out; |
Al Viro | 4245979 | 2012-09-03 03:24:18 -0400 | [diff] [blame] | 71 | error = do_execve(filename, argv, env, ¤t->thread.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | putname(filename); |
| 73 | out: |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 74 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |