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