MIT 6.S081 Lab: system calls

Result

MIT 6.S081 Lab: system calls_第1张图片

1、System call tracing

In this assignment you will add a system call tracing feature that may help you when debugging later labs. You’ll create a new trace system call that will control tracing. It should take one argument, an integer “mask”, whose bits specify which system calls to trace. For example, to trace the fork system call, a program calls trace(1 << SYS_fork), where SYS_fork is a syscall number from kernel/syscall.h. You have to modify the xv6 kernel to print out a line when each system call is about to return, if the system call’s number is set in the mask. The line should contain the process id, the name of the system call and the return value; you don’t need to print the system call arguments. The trace system call should enable tracing for the process that calls it and any children that it subsequently forks, but should not affect other processes.

  • user/user.h
    MIT 6.S081 Lab: system calls_第2张图片

  • user/usys.pl
    MIT 6.S081 Lab: system calls_第3张图片

  • kernel/syscall.h
    MIT 6.S081 Lab: system calls_第4张图片

  • kernel/sysproc.c
    MIT 6.S081 Lab: system calls_第5张图片

  • kernel/proc.h
    MIT 6.S081 Lab: system calls_第6张图片

  • kernel/proc.c
    MIT 6.S081 Lab: system calls_第7张图片

  • kernel/syscall.cMIT 6.S081 Lab: system calls_第8张图片

  • kernel/syscall.c
    MIT 6.S081 Lab: system calls_第9张图片

2、Sysinfo

In this assignment you will add a system call, sysinfo, that collects information about the running system. The system call takes one argument: a pointer to a struct sysinfo (see kernel/sysinfo.h). The kernel should fill out the fields of this struct: the freemem field should be set to the number of bytes of free memory, and the nproc field should be set to the number of processes whose state is not UNUSED. We provide a test program sysinfotest; you pass this assignment if it prints “sysinfotest: OK”.

  • user/user.h
    MIT 6.S081 Lab: system calls_第10张图片

  • kernel/syscall.h
    MIT 6.S081 Lab: system calls_第11张图片

  • user/usys.pl
    MIT 6.S081 Lab: system calls_第12张图片

  • kernel/defs.h
    MIT 6.S081 Lab: system calls_第13张图片

  • To collect the amount of free memory, add a function to kernel/kalloc.c
    MIT 6.S081 Lab: system calls_第14张图片

  • To collect the number of processes, add a function to kernel/proc.c

MIT 6.S081 Lab: system calls_第15张图片

  • kernel/sysproc.c, sysinfo needs to copy a struct sysinfo back to user space

MIT 6.S081 Lab: system calls_第16张图片

你可能感兴趣的:(MIT 6.S081 Lab: system calls)