xv6-65oo2/kernel/sysproc.c

92 lines
1.1 KiB
C
Raw Normal View History

#include "types.h"
2019-05-31 13:45:59 +00:00
#include "riscv.h"
2007-08-27 23:26:33 +00:00
#include "defs.h"
#include "date.h"
#include "param.h"
#include "memlayout.h"
#include "spinlock.h"
#include "proc.h"
uint64
2019-05-31 13:45:59 +00:00
sys_exit(void)
{
2019-05-31 13:45:59 +00:00
exit();
return 0; // not reached
}
uint64
2019-05-31 13:45:59 +00:00
sys_getpid(void)
{
2019-05-31 13:45:59 +00:00
return myproc()->pid;
}
uint64
2019-05-31 13:45:59 +00:00
sys_fork(void)
{
return fork();
}
uint64
sys_wait(void)
{
return wait();
}
uint64
sys_sbrk(void)
{
2006-09-07 14:13:26 +00:00
int addr;
int n;
2006-09-07 14:13:26 +00:00
if(argint(0, &n) < 0)
return -1;
addr = myproc()->sz;
2009-05-31 00:31:20 +00:00
if(growproc(n) < 0)
return -1;
return addr;
}
uint64
2007-08-27 13:34:35 +00:00
sys_sleep(void)
{
int n;
uint ticks0;
2007-08-27 13:34:35 +00:00
if(argint(0, &n) < 0)
return -1;
acquire(&tickslock);
ticks0 = ticks;
while(ticks - ticks0 < n){
if(myproc()->killed){
2007-08-27 13:34:35 +00:00
release(&tickslock);
return -1;
}
sleep(&ticks, &tickslock);
}
release(&tickslock);
return 0;
}
uint64
2019-06-04 15:31:50 +00:00
sys_kill(void)
{
int pid;
if(argint(0, &pid) < 0)
return -1;
return kill(pid);
}
// return how many clock tick interrupts have occurred
2011-08-16 00:11:13 +00:00
// since start.
uint64
sys_uptime(void)
{
uint xticks;
acquire(&tickslock);
xticks = ticks;
release(&tickslock);
return xticks;
}