作业信息
这个作业属于哪个课程 | <2020-2021-1Linux内核原理与分析)> |
---|---|
这个作业要求在哪里 | <2020-2021-1Linux内核原理与分析第六周作业> |
这个作业的目标 | 分析system_call中断处理过程 |
作业正文 | 2020-2021-1 20209306 《linux内核原理与分析》第六周作业 |
一、给MenuOS增加命令。
这里使用上周的time和time-asm命令。
1、下载新版本menu,使用代码如下:
cd LinuxKernel
rm -rf menu
git clone http://github.com/mengning/menu.git
2、在MenuOS中添加函数
3、打开menu镜像查看添加的函数。
二、使用gdb跟踪系统调用内核函数sys_time。
cd ..
qemu -kernel linux-3.18.6/arch/x86/boot/bzImage/ -initrd rootfs.img -S -s
然后另开窗口启动gdb并输入:
file linux-3.18.6/vmlinux # 在gdb界面中targe remote之前加载符号表
target remote:1234 # 建立gdb和gdbserver之间的连接,按c 让qemu上的Linux继续运行
设置断点break start_kernel
设置断点break sys_time
并运行
三、系统调用在内核代码中的处理过程
之前介绍的start_kernel函数里调用的trap_init函数,trap_init函数调用了set_system_trap_gate函数。其中有系统调用中断向量0x80和system_call中断服务程序入口的函数指针。system_call被声明为一个函数,其实是一段汇编代码的入口。
system_call 流程图如下:
Entry(system_call)进入函数
SAVE_ALL:保存现场
call *sys_call_table(,%eax,4)调用了系统调度处理函数,eax存的是系统调用号,是实际的系统调度程序。
sys_call_table:系统调用分派表
syscall_after_all:保存返回值
若有sys_exit_work,则进入sys_exit_work:会有一个进程调度时机。
work_pending -> work_notifysig,用来处理信号
可能call schedule:进程调度代码
可能跳转到restore_all,恢复现场。
若无sys_exit_work,就执行restore_all恢复,返回用户态。
INTERRUPT_RETURN <=> iret,结束。