exec.c 2.0 KB
Newer Older
J
Jeff Dike 已提交
1
/*
J
Jeff Dike 已提交
2
 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
L
Linus Torvalds 已提交
3 4 5
 * Licensed under the GPL
 */

J
Jeff Dike 已提交
6 7
#include "linux/stddef.h"
#include "linux/fs.h"
L
Linus Torvalds 已提交
8 9
#include "linux/smp_lock.h"
#include "linux/ptrace.h"
J
Jeff Dike 已提交
10 11 12
#include "linux/sched.h"
#include "asm/current.h"
#include "asm/processor.h"
L
Linus Torvalds 已提交
13 14
#include "asm/uaccess.h"
#include "mem_user.h"
J
Jeff Dike 已提交
15
#include "skas.h"
L
Linus Torvalds 已提交
16 17 18 19
#include "os.h"

void flush_thread(void)
{
20 21 22 23
	void *data = NULL;
	unsigned long end = proc_mm ? task_size : CONFIG_STUB_START;
	int ret;

24
	arch_flush_thread(&current->thread.arch);
25

26
	ret = unmap(&current->mm->context.id, 0, end, 1, &data);
J
Jeff Dike 已提交
27 28
	if (ret) {
		printk(KERN_ERR "flush_thread - clearing address space failed, "
29 30 31 32
		       "err = %d\n", ret);
		force_sig(SIGKILL, current);
	}

33
	__switch_mm(&current->mm->context.id);
L
Linus Torvalds 已提交
34 35 36 37
}

void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
{
38 39 40
	set_fs(USER_DS);
	PT_REGS_IP(regs) = eip;
	PT_REGS_SP(regs) = esp;
L
Linus Torvalds 已提交
41 42
}

J
Jeff Dike 已提交
43 44 45 46
#ifdef CONFIG_TTY_LOG
extern void log_exec(char **argv, void *tty);
#endif

L
Linus Torvalds 已提交
47
static long execve1(char *file, char __user * __user *argv,
48
		    char __user *__user *env)
L
Linus Torvalds 已提交
49
{
J
Jeff Dike 已提交
50
	long error;
51
#ifdef CONFIG_TTY_LOG
52
	struct tty_struct *tty;
L
Linus Torvalds 已提交
53

A
Alan Cox 已提交
54
	mutex_lock(&tty_mutex);
55 56 57
	tty = get_current_tty();
	if (tty)
		log_exec(argv, tty);
A
Alan Cox 已提交
58
	mutex_unlock(&tty_mutex);
L
Linus Torvalds 已提交
59
#endif
J
Jeff Dike 已提交
60 61
	error = do_execve(file, argv, env, &current->thread.regs);
	if (error == 0) {
L
Linus Torvalds 已提交
62
		task_lock(current);
J
Jeff Dike 已提交
63
		current->ptrace &= ~PT_DTRACE;
J
Jeff Dike 已提交
64 65 66
#ifdef SUBARCH_EXECVE1
		SUBARCH_EXECVE1(&current->thread.regs.regs);
#endif
L
Linus Torvalds 已提交
67
		task_unlock(current);
J
Jeff Dike 已提交
68 69
	}
	return error;
L
Linus Torvalds 已提交
70 71 72 73 74 75 76
}

long um_execve(char *file, char __user *__user *argv, char __user *__user *env)
{
	long err;

	err = execve1(file, argv, env);
J
Jeff Dike 已提交
77
	if (!err)
J
Jeff Dike 已提交
78
		UML_LONGJMP(current->thread.exec_buf, 1);
J
Jeff Dike 已提交
79
	return err;
L
Linus Torvalds 已提交
80 81
}

A
Al Viro 已提交
82
long sys_execve(char __user *file, char __user *__user *argv,
L
Linus Torvalds 已提交
83 84 85 86 87 88
		char __user *__user *env)
{
	long error;
	char *filename;

	lock_kernel();
A
Al Viro 已提交
89
	filename = getname(file);
L
Linus Torvalds 已提交
90 91 92 93 94 95
	error = PTR_ERR(filename);
	if (IS_ERR(filename)) goto out;
	error = execve1(filename, argv, env);
	putname(filename);
 out:
	unlock_kernel();
J
Jeff Dike 已提交
96
	return error;
L
Linus Torvalds 已提交
97
}