syscall lab need to finish

This commit is contained in:
2025-03-25 01:13:50 +08:00
parent e33ff43dd6
commit d92eea9e49
12 changed files with 193 additions and 87 deletions

View File

@@ -310,6 +310,8 @@ fork(void)
safestrcpy(np->name, p->name, sizeof(p->name));
// 复制掩码
np->tracemask = p->tracemask;
pid = np->pid;
release(&np->lock);

View File

@@ -91,6 +91,7 @@ struct proc {
int killed; // If non-zero, have been killed
int xstate; // Exit status to be returned to parent's wait
int pid; // Process ID
int tracemask; // Trace Mask
// wait_lock must be held when using this:
struct proc *parent; // Parent process

View File

@@ -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);

View File

@@ -20,3 +20,4 @@
#define SYS_link 19
#define SYS_mkdir 20
#define SYS_close 21
#define SYS_trace 22

View File

@@ -91,3 +91,13 @@ sys_uptime(void)
release(&tickslock);
return xticks;
}
uint64
sys_trace(void)
{
int n;
argint(0, &n);
if(n<0) return -1;
myproc()->tracemask = n;
return 0;
}