kernel/sysproc.c
109 lines
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"910uint6411sys_exit(void)12{13 int n;14 argint(0, &n);15 kexit(n);16 return 0; // not reached17}1819uint6420sys_getpid(void)21{22 return myproc()->pid;23}2425uint6426sys_fork(void)27{28 return kfork();29}3031uint6432sys_wait(void)33{34 uint64 p;35 argaddr(0, &p);36 return kwait(p);37}3839uint6440sys_sbrk(void)41{42 uint64 addr;43 int t;44 int n;4546 argint(0, &n);47 argint(1, &t);48 addr = myproc()->sz;4950 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 memory56 // size but don't allocate memory. If the processes uses the57 // 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}6667uint6468sys_pause(void)69{70 int n;71 uint ticks0;7273 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}8889uint6490sys_kill(void)91{92 int pid;9394 argint(0, &pid);95 return kkill(pid);96}9798// return how many clock tick interrupts have occurred99// since start.100uint64101sys_uptime(void)102{103 uint xticks;104105 acquire(&tickslock);106 xticks = ticks;107 release(&tickslock);108 return xticks;109}110