blob: 9ce1c49421f88a7cf40cb6bcac3719add73b6e39 [file] [log] [blame]
Jeff Dike995473a2006-09-27 01:50:40 -07001/*
Jeff Dikeba180fd2007-10-16 01:27:00 -07002 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Jeff Dike995473a2006-09-27 01:50:40 -07003 * Licensed under the GPL
4 */
5
Jeff Dike995473a2006-09-27 01:50:40 -07006#include "linux/init.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -07007#include "linux/sched.h"
Jeff Dike4ff83ce2007-05-06 14:51:08 -07008#include "as-layout.h"
Jeff Dike995473a2006-09-27 01:50:40 -07009#include "os.h"
Jeff Dikeba180fd2007-10-16 01:27:00 -070010#include "skas.h"
Jeff Dike995473a2006-09-27 01:50:40 -070011
Jeff Dike995473a2006-09-27 01:50:40 -070012int new_mm(unsigned long stack)
13{
14 int fd;
15
16 fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
Jeff Dikeba180fd2007-10-16 01:27:00 -070017 if (fd < 0)
Jeff Dike77bf4402007-10-16 01:26:58 -070018 return fd;
Jeff Dike995473a2006-09-27 01:50:40 -070019
Jeff Dikeba180fd2007-10-16 01:27:00 -070020 if (skas_needs_stub)
Jeff Dike995473a2006-09-27 01:50:40 -070021 map_stub_pages(fd, CONFIG_STUB_CODE, CONFIG_STUB_DATA, stack);
22
Jeff Dike77bf4402007-10-16 01:26:58 -070023 return fd;
Jeff Dike995473a2006-09-27 01:50:40 -070024}
25
26extern void start_kernel(void);
27
Jeff Dike97a1fcb2007-07-23 18:43:48 -070028static int __init start_kernel_proc(void *unused)
Jeff Dike995473a2006-09-27 01:50:40 -070029{
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();
Jeff Dike77bf4402007-10-16 01:26:58 -070041 return 0;
Jeff Dike995473a2006-09-27 01:50:40 -070042}
43
44extern int userspace_pid[];
45
Jeff Dikec14b8492007-05-10 22:22:34 -070046extern char cpu0_irqstack[];
47
Jeff Dike77bf4402007-10-16 01:26:58 -070048int __init start_uml(void)
Jeff Dike995473a2006-09-27 01:50:40 -070049{
Jeff Dikec14b8492007-05-10 22:22:34 -070050 stack_protections((unsigned long) &cpu0_irqstack);
51 set_sigstack(cpu0_irqstack, THREAD_SIZE);
Jeff Dikeba180fd2007-10-16 01:27:00 -070052 if (proc_mm)
Jeff Dike995473a2006-09-27 01:50:40 -070053 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;
Jeff Dike77bf4402007-10-16 01:26:58 -070059 return start_idle_thread(task_stack_page(&init_task),
60 &init_task.thread.switch_buf);
Jeff Dike995473a2006-09-27 01:50:40 -070061}
62
63unsigned long current_stub_stack(void)
64{
Jeff Dikeba180fd2007-10-16 01:27:00 -070065 if (current->mm == NULL)
Jeff Dike77bf4402007-10-16 01:26:58 -070066 return 0;
Jeff Dike995473a2006-09-27 01:50:40 -070067
Jeff Dike77bf4402007-10-16 01:26:58 -070068 return current->mm->context.skas.id.stack;
Jeff Dike995473a2006-09-27 01:50:40 -070069}