syscall lab need to finish
This commit is contained in:
@@ -7,6 +7,11 @@
|
||||
#include "syscall.h"
|
||||
#include "defs.h"
|
||||
|
||||
// 保留系统调用别名
|
||||
char* syscalls_name[24] = {"", "fork", "exit", "wait", "pipe", "read", "kill", "exec",
|
||||
"fstat", "chdir", "dup", "getpid", "sbrk", "sleep", "uptime",
|
||||
"open", "write", "mknod", "unlink", "link", "mkdir", "close", "trace"};
|
||||
|
||||
// Fetch the uint64 at addr from the current process.
|
||||
int
|
||||
fetchaddr(uint64 addr, uint64 *ip)
|
||||
@@ -101,6 +106,7 @@ extern uint64 sys_unlink(void);
|
||||
extern uint64 sys_link(void);
|
||||
extern uint64 sys_mkdir(void);
|
||||
extern uint64 sys_close(void);
|
||||
extern uint64 sys_trace(void);
|
||||
|
||||
// An array mapping syscall numbers from syscall.h
|
||||
// to the function that handles the system call.
|
||||
@@ -126,6 +132,7 @@ static uint64 (*syscalls[])(void) = {
|
||||
[SYS_link] sys_link,
|
||||
[SYS_mkdir] sys_mkdir,
|
||||
[SYS_close] sys_close,
|
||||
[SYS_trace] sys_trace,
|
||||
};
|
||||
|
||||
void
|
||||
@@ -139,6 +146,9 @@ syscall(void)
|
||||
// Use num to lookup the system call function for num, call it,
|
||||
// and store its return value in p->trapframe->a0
|
||||
p->trapframe->a0 = syscalls[num]();
|
||||
if (p->tracemask & (1 << num)) {
|
||||
printf("%d: syscall %s -> %d\n",p->pid, syscalls_name[num], p->trapframe->a0);
|
||||
}
|
||||
} else {
|
||||
printf("%d %s: unknown sys call %d\n",
|
||||
p->pid, p->name, num);
|
||||
|
||||
Reference in New Issue
Block a user