xref: /openbmc/linux/arch/um/kernel/exec.c (revision 77bf4400319db9d2a8af6b00c2be6faa0f3d07cb)
1 /*
2  * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5 
6 #include "linux/slab.h"
7 #include "linux/smp_lock.h"
8 #include "linux/ptrace.h"
9 #include "linux/fs.h"
10 #include "asm/ptrace.h"
11 #include "asm/pgtable.h"
12 #include "asm/tlbflush.h"
13 #include "asm/uaccess.h"
14 #include "kern_util.h"
15 #include "as-layout.h"
16 #include "mem_user.h"
17 #include "kern.h"
18 #include "irq_user.h"
19 #include "tlb.h"
20 #include "os.h"
21 #include "skas/skas.h"
22 
23 void flush_thread(void)
24 {
25 	void *data = NULL;
26 	unsigned long end = proc_mm ? task_size : CONFIG_STUB_START;
27 	int ret;
28 
29 	arch_flush_thread(&current->thread.arch);
30 
31 	ret = unmap(&current->mm->context.skas.id, 0, end, 1, &data);
32 	if(ret){
33 		printk("flush_thread - clearing address space failed, "
34 		       "err = %d\n", ret);
35 		force_sig(SIGKILL, current);
36 	}
37 
38 	__switch_mm(&current->mm->context.skas.id);
39 }
40 
41 void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
42 {
43 	set_fs(USER_DS);
44 	PT_REGS_IP(regs) = eip;
45 	PT_REGS_SP(regs) = esp;
46 }
47 
48 #ifdef CONFIG_TTY_LOG
49 extern void log_exec(char **argv, void *tty);
50 #endif
51 
52 static long execve1(char *file, char __user * __user *argv,
53 		    char __user *__user *env)
54 {
55         long error;
56 #ifdef CONFIG_TTY_LOG
57 	struct tty_struct *tty;
58 
59 	mutex_lock(&tty_mutex);
60 	tty = get_current_tty();
61 	if (tty)
62 		log_exec(argv, tty);
63 	mutex_unlock(&tty_mutex);
64 #endif
65         error = do_execve(file, argv, env, &current->thread.regs);
66         if (error == 0){
67 		task_lock(current);
68                 current->ptrace &= ~PT_DTRACE;
69 #ifdef SUBARCH_EXECVE1
70 		SUBARCH_EXECVE1(&current->thread.regs.regs);
71 #endif
72 		task_unlock(current);
73         }
74         return(error);
75 }
76 
77 long um_execve(char *file, char __user *__user *argv, char __user *__user *env)
78 {
79 	long err;
80 
81 	err = execve1(file, argv, env);
82 	if(!err)
83 		do_longjmp(current->thread.exec_buf, 1);
84 	return(err);
85 }
86 
87 long sys_execve(char __user *file, char __user *__user *argv,
88 		char __user *__user *env)
89 {
90 	long error;
91 	char *filename;
92 
93 	lock_kernel();
94 	filename = getname(file);
95 	error = PTR_ERR(filename);
96 	if (IS_ERR(filename)) goto out;
97 	error = execve1(filename, argv, env);
98 	putname(filename);
99  out:
100 	unlock_kernel();
101 	return(error);
102 }
103