exec.c 2.1 KB
Newer Older
J
Jeff Dike 已提交
1
/*
L
Linus Torvalds 已提交
2 3 4 5 6 7 8
 * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
 * Licensed under the GPL
 */

#include "linux/slab.h"
#include "linux/smp_lock.h"
#include "linux/ptrace.h"
A
Alexey Dobriyan 已提交
9
#include "linux/fs.h"
L
Linus Torvalds 已提交
10 11 12 13 14
#include "asm/ptrace.h"
#include "asm/pgtable.h"
#include "asm/tlbflush.h"
#include "asm/uaccess.h"
#include "kern_util.h"
J
Jeff Dike 已提交
15
#include "as-layout.h"
L
Linus Torvalds 已提交
16 17 18 19 20
#include "mem_user.h"
#include "kern.h"
#include "irq_user.h"
#include "tlb.h"
#include "os.h"
21
#include "skas/skas.h"
L
Linus Torvalds 已提交
22 23 24

void flush_thread(void)
{
25 26 27 28
	void *data = NULL;
	unsigned long end = proc_mm ? task_size : CONFIG_STUB_START;
	int ret;

29
	arch_flush_thread(&current->thread.arch);
30 31 32 33 34 35 36 37 38

	ret = unmap(&current->mm->context.skas.id, 0, end, 1, &data);
	if(ret){
		printk("flush_thread - clearing address space failed, "
		       "err = %d\n", ret);
		force_sig(SIGKILL, current);
	}

	__switch_mm(&current->mm->context.skas.id);
L
Linus Torvalds 已提交
39 40 41 42
}

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

J
Jeff Dike 已提交
48 49 50 51
#ifdef CONFIG_TTY_LOG
extern void log_exec(char **argv, void *tty);
#endif

L
Linus Torvalds 已提交
52
static long execve1(char *file, char __user * __user *argv,
53
		    char __user *__user *env)
L
Linus Torvalds 已提交
54 55
{
        long error;
56
#ifdef CONFIG_TTY_LOG
57
	struct tty_struct *tty;
L
Linus Torvalds 已提交
58

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

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

	err = execve1(file, argv, env);
	if(!err)
		do_longjmp(current->thread.exec_buf, 1);
	return(err);
}

A
Al Viro 已提交
87
long sys_execve(char __user *file, char __user *__user *argv,
L
Linus Torvalds 已提交
88 89 90 91 92 93
		char __user *__user *env)
{
	long error;
	char *filename;

	lock_kernel();
A
Al Viro 已提交
94
	filename = getname(file);
L
Linus Torvalds 已提交
95 96 97 98 99 100 101 102
	error = PTR_ERR(filename);
	if (IS_ERR(filename)) goto out;
	error = execve1(filename, argv, env);
	putname(filename);
 out:
	unlock_kernel();
	return(error);
}