Xv6 Lab system calls
Lab: system calls
From: https://pdos.csail.mit.edu/6.S081/2020/labs/syscall.html
【NOTE】Add a new system call
To add a new system call, say, named xxx
:
add a prototype for the system call to
user/user.h
1
int xxx(int)
add a stub to
user/usys.pl
1
entry("xxx");
add a syscall number to
kernel/syscall.h
1
add the new syscall into
kernel/syscall.c
1
2
3
4
5
6extern uint64 sys_xxx(void); // 1
static uint64 (*syscalls[])(void) = {
...
[SYS_xxx] sys_xxx, // 2
};add
sys_xxx
(a function takes void as argument and returns uint64) inkernel/sysproc.c
. This function do fetch arguments about the system call and return values.1
2
3
4
5uint64
sys_xxx(void)
{
// about arguments: the [xv6 book](https://pdos.csail.mit.edu/6.S081/2020/xv6/book-riscv-rev1.pdf) Sections 4.3 and 4.4 of Chapter 4
}implement the syscall somewhere in the kernel. (e.g. implement a
xxx
function , defines inkernel/defs.h
, to do hard work)
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.
Main implement
kernel/sysproc.c
:
1 | ... |
kernel/proc.h
:
1 | struct proc { |
kernel/syscall.c
:
1 | ... |
Detailed diff
1 | diff --git a/Makefile b/Makefile |
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”.
Main implement
kernel/sysproc.c
:
1 | uint64 |
kernel/sysinfo.c
:
1 |
|
kernel/proc.c
:
1 | // Get the number of processes whose state is not UNUSED. |
kernel/kalloc.c
:
1 | // Get the number of bytes of free memory |
Detailed diff
1 | diff --git a/Makefile b/Makefile |
EOF
By CDFMLR 2020-03-02
顶部图片来自于小歪API,系随机选取的图片,仅用于检测屏幕显示的机械、光电性能,与文章的任何内容及观点无关,也并不代表本人局部或全部同意、支持或者反对其中的任何内容及观点。如有侵权,联系删除。