2006-09-06 18:19:11 +00:00
|
|
|
#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"
|
2014-09-12 21:18:57 +00:00
|
|
|
#include "date.h"
|
2006-09-06 18:19:11 +00:00
|
|
|
#include "param.h"
|
2011-07-29 11:31:27 +00:00
|
|
|
#include "memlayout.h"
|
2019-07-02 13:14:47 +00:00
|
|
|
#include "spinlock.h"
|
2006-09-06 18:19:11 +00:00
|
|
|
#include "proc.h"
|
|
|
|
|
2019-07-01 21:01:50 +00:00
|
|
|
uint64
|
2019-05-31 13:45:59 +00:00
|
|
|
sys_exit(void)
|
2006-09-06 18:19:11 +00:00
|
|
|
{
|
2019-09-10 16:30:10 +00:00
|
|
|
int n;
|
|
|
|
if(argint(0, &n) < 0)
|
|
|
|
return -1;
|
|
|
|
exit(n);
|
2019-05-31 13:45:59 +00:00
|
|
|
return 0; // not reached
|
2006-09-06 18:19:11 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 21:01:50 +00:00
|
|
|
uint64
|
2019-05-31 13:45:59 +00:00
|
|
|
sys_getpid(void)
|
2006-09-06 18:19:11 +00:00
|
|
|
{
|
2019-05-31 13:45:59 +00:00
|
|
|
return myproc()->pid;
|
|
|
|
}
|
|
|
|
|
2019-07-01 21:01:50 +00:00
|
|
|
uint64
|
2019-05-31 13:45:59 +00:00
|
|
|
sys_fork(void)
|
|
|
|
{
|
|
|
|
return fork();
|
2006-09-06 18:19:11 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 21:01:50 +00:00
|
|
|
uint64
|
2006-09-06 18:19:11 +00:00
|
|
|
sys_wait(void)
|
|
|
|
{
|
2019-09-10 16:30:10 +00:00
|
|
|
uint64 p;
|
|
|
|
if(argaddr(0, &p) < 0)
|
|
|
|
return -1;
|
|
|
|
return wait(p);
|
2006-09-06 18:19:11 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 21:01:50 +00:00
|
|
|
uint64
|
2006-09-06 18:19:11 +00:00
|
|
|
sys_sbrk(void)
|
|
|
|
{
|
2006-09-07 14:13:26 +00:00
|
|
|
int addr;
|
2006-09-06 18:19:11 +00:00
|
|
|
int n;
|
|
|
|
|
2006-09-07 14:13:26 +00:00
|
|
|
if(argint(0, &n) < 0)
|
2006-09-06 18:19:11 +00:00
|
|
|
return -1;
|
2017-01-31 22:47:16 +00:00
|
|
|
addr = myproc()->sz;
|
2009-05-31 00:31:20 +00:00
|
|
|
if(growproc(n) < 0)
|
2006-09-06 18:19:11 +00:00
|
|
|
return -1;
|
|
|
|
return addr;
|
|
|
|
}
|
2007-08-24 20:04:53 +00:00
|
|
|
|
2019-07-01 21:01:50 +00:00
|
|
|
uint64
|
2007-08-27 13:34:35 +00:00
|
|
|
sys_sleep(void)
|
2007-08-24 20:04:53 +00:00
|
|
|
{
|
2010-08-11 18:34:45 +00:00
|
|
|
int n;
|
|
|
|
uint ticks0;
|
2016-08-25 13:13:00 +00:00
|
|
|
|
2007-08-27 13:34:35 +00:00
|
|
|
if(argint(0, &n) < 0)
|
|
|
|
return -1;
|
|
|
|
acquire(&tickslock);
|
|
|
|
ticks0 = ticks;
|
|
|
|
while(ticks - ticks0 < n){
|
2017-01-31 22:47:16 +00:00
|
|
|
if(myproc()->killed){
|
2007-08-27 13:34:35 +00:00
|
|
|
release(&tickslock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sleep(&ticks, &tickslock);
|
|
|
|
}
|
|
|
|
release(&tickslock);
|
2007-08-24 20:04:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-08-11 18:34:45 +00:00
|
|
|
|
2019-07-01 21:01:50 +00:00
|
|
|
uint64
|
2019-06-04 15:31:50 +00:00
|
|
|
sys_kill(void)
|
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
if(argint(0, &pid) < 0)
|
|
|
|
return -1;
|
|
|
|
return kill(pid);
|
|
|
|
}
|
|
|
|
|
2010-08-11 18:34:45 +00:00
|
|
|
// return how many clock tick interrupts have occurred
|
2011-08-16 00:11:13 +00:00
|
|
|
// since start.
|
2019-07-01 21:01:50 +00:00
|
|
|
uint64
|
2010-08-11 18:34:45 +00:00
|
|
|
sys_uptime(void)
|
|
|
|
{
|
|
|
|
uint xticks;
|
2016-08-25 13:13:00 +00:00
|
|
|
|
2010-08-11 18:34:45 +00:00
|
|
|
acquire(&tickslock);
|
|
|
|
xticks = ticks;
|
|
|
|
release(&tickslock);
|
|
|
|
return xticks;
|
|
|
|
}
|