MIT 6.828 Assignment:System Calls

系统调用


MIT 6.828 Operating System Engineering

System call tracing

在进行系统调用时,打印出系统调用的名字和返回值。提醒也很明显,就是修改syscall.c/syscall()函数,

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
char* syscall_name[22] =
{
[SYS_fork] "fork",
[SYS_exit] "exit",
[SYS_wait] "wait",
[SYS_pipe] "pipe",
[SYS_read] "read",
[SYS_kill] "kill",
[SYS_exec] "exec",
[SYS_fstat] "fstat",
[SYS_chdir] "chdir",
[SYS_dup] "dup",
[SYS_getpid] "getpid",
[SYS_sbrk] "sbrk",
[SYS_sleep] "sleep",
[SYS_uptime] "uptime",
[SYS_open] "open",
[SYS_write] "write",
[SYS_mknod] "mknod",
[SYS_unlink] "unlink",
[SYS_link] "link",
[SYS_mkdir] "mkdir",
[SYS_close] "close",
};


void
syscall(void)
{
int num;
struct proc *curproc = myproc();

num = curproc->tf->eax;
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
curproc->tf->eax = syscalls[num]();
cprintf("%s -> %d\n",syscall_name[num],curproc->tf->eax);
} else {
cprintf("%d %s: unknown sys call %d\n",
curproc->pid, curproc->name, num);
curproc->tf->eax = -1;
}
}

Date system call

第二个任务是添加新的系统调用,去获取当前时间并返回给用户程序。此时需要辅助函数cmostime() (在lapic.c中定义)来读取实时时钟。date.h包含struct rtcdate结构的定义,作为提供给cmostime()的指针参数

重新定义一个系统调用需要修改一下文件,另外还需要新建一个用户程序

1
2
3
4
5
syscall.c
syscall.h
user.c
usys.S
xxx.c

对于系统调用的流程还是不清楚,这个assignment也是跟着网上写的,看完第三章,再回过头整理