process.c 1.5 KB
Newer Older
J
Jeff Dike 已提交
1
/*
J
Jeff Dike 已提交
2
 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
J
Jeff Dike 已提交
3 4 5 6
 * Licensed under the GPL
 */

#include "linux/init.h"
J
Jeff Dike 已提交
7
#include "linux/sched.h"
J
Jeff Dike 已提交
8
#include "as-layout.h"
9
#include "kern.h"
J
Jeff Dike 已提交
10
#include "os.h"
J
Jeff Dike 已提交
11
#include "skas.h"
J
Jeff Dike 已提交
12 13 14

int new_mm(unsigned long stack)
{
15
	int fd, err;
J
Jeff Dike 已提交
16 17

	fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
J
Jeff Dike 已提交
18
	if (fd < 0)
19
		return fd;
J
Jeff Dike 已提交
20

21 22 23 24 25 26 27
	if (skas_needs_stub) {
		err = map_stub_pages(fd, STUB_CODE, STUB_DATA, stack);
		if (err) {
			os_close_file(fd);
			return err;
		}
	}
J
Jeff Dike 已提交
28

29
	return fd;
J
Jeff Dike 已提交
30 31 32 33
}

extern void start_kernel(void);

J
Jeff Dike 已提交
34
static int __init start_kernel_proc(void *unused)
J
Jeff Dike 已提交
35 36 37 38 39 40 41 42 43 44 45 46
{
	int pid;

	block_signals();
	pid = os_getpid();

	cpu_tasks[0].pid = pid;
	cpu_tasks[0].task = current;
#ifdef CONFIG_SMP
	cpu_online_map = cpumask_of_cpu(0);
#endif
	start_kernel();
47
	return 0;
J
Jeff Dike 已提交
48 49 50 51
}

extern int userspace_pid[];

J
Jeff Dike 已提交
52 53
extern char cpu0_irqstack[];

54
int __init start_uml(void)
J
Jeff Dike 已提交
55
{
J
Jeff Dike 已提交
56 57
	stack_protections((unsigned long) &cpu0_irqstack);
	set_sigstack(cpu0_irqstack, THREAD_SIZE);
58
	if (proc_mm) {
J
Jeff Dike 已提交
59
		userspace_pid[0] = start_userspace(0);
60 61 62 63 64 65
		if (userspace_pid[0] < 0) {
			printf("start_uml - start_userspace returned %d\n",
			       userspace_pid[0]);
			exit(1);
		}
	}
J
Jeff Dike 已提交
66 67 68 69 70

	init_new_thread_signals();

	init_task.thread.request.u.thread.proc = start_kernel_proc;
	init_task.thread.request.u.thread.arg = NULL;
71 72
	return start_idle_thread(task_stack_page(&init_task),
				 &init_task.thread.switch_buf);
J
Jeff Dike 已提交
73 74 75 76
}

unsigned long current_stub_stack(void)
{
J
Jeff Dike 已提交
77
	if (current->mm == NULL)
78
		return 0;
J
Jeff Dike 已提交
79

80
	return current->mm->context.id.stack;
J
Jeff Dike 已提交
81
}