1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
4 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
8 #include <linux/sched/signal.h>
9 #include <linux/slab.h>
11 #include <asm/pgalloc.h>
12 #include <asm/sections.h>
13 #include <as-layout.h>
17 int init_new_context(struct task_struct *task, struct mm_struct *mm)
19 struct mm_context *from_mm = NULL;
20 struct mm_context *to_mm = &mm->context;
21 unsigned long stack = 0;
24 stack = get_zeroed_page(GFP_KERNEL);
28 to_mm->id.stack = stack;
29 if (current->mm != NULL && current->mm != &init_mm)
30 from_mm = ¤t->mm->context;
32 block_signals_trace();
34 to_mm->id.u.pid = copy_context_skas0(stack,
36 else to_mm->id.u.pid = start_userspace(stack);
37 unblock_signals_trace();
39 if (to_mm->id.u.pid < 0) {
40 ret = to_mm->id.u.pid;
44 ret = init_new_ldt(to_mm, from_mm);
46 printk(KERN_ERR "init_new_context_skas - init_ldt"
47 " failed, errno = %d\n", ret);
54 if (to_mm->id.stack != 0)
55 free_page(to_mm->id.stack);
60 void destroy_context(struct mm_struct *mm)
62 struct mm_context *mmu = &mm->context;
65 * If init_new_context wasn't called, this will be
66 * zero, resulting in a kill(0), which will result in the
67 * whole UML suddenly dying. Also, cover negative and
68 * 1 cases, since they shouldn't happen either.
70 if (mmu->id.u.pid < 2) {
71 printk(KERN_ERR "corrupt mm_context - pid = %d\n",
75 os_kill_ptraced_process(mmu->id.u.pid, 1);
77 free_page(mmu->id.stack);