// Create a new process, copying the parent. // Sets up child kernel stack to return as if from fork() system call. intfork(void) { ... // 父子进程复制跟踪掩码 np->trace_mask = p->trace_mask; ... }
chenz@Chenzc:~/lab$ sudo python3 grade-lab-syscall trace make: 'kernel/kernel' is up to date. == Test trace 32 grep == trace 32 grep: OK (3.3s) == Test trace all grep == trace all grep: OK (1.1s) == Test trace nothing == trace nothing: OK (2.0s) == Test trace children == trace children: OK (20.5s)
Sysinfo
这个lab也是一个功能性的系统调用。获取操作系统中的工作线程数量与空闲内存
需要依次添加修改:
kernel/kalloc.c获取空闲内存
1 2 3 4 5 6 7 8 9 10 11
uint64 kgetmem(void) { uint64 retV = 0; structrun* r; r = kmem.freelist; while (r != (void*)0) { retV += PGSIZE; r = r->next; } freemem = retV; return retV; }
kernel/proc.c获取工作线程数量
1 2 3 4 5 6 7 8 9 10
uint64 getunusedproc(void){ uint64 cnt = 0; structproc* p; for (p = proc; p < &proc[NPROC]; p ++) { if (p->state != UNUSED) { cnt++; } } return cnt; }
kernel/sysinfo.cecall函数
1 2 3 4 5 6 7 8
uint64 sys_info(void) { uint64 info; if (argaddr(0, &info) < 0) { return-1; } int iaddr = ssinfo(info); return iaddr; }
kernel/info.c组装&拷贝返回
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
intssinfo(uint64 addr) { structsysinfos; structproc* p = myproc();