MIT 6.S081 Lab: system calls

Result

在这里插入图片描述

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
    在这里插入图片描述

  • user/usys.pl
    在这里插入图片描述

  • kernel/syscall.h
    在这里插入图片描述

  • kernel/sysproc.c
    在这里插入图片描述

  • kernel/proc.h
    在这里插入图片描述

  • kernel/proc.c
    在这里插入图片描述

  • kernel/syscall.c在这里插入图片描述

  • kernel/syscall.c
    在这里插入图片描述

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
    在这里插入图片描述

  • kernel/syscall.h
    在这里插入图片描述

  • user/usys.pl
    在这里插入图片描述

  • kernel/defs.h
    在这里插入图片描述

  • To collect the amount of free memory, add a function to kernel/kalloc.c
    在这里插入图片描述

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

在这里插入图片描述

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

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41714373/article/details/109900212