跟踪分析Linux内核系统调用处理过程

跟踪分析Linux内核系统调用处理过程

学号245。原创作品,转载请注明出处:https://github.com/mengning/linuxkernel/

实验要求

举例跟踪分析Linux内核5.0系统调用处理过程

  • 编译内核5.0

  • qemu -kernel linux-5.0.1/arch/x86/boot/bzImage -initrd rootfs.img

  • 选择系统调用号后两位与您的学号后两位相同的系统调用进行跟踪分析

  • https://github.com/mengning/menu

  • 给出相关关键源代码及实验截图,撰写一篇博客(署真实姓名或学号最后3位编号),并在博客文章中注明“原创作品转载请注明出处 + https://github.com/mengning/linuxkernel/ ”,博客内容的具体要求如下:

    • 题目自拟,内容围绕系统调用进行;
    • 博客中需要使用实验截图
    • 博客内容中需要仔细分析系统调用、保护现场与恢复现场、系统调用号及参数传递过程

    • 总结部分需要阐明自己对系统调用工作机制的理解。

环境配置

编译内核

下载内核5.0并解压

mkdir kernel
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.0.1.tar.xz
xz -d linux-5.0.1.tar.xz
tar -xvf linux-5.0.1.tar
cd linux-5.0.1
make menuconfig //kernel hacking -> Compile-time checks and compiler options [*]compile the kernel with debug info
make

过程中需要手动安装部分依赖。

制作根文件系统

按照如下步骤

cd ..
mkdir rootfs
git clone https://github.com/mengning/menu.git
cd menu
sudo apt install gcc-multilib
gcc -pthread -o init linktable.c menu.c test.c -m32 -static
cd ../rootfs
cp ../menu/init ./
find . | cpio -o -Hnewc | gzip -9 > ../rootfs.img

启动MenuOS

qemu-system-i386 -kernel bzImage -initrd rootfs.img

正常启动后如下图所示:

跟踪系统调用

选择学号后两位的系统调用,我的是45,如图所示:

__NR_brk

在test.c中添加函数,重新编译制作rootfs.img

内核还没编译完,之后再更

猜你喜欢

转载自www.cnblogs.com/luuu/p/10561826.html