Trace syscall complete, kernel interface and userspace demo program
This commit is contained in:
parent
641ebb302a
commit
ca76d0772b
7 changed files with 33 additions and 1 deletions
1
Makefile
1
Makefile
|
@ -138,6 +138,7 @@ UPROGS=\
|
||||||
$U/_clear\
|
$U/_clear\
|
||||||
$U/_halt\
|
$U/_halt\
|
||||||
$U/_reset\
|
$U/_reset\
|
||||||
|
$U/_traced\
|
||||||
|
|
||||||
fs.img: mkfs/mkfs README.md $(UPROGS)
|
fs.img: mkfs/mkfs README.md $(UPROGS)
|
||||||
mkfs/mkfs fs.img README.md $(UPROGS)
|
mkfs/mkfs fs.img README.md $(UPROGS)
|
||||||
|
|
|
@ -127,6 +127,7 @@ exec(char *path, char **argv)
|
||||||
p->sz = sz;
|
p->sz = sz;
|
||||||
p->trapframe->epc = elf.entry; // initial program counter = main
|
p->trapframe->epc = elf.entry; // initial program counter = main
|
||||||
p->trapframe->sp = sp; // initial stack pointer
|
p->trapframe->sp = sp; // initial stack pointer
|
||||||
|
p->mask = 0;
|
||||||
proc_freepagetable(oldpagetable, oldsz);
|
proc_freepagetable(oldpagetable, oldsz);
|
||||||
|
|
||||||
return argc; // this ends up in a0, the first argument to main(argc, argv)
|
return argc; // this ends up in a0, the first argument to main(argc, argv)
|
||||||
|
|
|
@ -112,6 +112,7 @@ allocproc(void)
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
|
|
||||||
for(p = proc; p < &proc[NPROC]; p++) {
|
for(p = proc; p < &proc[NPROC]; p++) {
|
||||||
|
p->mask = 0;
|
||||||
acquire(&p->lock);
|
acquire(&p->lock);
|
||||||
if(p->state == UNUSED) {
|
if(p->state == UNUSED) {
|
||||||
goto found;
|
goto found;
|
||||||
|
@ -304,6 +305,7 @@ fork(void)
|
||||||
safestrcpy(np->name, p->name, sizeof(p->name));
|
safestrcpy(np->name, p->name, sizeof(p->name));
|
||||||
|
|
||||||
pid = np->pid;
|
pid = np->pid;
|
||||||
|
np->mask = 0;
|
||||||
|
|
||||||
release(&np->lock);
|
release(&np->lock);
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,10 @@ syscall(void)
|
||||||
|
|
||||||
num = p->trapframe->a7;
|
num = p->trapframe->a7;
|
||||||
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
|
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
|
||||||
|
if(p->mask & (1 << num)) {
|
||||||
|
printf("%d %s: Trace: syscall #%d\n", p->pid, p->name, num);
|
||||||
|
}
|
||||||
|
|
||||||
// Use num to lookup the system call function for num, call it,
|
// Use num to lookup the system call function for num, call it,
|
||||||
// and store its return value in p->trapframe->a0
|
// and store its return value in p->trapframe->a0
|
||||||
p->trapframe->a0 = syscalls[num]();
|
p->trapframe->a0 = syscalls[num]();
|
||||||
|
|
|
@ -93,7 +93,10 @@ sys_uptime(void)
|
||||||
u64
|
u64
|
||||||
sys_trace(void)
|
sys_trace(void)
|
||||||
{
|
{
|
||||||
/* TODO: Implement sys_trace */
|
int mask;
|
||||||
|
argint(0, &mask);
|
||||||
|
|
||||||
|
myproc()->mask = mask;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
user/traced.c
Normal file
18
user/traced.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#include "kernel/types.h"
|
||||||
|
#include "kernel/stat.h"
|
||||||
|
#include "user/user.h"
|
||||||
|
#include "kernel/syscall.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
trace(1 << SYS_open);
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if((fd = open(argv[1], 0)) < 0) {
|
||||||
|
fprintf(stderr, "Traced: cannot open %s\n", argv[1]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
#include "../kernel/types.h"
|
#include "../kernel/types.h"
|
||||||
|
|
||||||
|
#define stderr 2
|
||||||
|
#define stdout 1
|
||||||
|
|
||||||
struct stat;
|
struct stat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue