xref: /openbmc/linux/arch/um/kernel/skas/process.c (revision 643d1f7f)
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 "os.h"
10 #include "skas.h"
11 
12 int new_mm(unsigned long stack)
13 {
14 	int fd;
15 
16 	fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
17 	if (fd < 0)
18 		return fd;
19 
20 	if (skas_needs_stub)
21 		map_stub_pages(fd, STUB_CODE, STUB_DATA, stack);
22 
23 	return fd;
24 }
25 
26 extern void start_kernel(void);
27 
28 static int __init start_kernel_proc(void *unused)
29 {
30 	int pid;
31 
32 	block_signals();
33 	pid = os_getpid();
34 
35 	cpu_tasks[0].pid = pid;
36 	cpu_tasks[0].task = current;
37 #ifdef CONFIG_SMP
38 	cpu_online_map = cpumask_of_cpu(0);
39 #endif
40 	start_kernel();
41 	return 0;
42 }
43 
44 extern int userspace_pid[];
45 
46 extern char cpu0_irqstack[];
47 
48 int __init start_uml(void)
49 {
50 	stack_protections((unsigned long) &cpu0_irqstack);
51 	set_sigstack(cpu0_irqstack, THREAD_SIZE);
52 	if (proc_mm)
53 		userspace_pid[0] = start_userspace(0);
54 
55 	init_new_thread_signals();
56 
57 	init_task.thread.request.u.thread.proc = start_kernel_proc;
58 	init_task.thread.request.u.thread.arg = NULL;
59 	return start_idle_thread(task_stack_page(&init_task),
60 				 &init_task.thread.switch_buf);
61 }
62 
63 unsigned long current_stub_stack(void)
64 {
65 	if (current->mm == NULL)
66 		return 0;
67 
68 	return current->mm->context.id.stack;
69 }
70