1 /*
2  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3  * Licensed under the GPL
4  */
5 
6 #include "linux/init.h"
7 #include "linux/sched.h"
8 #include "as-layout.h"
9 #include "kern.h"
10 #include "os.h"
11 #include "skas.h"
12 
new_mm(unsigned long stack)13 int new_mm(unsigned long stack)
14 {
15 	int fd, err;
16 
17 	fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
18 	if (fd < 0)
19 		return fd;
20 
21 	if (skas_needs_stub) {
22 		err = map_stub_pages(fd, STUB_CODE, STUB_DATA, stack);
23 		if (err) {
24 			os_close_file(fd);
25 			return err;
26 		}
27 	}
28 
29 	return fd;
30 }
31 
32 extern void start_kernel(void);
33 
start_kernel_proc(void * unused)34 static int __init start_kernel_proc(void *unused)
35 {
36 	int pid;
37 
38 	block_signals();
39 	pid = os_getpid();
40 
41 	cpu_tasks[0].pid = pid;
42 	cpu_tasks[0].task = current;
43 #ifdef CONFIG_SMP
44 	cpu_online_map = cpumask_of_cpu(0);
45 #endif
46 	start_kernel();
47 	return 0;
48 }
49 
50 extern int userspace_pid[];
51 
52 extern char cpu0_irqstack[];
53 
start_uml(void)54 int __init start_uml(void)
55 {
56 	stack_protections((unsigned long) &cpu0_irqstack);
57 	set_sigstack(cpu0_irqstack, THREAD_SIZE);
58 	if (proc_mm) {
59 		userspace_pid[0] = start_userspace(0);
60 		if (userspace_pid[0] < 0) {
61 			printf("start_uml - start_userspace returned %d\n",
62 			       userspace_pid[0]);
63 			exit(1);
64 		}
65 	}
66 
67 	init_new_thread_signals();
68 
69 	init_task.thread.request.u.thread.proc = start_kernel_proc;
70 	init_task.thread.request.u.thread.arg = NULL;
71 	return start_idle_thread(task_stack_page(&init_task),
72 				 &init_task.thread.switch_buf);
73 }
74 
current_stub_stack(void)75 unsigned long current_stub_stack(void)
76 {
77 	if (current->mm == NULL)
78 		return 0;
79 
80 	return current->mm->context.id.stack;
81 }
82