-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyscall.cpp
More file actions
56 lines (47 loc) · 1.22 KB
/
Copy pathsyscall.cpp
File metadata and controls
56 lines (47 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module;
#include <algorithm>
#include <cstdint>
module syscall;
import debug;
import scheduler;
import kmm;
import vmm;
namespace syscall {
uint64_t handler(uint64_t snum, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6) {
dbg::printf("syscall {} with parameters {} {} {} {} {} {}\n", snum, arg1, arg2, arg3, arg4, arg5, arg6);
uint64_t ret = -1;
switch (static_cast<Syscall>(snum)) {
case SYS_WRITE:
{
char *out = (char *)kmm::kmalloc(arg3+1);
if (!out) goto write_done;
if (!vmm::copyFromUser(out, (void*)arg2, arg3)) goto write_done;
out[arg3] = 0;
dbg::printf("[USER] ");
dbg::printf(out);
dbg::putchar('\n');
ret = arg3;
write_done:
kmm::kfree(out);
}
break;
case SYS_SCHED_YIELD:
{
dbg::printf("yield\n");
sched::schedule();
ret = 0;
}
break;
case SYS_EXIT:
{
dbg::printf("exit called\n");
sched::suicide(arg1);
}
break;
default:
dbg::printf("unknown syscall number {}\n", snum);
break;
}
return ret;
}
}