MIT S081 Lab 2 System Calls

Lab链接

一 实现trace功能

1 题目要求

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.

We provide a trace user-level program that runs another program with tracing enabled (see user/trace.c). When you're done, you should see output like this:

cpp 复制代码
$ trace 32 grep hello README
3: syscall read -> 1023
3: syscall read -> 966
3: syscall read -> 70
3: syscall read -> 0
$
$ trace 2147483647 grep hello README
4: syscall trace -> 0
4: syscall exec -> 3
4: syscall open -> 3
4: syscall read -> 1023
4: syscall read -> 966
4: syscall read -> 70
4: syscall read -> 0
4: syscall close -> 0
$
$ grep hello README
$
$ trace 2 usertests forkforkfork
usertests starting
test forkforkfork: 407: syscall fork -> 408
408: syscall fork -> 409
409: syscall fork -> 410
410: syscall fork -> 411
409: syscall fork -> 412
410: syscall fork -> 413
409: syscall fork -> 414
411: syscall fork -> 415
...
$   

trace是一个运行在用户空间的程序。 你需要实现一个用户空间程序 trace,它将启动另一个程序并启用跟踪功能。

trace调用时,会传入一个int类型的mask值,来指明需要对哪些系统调用trace。

获取argument,获取系统调用号、

相关推荐
snow@li2 小时前
Java:Java 服务器(Web 容器 / Servlet 容器)完整工作清单
java·服务器·前端
JL152 小时前
Agent工程-为什么Agent必须有观测和Tracing
服务器·网络·人工智能·安全
洋子3 小时前
Yank Note 系列 14 - 我和 AI 怎么一起写文章
前端·markdown
神州世通3 小时前
IP Office内置外显卡兼容性说明
服务器·网络·tcp/ip
ylscode3 小时前
CVE-2026-31694 漏洞深度分析:Linux 内核 FUSE 组件存在本地提权风险,普通用户可直取 root 权限
linux·运维·服务器
江华森3 小时前
前端构建工具 Webpack 速览
前端·webpack·node.js
frank00600713 小时前
Rocky 9.8设置本地yum源
服务器
谙忆10244 小时前
HTTP 图片缓存实战:Cache-Control、ETag、内容哈希文件名与 CDN 回源到底怎么配
前端
小妖6664 小时前
React input 输入卡顿问题
前端·javascript·react.js
এ慕ོ冬℘゜4 小时前
JavaScript 数据类型检测与转换、运算符超全实战详解
前端·html