Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
0004  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
0005  */
0006 
0007 #include <linux/mm.h>
0008 #include <linux/sched/signal.h>
0009 #include <linux/slab.h>
0010 
0011 #include <asm/pgalloc.h>
0012 #include <asm/sections.h>
0013 #include <as-layout.h>
0014 #include <os.h>
0015 #include <skas.h>
0016 
0017 int init_new_context(struct task_struct *task, struct mm_struct *mm)
0018 {
0019     struct mm_context *from_mm = NULL;
0020     struct mm_context *to_mm = &mm->context;
0021     unsigned long stack = 0;
0022     int ret = -ENOMEM;
0023 
0024     stack = get_zeroed_page(GFP_KERNEL);
0025     if (stack == 0)
0026         goto out;
0027 
0028     to_mm->id.stack = stack;
0029     if (current->mm != NULL && current->mm != &init_mm)
0030         from_mm = &current->mm->context;
0031 
0032     block_signals_trace();
0033     if (from_mm)
0034         to_mm->id.u.pid = copy_context_skas0(stack,
0035                              from_mm->id.u.pid);
0036     else to_mm->id.u.pid = start_userspace(stack);
0037     unblock_signals_trace();
0038 
0039     if (to_mm->id.u.pid < 0) {
0040         ret = to_mm->id.u.pid;
0041         goto out_free;
0042     }
0043 
0044     ret = init_new_ldt(to_mm, from_mm);
0045     if (ret < 0) {
0046         printk(KERN_ERR "init_new_context_skas - init_ldt"
0047                " failed, errno = %d\n", ret);
0048         goto out_free;
0049     }
0050 
0051     return 0;
0052 
0053  out_free:
0054     if (to_mm->id.stack != 0)
0055         free_page(to_mm->id.stack);
0056  out:
0057     return ret;
0058 }
0059 
0060 void destroy_context(struct mm_struct *mm)
0061 {
0062     struct mm_context *mmu = &mm->context;
0063 
0064     /*
0065      * If init_new_context wasn't called, this will be
0066      * zero, resulting in a kill(0), which will result in the
0067      * whole UML suddenly dying.  Also, cover negative and
0068      * 1 cases, since they shouldn't happen either.
0069      */
0070     if (mmu->id.u.pid < 2) {
0071         printk(KERN_ERR "corrupt mm_context - pid = %d\n",
0072                mmu->id.u.pid);
0073         return;
0074     }
0075     os_kill_ptraced_process(mmu->id.u.pid, 1);
0076 
0077     free_page(mmu->id.stack);
0078     free_ldt(mmu);
0079 }