exec.c 1.8 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
#include "asm/uaccess.h"
J
Jeff Dike 已提交
14
#include "as-layout.h"
L
Linus Torvalds 已提交
15
#include "mem_user.h"
J
Jeff Dike 已提交
16
#include "skas.h"
L
Linus Torvalds 已提交
17 18 19 20
#include "os.h"

void flush_thread(void)
{
21 22 23
	void *data = NULL;
	int ret;

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

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

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

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

static long execve1(char *file, char __user * __user *argv,
46
		    char __user *__user *env)
L
Linus Torvalds 已提交
47
{
J
Jeff Dike 已提交
48
	long error;
L
Linus Torvalds 已提交
49

J
Jeff Dike 已提交
50 51
	error = do_execve(file, argv, env, &current->thread.regs);
	if (error == 0) {
L
Linus Torvalds 已提交
52
		task_lock(current);
J
Jeff Dike 已提交
53
		current->ptrace &= ~PT_DTRACE;
J
Jeff Dike 已提交
54 55 56
#ifdef SUBARCH_EXECVE1
		SUBARCH_EXECVE1(&current->thread.regs.regs);
#endif
L
Linus Torvalds 已提交
57
		task_unlock(current);
J
Jeff Dike 已提交
58 59
	}
	return error;
L
Linus Torvalds 已提交
60 61 62 63 64 65 66
}

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

	err = execve1(file, argv, env);
J
Jeff Dike 已提交
67
	if (!err)
J
Jeff Dike 已提交
68
		UML_LONGJMP(current->thread.exec_buf, 1);
J
Jeff Dike 已提交
69
	return err;
L
Linus Torvalds 已提交
70 71
}

A
Al Viro 已提交
72
long sys_execve(char __user *file, char __user *__user *argv,
L
Linus Torvalds 已提交
73 74 75 76 77 78
		char __user *__user *env)
{
	long error;
	char *filename;

	lock_kernel();
A
Al Viro 已提交
79
	filename = getname(file);
L
Linus Torvalds 已提交
80 81 82 83 84 85
	error = PTR_ERR(filename);
	if (IS_ERR(filename)) goto out;
	error = execve1(filename, argv, env);
	putname(filename);
 out:
	unlock_kernel();
J
Jeff Dike 已提交
86
	return error;
L
Linus Torvalds 已提交
87
}