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
 * Licensed under the GPL
 */

6 7 8 9 10 11
#include <linux/init.h>
#include <linux/sched.h>
#include <as-layout.h>
#include <kern.h>
#include <os.h>
#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
{
	int pid;

	block_signals();
	pid = os_getpid();

	cpu_tasks[0].pid = pid;
	cpu_tasks[0].task = current;
#ifdef CONFIG_SMP
44
	init_cpu_online(get_cpu_mask(0));
J
Jeff Dike 已提交
45 46
#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
}