6.S081 Xv6 Lab 2: system calls

这篇博客介绍了如何在Xv6中添加新的系统调用,包括在不同文件中实现原型、 stub、系统调用号等步骤。此外,还详细说明了如何实现系统调用跟踪功能,该功能允许根据掩码追踪特定系统调用,以辅助后续的调试工作。同时,博主还阐述了增加`sysinfo`系统调用的细节,此调用能收集系统运行信息,如空闲内存和活动进程数量。
摘要由CSDN通过智能技术生成

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
MIT 6.828是一门关于xv6操作系统的课程,该课程提供了关于xv6操作系统的中文指南和实验室。 xv6是一个操作系统的教学版本,MIT 6.828课程提供了xv6全文的翻译成书供学习使用。 在课程中,还提供了一些实验,供学生进行实践和学习。 关于xv6的具体实现细节,根据引用中的内容,在user.h文件中可以找到函数的定义。需要在date.c的代码中补充相应的函数。 另外,引用中提供了一个样例过程,展示了一系列操作的执行顺序,包括fork、exec、open、close、write等。这个样例过程可以帮助理解xv6操作系统的运行机制。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [MIT-6.828:MIT 6.828操作系统课程](https://download.csdn.net/download/weixin_42139357/15728097)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [MIT6.828 Homework3 xv6 system calls](https://blog.csdn.net/qq_43012789/article/details/107746030)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值