LCOV - code coverage report
Current view: top level - arch/um/kernel/skas - mmu.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 30 0.0 %
Date: 2023-03-27 20:00:47 Functions: 0 2 0.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : /*
       3             :  * Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
       4             :  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
       5             :  */
       6             : 
       7             : #include <linux/mm.h>
       8             : #include <linux/sched/signal.h>
       9             : #include <linux/slab.h>
      10             : 
      11             : #include <asm/pgalloc.h>
      12             : #include <asm/sections.h>
      13             : #include <as-layout.h>
      14             : #include <os.h>
      15             : #include <skas.h>
      16             : 
      17           0 : int init_new_context(struct task_struct *task, struct mm_struct *mm)
      18             : {
      19           0 :         struct mm_context *from_mm = NULL;
      20           0 :         struct mm_context *to_mm = &mm->context;
      21           0 :         unsigned long stack = 0;
      22           0 :         int ret = -ENOMEM;
      23             : 
      24           0 :         stack = get_zeroed_page(GFP_KERNEL);
      25           0 :         if (stack == 0)
      26             :                 goto out;
      27             : 
      28           0 :         to_mm->id.stack = stack;
      29           0 :         if (current->mm != NULL && current->mm != &init_mm)
      30           0 :                 from_mm = &current->mm->context;
      31             : 
      32           0 :         block_signals_trace();
      33           0 :         if (from_mm)
      34           0 :                 to_mm->id.u.pid = copy_context_skas0(stack,
      35             :                                                      from_mm->id.u.pid);
      36           0 :         else to_mm->id.u.pid = start_userspace(stack);
      37           0 :         unblock_signals_trace();
      38             : 
      39           0 :         if (to_mm->id.u.pid < 0) {
      40             :                 ret = to_mm->id.u.pid;
      41             :                 goto out_free;
      42             :         }
      43             : 
      44           0 :         ret = init_new_ldt(to_mm, from_mm);
      45           0 :         if (ret < 0) {
      46           0 :                 printk(KERN_ERR "init_new_context_skas - init_ldt"
      47             :                        " failed, errno = %d\n", ret);
      48           0 :                 goto out_free;
      49             :         }
      50             : 
      51             :         return 0;
      52             : 
      53             :  out_free:
      54           0 :         if (to_mm->id.stack != 0)
      55           0 :                 free_page(to_mm->id.stack);
      56             :  out:
      57             :         return ret;
      58             : }
      59             : 
      60           0 : void destroy_context(struct mm_struct *mm)
      61             : {
      62           0 :         struct mm_context *mmu = &mm->context;
      63             : 
      64             :         /*
      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.
      69             :          */
      70           0 :         if (mmu->id.u.pid < 2) {
      71           0 :                 printk(KERN_ERR "corrupt mm_context - pid = %d\n",
      72             :                        mmu->id.u.pid);
      73           0 :                 return;
      74             :         }
      75           0 :         os_kill_ptraced_process(mmu->id.u.pid, 1);
      76             : 
      77           0 :         free_page(mmu->id.stack);
      78           0 :         free_ldt(mmu);
      79             : }

Generated by: LCOV version 1.14