0
|
1 #include "types.h"
|
|
2 #include "arm.h"
|
|
3 #include "defs.h"
|
|
4 #include "param.h"
|
|
5 #include "memlayout.h"
|
|
6 #include "mmu.h"
|
|
7 #include "proc.h"
|
|
8
|
|
9 int sys_fork(void)
|
|
10 {
|
|
11 return fork();
|
|
12 }
|
|
13
|
|
14 int sys_exit(void)
|
|
15 {
|
|
16 exit();
|
|
17 return 0; // not reached
|
|
18 }
|
|
19
|
|
20 int sys_wait(void)
|
|
21 {
|
|
22 return wait();
|
|
23 }
|
|
24
|
|
25 int sys_kill(void)
|
|
26 {
|
|
27 int pid;
|
|
28
|
|
29 if(argint(0, &pid) < 0) {
|
|
30 return -1;
|
|
31 }
|
|
32
|
|
33 return kill(pid);
|
|
34 }
|
|
35
|
|
36 int sys_getpid(void)
|
|
37 {
|
|
38 return proc->pid;
|
|
39 }
|
|
40
|
|
41 int sys_sbrk(void)
|
|
42 {
|
|
43 int addr;
|
|
44 int n;
|
|
45
|
|
46 if(argint(0, &n) < 0) {
|
|
47 return -1;
|
|
48 }
|
|
49
|
|
50 addr = proc->sz;
|
|
51
|
|
52 if(growproc(n) < 0) {
|
|
53 return -1;
|
|
54 }
|
|
55
|
|
56 return addr;
|
|
57 }
|
|
58
|
|
59 int sys_sleep(void)
|
|
60 {
|
|
61 int n;
|
|
62 uint ticks0;
|
|
63
|
|
64 if(argint(0, &n) < 0) {
|
|
65 return -1;
|
|
66 }
|
|
67
|
|
68 acquire(&tickslock);
|
|
69
|
|
70 ticks0 = ticks;
|
|
71
|
|
72 while(ticks - ticks0 < n){
|
|
73 if(proc->killed){
|
|
74 release(&tickslock);
|
|
75 return -1;
|
|
76 }
|
|
77
|
|
78 sleep(&ticks, &tickslock);
|
|
79 }
|
|
80
|
|
81 release(&tickslock);
|
|
82 return 0;
|
|
83 }
|
|
84
|
|
85 // return how many clock tick interrupts have occurred
|
|
86 // since start.
|
|
87 int sys_uptime(void)
|
|
88 {
|
|
89 uint xticks;
|
|
90
|
|
91 acquire(&tickslock);
|
|
92 xticks = ticks;
|
|
93 release(&tickslock);
|
|
94
|
|
95 return xticks;
|
|
96 }
|