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