blob: 49b5e1eb32622abbdab4b3631207460bc80a1e14 [file] [log] [blame]
Jeff Dike1d3468a2006-07-10 04:45:13 -07001/*
Jeff Dikeba180fd2007-10-16 01:27:00 -07002 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Licensed under the GPL
4 */
5
Jeff Dikeba180fd2007-10-16 01:27:00 -07006#include "linux/stddef.h"
7#include "linux/fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include "linux/smp_lock.h"
9#include "linux/ptrace.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070010#include "linux/sched.h"
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include "linux/slab.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070012#include "asm/current.h"
13#include "asm/processor.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include "asm/uaccess.h"
Jeff Dike54ae36f2007-10-16 01:27:33 -070015#include "as-layout.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include "mem_user.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070017#include "skas.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "os.h"
Al Viroff64b4c2008-08-18 04:01:47 -040019#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21void flush_thread(void)
22{
Jeff Dike77bf4402007-10-16 01:26:58 -070023 void *data = NULL;
Jeff Dike77bf4402007-10-16 01:26:58 -070024 int ret;
25
Paolo 'Blaisorblade' Giarrussoaa6758d2006-03-31 02:30:22 -080026 arch_flush_thread(&current->thread.arch);
Jeff Dike77bf4402007-10-16 01:26:58 -070027
Jeff Dike39633332008-02-04 22:31:01 -080028 ret = unmap(&current->mm->context.id, 0, STUB_START, 0, &data);
29 ret = ret || unmap(&current->mm->context.id, STUB_END,
Jeff Dike536788f2008-02-08 04:22:07 -080030 host_task_size - STUB_END, 1, &data);
Jeff Dikeba180fd2007-10-16 01:27:00 -070031 if (ret) {
32 printk(KERN_ERR "flush_thread - clearing address space failed, "
Jeff Dike77bf4402007-10-16 01:26:58 -070033 "err = %d\n", ret);
34 force_sig(SIGKILL, current);
35 }
36
Jeff Dike6c738ff2007-10-16 01:27:06 -070037 __switch_mm(&current->mm->context.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
40void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
41{
Jeff Dike77bf4402007-10-16 01:26:58 -070042 set_fs(USER_DS);
43 PT_REGS_IP(regs) = eip;
44 PT_REGS_SP(regs) = esp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
David Howellsd7627462010-08-17 23:52:56 +010047static long execve1(const char *file,
48 const char __user *const __user *argv,
49 const char __user *const __user *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Jeff Dikeba180fd2007-10-16 01:27:00 -070051 long error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Jeff Dikeba180fd2007-10-16 01:27:00 -070053 error = do_execve(file, argv, env, &current->thread.regs);
54 if (error == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 task_lock(current);
Jeff Dikeba180fd2007-10-16 01:27:00 -070056 current->ptrace &= ~PT_DTRACE;
Jeff Dike1d3468a2006-07-10 04:45:13 -070057#ifdef SUBARCH_EXECVE1
58 SUBARCH_EXECVE1(&current->thread.regs.regs);
59#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 task_unlock(current);
Jeff Dikeba180fd2007-10-16 01:27:00 -070061 }
62 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Richard Weinbergercb1dcc02010-09-22 13:05:07 -070065long um_execve(const char *file, const char __user *const __user *argv, const char __user *const __user *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 long err;
68
69 err = execve1(file, argv, env);
Jeff Dikeba180fd2007-10-16 01:27:00 -070070 if (!err)
Jeff Dikefab95c52007-10-16 01:27:05 -070071 UML_LONGJMP(current->thread.exec_buf, 1);
Jeff Dikeba180fd2007-10-16 01:27:00 -070072 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
Richard Weinbergercb1dcc02010-09-22 13:05:07 -070075long sys_execve(const char __user *file, const char __user *const __user *argv,
76 const char __user *const __user *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
78 long error;
79 char *filename;
80
81 lock_kernel();
Al Viro4d338e12006-03-31 02:30:15 -080082 filename = getname(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 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 Dikeba180fd2007-10-16 01:27:00 -070089 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}