2006-09-06 18:19:11 +00:00
|
|
|
#include "types.h"
|
2007-08-27 23:26:33 +00:00
|
|
|
#include "defs.h"
|
2006-09-06 18:19:11 +00:00
|
|
|
#include "param.h"
|
|
|
|
#include "mmu.h"
|
|
|
|
#include "proc.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_fork(void)
|
|
|
|
{
|
|
|
|
struct proc *np;
|
|
|
|
|
2007-08-10 16:37:27 +00:00
|
|
|
if((np = copyproc(cp)) == 0)
|
2006-09-06 18:19:11 +00:00
|
|
|
return -1;
|
|
|
|
np->state = RUNNABLE;
|
|
|
|
return np->pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_exit(void)
|
|
|
|
{
|
|
|
|
proc_exit();
|
|
|
|
return 0; // not reached
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_wait(void)
|
|
|
|
{
|
|
|
|
return proc_wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
return proc_kill(pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sys_getpid(void)
|
|
|
|
{
|
2007-08-10 16:37:27 +00:00
|
|
|
return cp->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;
|
2006-09-07 14:13:26 +00:00
|
|
|
if((addr = growproc(n)) < 0)
|
2006-09-06 18:19:11 +00:00
|
|
|
return -1;
|
|
|
|
setupsegs(cp);
|
|
|
|
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
|
|
|
{
|
2007-08-27 13:34:35 +00:00
|
|
|
int n, ticks0;
|
|
|
|
|
|
|
|
if(argint(0, &n) < 0)
|
|
|
|
return -1;
|
|
|
|
acquire(&tickslock);
|
|
|
|
ticks0 = ticks;
|
|
|
|
while(ticks - ticks0 < n){
|
|
|
|
if(cp->killed){
|
|
|
|
release(&tickslock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
sleep(&ticks, &tickslock);
|
|
|
|
}
|
|
|
|
release(&tickslock);
|
2007-08-24 20:04:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|