blob: 8c82786da823df2cdf53ad9361b9b950d85018c7 [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
Al Viro73395a02011-08-18 20:14:10 +01006#include <linux/stddef.h>
7#include <linux/module.h>
8#include <linux/fs.h>
9#include <linux/ptrace.h>
10#include <linux/sched.h>
11#include <linux/slab.h>
12#include <asm/current.h>
13#include <asm/processor.h>
14#include <asm/uaccess.h>
Jeff Dike54ae36f2007-10-16 01:27:33 -070015#include "as-layout.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include "mem_user.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070017#include "skas.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "os.h"
Al Viroff64b4c2008-08-18 04:01:47 -040019#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21void flush_thread(void)
22{
Jeff Dike77bf4402007-10-16 01:26:58 -070023 void *data = NULL;
Jeff Dike77bf4402007-10-16 01:26:58 -070024 int ret;
25
Paolo 'Blaisorblade' Giarrussoaa6758d2006-03-31 02:30:22 -080026 arch_flush_thread(&current->thread.arch);
Jeff Dike77bf4402007-10-16 01:26:58 -070027
Jeff Dike39633332008-02-04 22:31:01 -080028 ret = unmap(&current->mm->context.id, 0, STUB_START, 0, &data);
29 ret = ret || unmap(&current->mm->context.id, STUB_END,
Jeff Dike536788f2008-02-08 04:22:07 -080030 host_task_size - STUB_END, 1, &data);
Jeff Dikeba180fd2007-10-16 01:27:00 -070031 if (ret) {
32 printk(KERN_ERR "flush_thread - clearing address space failed, "
Jeff Dike77bf4402007-10-16 01:26:58 -070033 "err = %d\n", ret);
34 force_sig(SIGKILL, current);
35 }
36
Jeff Dike6c738ff2007-10-16 01:27:06 -070037 __switch_mm(&current->mm->context.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
40void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
41{
Al Virobf56d572012-09-05 23:20:33 -040042 get_safe_registers(regs->regs.gp, regs->regs.fp);
Jeff Dike77bf4402007-10-16 01:26:58 -070043 PT_REGS_IP(regs) = eip;
44 PT_REGS_SP(regs) = esp;
Al Viro42459792012-09-03 03:24:18 -040045 current->ptrace &= ~PT_DTRACE;
46#ifdef SUBARCH_EXECVE1
47 SUBARCH_EXECVE1(regs->regs);
48#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
Al Viro73395a02011-08-18 20:14:10 +010050EXPORT_SYMBOL(start_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Richard Weinbergercb1dcc02010-09-22 13:05:07 -070052long um_execve(const char *file, const char __user *const __user *argv, const char __user *const __user *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 long err;
55
Al Viro42459792012-09-03 03:24:18 -040056 err = do_execve(file, argv, env, &current->thread.regs);
Jeff Dikeba180fd2007-10-16 01:27:00 -070057 if (!err)
Jeff Dikefab95c52007-10-16 01:27:05 -070058 UML_LONGJMP(current->thread.exec_buf, 1);
Jeff Dikeba180fd2007-10-16 01:27:00 -070059 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Richard Weinbergercb1dcc02010-09-22 13:05:07 -070062long sys_execve(const char __user *file, const char __user *const __user *argv,
63 const char __user *const __user *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 long error;
66 char *filename;
67
Al Viro4d338e12006-03-31 02:30:15 -080068 filename = getname(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 error = PTR_ERR(filename);
70 if (IS_ERR(filename)) goto out;
Al Viro42459792012-09-03 03:24:18 -040071 error = do_execve(filename, argv, env, &current->thread.regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 putname(filename);
73 out:
Jeff Dikeba180fd2007-10-16 01:27:00 -070074 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}