Lab: System calls

This lab shows us how to create a system call and use definitions in kernel code.

How to activate a system call in xv6?

  1. ecall <num> - There is a function declaration in user/user.h, a system call number in kernel/syscall.h and a stub to user/usys.pl (which generates user-level syscall instructions).
  2. jump to syscall() - ecall will jump to the syscall() function in kernel/syscall.c with the calling number saved in a7 register.
  3. syscall() calls corresponding kernel code - syscall() use the number as an index of a function pointer array to get the address of its kernel code and call it.
  4. execute kernel code - Execute the actual kernel system call, ex. sys_fork(), in kernel/sysproc.c and other files.
  5. resume user code

System Call Tracing (moderate)

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?

Sysinfo (moderate)