root/kernel/sysproc.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_exit
  2. sys_getpid
  3. sys_fork
  4. sys_wait
  5. sys_sbrk
  6. sys_pause
  7. sys_kill
  8. sys_uptime

   1 #include "types.h"
   2 #include "riscv.h"
   3 #include "defs.h"
   4 #include "param.h"
   5 #include "memlayout.h"
   6 #include "spinlock.h"
   7 #include "proc.h"
   8 #include "vm.h"
   9 
  10 uint64
  11 sys_exit(void)
  12 {
  13   int n;
  14   argint(0, &n);
  15   kexit(n);
  16   return 0;  // not reached
  17 }
  18 
  19 uint64
  20 sys_getpid(void)
  21 {
  22   return myproc()->pid;
  23 }
  24 
  25 uint64
  26 sys_fork(void)
  27 {
  28   return kfork();
  29 }
  30 
  31 uint64
  32 sys_wait(void)
  33 {
  34   uint64 p;
  35   argaddr(0, &p);
  36   return kwait(p);
  37 }
  38 
  39 uint64
  40 sys_sbrk(void)
  41 {
  42   uint64 addr;
  43   int t;
  44   int n;
  45 
  46   argint(0, &n);
  47   argint(1, &t);
  48   addr = myproc()->sz;
  49 
  50   if(t == SBRK_EAGER || n < 0) {
  51     if(growproc(n) < 0) {
  52       return -1;
  53     }
  54   } else {
  55     // Lazily allocate memory for this process: increase its memory
  56     // size but don't allocate memory. If the processes uses the
  57     // memory, vmfault() will allocate it.
  58     if(addr + n < addr)
  59       return -1;
  60     if(addr + n > TRAPFRAME)
  61       return -1;
  62     myproc()->sz += n;
  63   }
  64   return addr;
  65 }
  66 
  67 uint64
  68 sys_pause(void)
  69 {
  70   int n;
  71   uint ticks0;
  72 
  73   argint(0, &n);
  74   if(n < 0)
  75     n = 0;
  76   acquire(&tickslock);
  77   ticks0 = ticks;
  78   while(ticks - ticks0 < n){
  79     if(killed(myproc())){
  80       release(&tickslock);
  81       return -1;
  82     }
  83     sleep(&ticks, &tickslock);
  84   }
  85   release(&tickslock);
  86   return 0;
  87 }
  88 
  89 uint64
  90 sys_kill(void)
  91 {
  92   int pid;
  93 
  94   argint(0, &pid);
  95   return kkill(pid);
  96 }
  97 
  98 // return how many clock tick interrupts have occurred
  99 // since start.
 100 uint64
 101 sys_uptime(void)
 102 {
 103   uint xticks;
 104 
 105   acquire(&tickslock);
 106   xticks = ticks;
 107   release(&tickslock);
 108   return xticks;
 109 }

/* [<][>][^][v][top][bottom][index][help] */