This lab shows us how to create a system call and use definitions in kernel code.
How to activate a system call in xv6?
user/user.h
, a system call number in kernel/syscall.h
and a stub to user/usys.pl
(which generates user-level syscall instructions).ecall
will jump to the syscall()
function in kernel/syscall.c
with the calling number saved in a7
register.syscall()
use the number as an index of a function pointer array to get the address of its kernel code and call it.sys_fork()
, in kernel/sysproc.c
and other files.Add an mask integer in process structure. When the actual system call returns to syscall()
, test the process mask with the system call number and print a line.
How to pass the mask to child processes?
sys_trace()
writes the mask integer of process from its argument. If the user doesn't call trace()
, all processes will have empty masks and hence avoid printing lines.fork()
will copy mask number to the child process.PGSIZE
.sys_sysinfo()
copy the result numbers to the given address by calling copyout()
.