2006-09-06 18:19:11 +00:00
|
|
|
#include "types.h"
|
2009-05-31 00:31:20 +00:00
|
|
|
#include "x86.h"
|
2007-08-27 23:26:33 +00:00
|
|
|
#include "defs.h"
|
2006-09-06 18:19:11 +00:00
|
|
|
#include "param.h"
|
2011-07-29 11:31:27 +00:00
|
|
|
#include "memlayout.h"
|
2006-09-06 18:19:11 +00:00
|
|
|
#include "mmu.h"
|
|
|
|
#include "proc.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_fork(void)
|
|
|
|
{
|
2009-05-31 00:38:51 +00:00
|
|
|
return fork();
|
2006-09-06 18:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_exit(void)
|
|
|
|
{
|
2007-08-28 19:14:43 +00:00
|
|
|
exit();
|
2006-09-06 18:19:11 +00:00
|
|
|
return 0; // not reached
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_wait(void)
|
|
|
|
{
|
2007-08-28 19:14:43 +00:00
|
|
|
return wait();
|
2006-09-06 18:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_kill(void)
|
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
|
2006-09-07 14:13:26 +00:00
|
|
|
if(argint(0, &pid) < 0)
|
2006-09-06 18:19:11 +00:00
|
|
|
return -1;
|
2007-08-28 19:14:43 +00:00
|
|
|
return kill(pid);
|
2006-09-06 18:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_getpid(void)
|
|
|
|
{
|
2009-08-31 06:02:08 +00:00
|
|
|
return proc->pid;
|
2006-09-06 18:19:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
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;
|
2009-08-31 06:02:08 +00:00
|
|
|
addr = proc->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
|
|
|
|
|
|
|
int
|
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;
|
2007-08-27 13:34:35 +00:00
|
|
|
|
|
|
|
if(argint(0, &n) < 0)
|
|
|
|
return -1;
|
|
|
|
acquire(&tickslock);
|
|
|
|
ticks0 = ticks;
|
|
|
|
while(ticks - ticks0 < n){
|
2009-08-31 06:02:08 +00:00
|
|
|
if(proc->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
|
|
|
|
|
|
|
// return how many clock tick interrupts have occurred
|
2011-08-16 00:11:13 +00:00
|
|
|
// since start.
|
2010-08-11 18:34:45 +00:00
|
|
|
int
|
|
|
|
sys_uptime(void)
|
|
|
|
{
|
|
|
|
uint xticks;
|
|
|
|
|
|
|
|
acquire(&tickslock);
|
|
|
|
xticks = ticks;
|
|
|
|
release(&tickslock);
|
|
|
|
return xticks;
|
|
|
|
}
|