blob: 76a62c0cb2bc89692e72df74a096df83f33487e5 [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"
11#include "asm/current.h"
12#include "asm/processor.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "asm/uaccess.h"
Jeff Dike54ae36f2007-10-16 01:27:33 -070014#include "as-layout.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "mem_user.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070016#include "skas.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "os.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19void flush_thread(void)
20{
Jeff Dike77bf4402007-10-16 01:26:58 -070021 void *data = NULL;
Jeff Dike77bf4402007-10-16 01:26:58 -070022 int ret;
23
Paolo 'Blaisorblade' Giarrussoaa6758d2006-03-31 02:30:22 -080024 arch_flush_thread(&current->thread.arch);
Jeff Dike77bf4402007-10-16 01:26:58 -070025
Jeff Dike39633332008-02-04 22:31:01 -080026 ret = unmap(&current->mm->context.id, 0, STUB_START, 0, &data);
27 ret = ret || unmap(&current->mm->context.id, STUB_END,
28 TASK_SIZE - STUB_END, 1, &data);
Jeff Dikeba180fd2007-10-16 01:27:00 -070029 if (ret) {
30 printk(KERN_ERR "flush_thread - clearing address space failed, "
Jeff Dike77bf4402007-10-16 01:26:58 -070031 "err = %d\n", ret);
32 force_sig(SIGKILL, current);
33 }
34
Jeff Dike6c738ff2007-10-16 01:27:06 -070035 __switch_mm(&current->mm->context.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
38void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
39{
Jeff Dike77bf4402007-10-16 01:26:58 -070040 set_fs(USER_DS);
41 PT_REGS_IP(regs) = eip;
42 PT_REGS_SP(regs) = esp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Jeff Dike1d3468a2006-07-10 04:45:13 -070045#ifdef CONFIG_TTY_LOG
46extern void log_exec(char **argv, void *tty);
47#endif
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static long execve1(char *file, char __user * __user *argv,
Paolo 'Blaisorblade' Giarrusso42947cb2006-02-01 03:06:29 -080050 char __user *__user *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Jeff Dikeba180fd2007-10-16 01:27:00 -070052 long error;
Jeff Dikef9795222007-02-10 01:44:03 -080053#ifdef CONFIG_TTY_LOG
Peter Zijlstra24ec8392006-12-08 02:36:04 -080054 struct tty_struct *tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Alan Coxb1fc0b12006-09-25 23:33:08 -070056 mutex_lock(&tty_mutex);
Peter Zijlstra24ec8392006-12-08 02:36:04 -080057 tty = get_current_tty();
58 if (tty)
59 log_exec(argv, tty);
Alan Coxb1fc0b12006-09-25 23:33:08 -070060 mutex_unlock(&tty_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#endif
Jeff Dikeba180fd2007-10-16 01:27:00 -070062 error = do_execve(file, argv, env, &current->thread.regs);
63 if (error == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 task_lock(current);
Jeff Dikeba180fd2007-10-16 01:27:00 -070065 current->ptrace &= ~PT_DTRACE;
Jeff Dike1d3468a2006-07-10 04:45:13 -070066#ifdef SUBARCH_EXECVE1
67 SUBARCH_EXECVE1(&current->thread.regs.regs);
68#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 task_unlock(current);
Jeff Dikeba180fd2007-10-16 01:27:00 -070070 }
71 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
74long um_execve(char *file, char __user *__user *argv, char __user *__user *env)
75{
76 long err;
77
78 err = execve1(file, argv, env);
Jeff Dikeba180fd2007-10-16 01:27:00 -070079 if (!err)
Jeff Dikefab95c52007-10-16 01:27:05 -070080 UML_LONGJMP(current->thread.exec_buf, 1);
Jeff Dikeba180fd2007-10-16 01:27:00 -070081 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Al Viro4d338e12006-03-31 02:30:15 -080084long sys_execve(char __user *file, char __user *__user *argv,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 char __user *__user *env)
86{
87 long error;
88 char *filename;
89
90 lock_kernel();
Al Viro4d338e12006-03-31 02:30:15 -080091 filename = getname(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 error = PTR_ERR(filename);
93 if (IS_ERR(filename)) goto out;
94 error = execve1(filename, argv, env);
95 putname(filename);
96 out:
97 unlock_kernel();
Jeff Dikeba180fd2007-10-16 01:27:00 -070098 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}