6.S081 Xv6 Lab 2: system calls

Meaning Unknown's Head Image

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:

  1. add a prototype for the system call to user/user.h

    int xxx(int)
    
  2. add a stub to user/usys.pl

    entry("xxx");
    
  3. add a syscall number to kernel/syscall.h

    #define SYS_xxx  22
    
  4. add the new syscall into kernel/syscall.c

    extern uint64 sys_xxx(void);  // 1
    
    static uint64 (*syscalls[])(void) = {
         
    ...
    [SYS_xxx]   sys_xxx,          // 2
    };
    
  5. 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.

    uint64 
    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
    }
    
  6. implement the syscall somewhere in the kernel. (e.g. implement a xxx function , defines in kernel/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 tracesystem 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:

...

// *
uint64
sys_trace(void)
{
   
	if (argint(0, &myproc()->tracemask) < 0)
		return -1;

	return 0;
}

kernel/proc.h:

struct proc {
   
  struct spinlock lock;
  ...
  int pid;                     // Process I
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值