ImageVerifierCode 换一换
格式:DOC , 页数:6 ,大小:179.50KB ,
资源ID:3588555      下载积分:10 文钱
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,省得不是一点点
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.wenke99.com/d-3588555.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(操作系统实验一指导手册.doc)为本站会员(da****u)主动上传,文客久久仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知文客久久(发送邮件至hr@wenke99.com或直接QQ联系客服),我们立即给予删除!

操作系统实验一指导手册.doc

1、操作系统实验一指导手册提示 :此文档只包含一些基本的实验提示,很多地方仍然需要自己去思考去实现。有能力的同学可以忽略此文档。Fedora 7 虚拟机镜像的初始登录用户名:seu,密码:seu,root 用户密码:seu。实验 1:Linux 内核代码分析1. 解压内核桌面上的 linux-2.6.21.tar.gz 是 linux-2.6.21 的内核代码压缩包,解压:$ cd Desktop$ tar zxvf linux-2.6.21.tar.gz$ cd linux-2.6.212. 生成内核配置文件将当前正在运行的内核对应的配置文件作为模板来生成.config 文件,即将/boot 目

2、录下的已有的 config 文件复制到 linux-2.6.21 目录下$ make mrproper$ cp /boot/config-uname -r ./config第一个命令 make mrproper 用来保证内核树是干净的,如果内核第一次编译则可以省略。其中的 uname r 命令可查看当前环境下的内核版本号。更新 config 文件:$ make oldconfig部分新配置项会提示用户选择,都选 N 或者缺省即可,完成后即可生成.config 文件。3. 编译安装内核在编译内核前,可以定义自己的内核版本号,在内核代码的根目录下有 Makefile 文件,例如将第 4 行改为:E

3、XTRAVERSION = -seu这样新内核版本号就是 2.6.21-seu$ make all$ su# make modules_install# make install# make headers_installMake all 的执行过程可能比较长。如果三个命令均成功执行,可以观察引导程序 grub 的配置文件/boot/grub/menu.lst 的内容,在 hiddenmenu 之后可以看到刚刚编译安装的内核版本,将 hiddenmenu 那一行注释或删除,方便直接操作菜单:#hiddenmenu 或者 hiddenmenu然后重启系统:# reboot重启后可以看到 grub

4、 菜单已经包含了新编译的内核。如果新内核启动失败,一般是由于配置或者内核代码修改的有问题,选择原先的内核启动,再进行修改、编译。实验 2:新增系统调用1. 在文件 arch/i386/kernel/syscall_table.S 的尾部加上要新增的系统调用函数的名称,如下图中添加了 psta 系统调用,注释中的 320 表示它的系统调用号2. 在 include/linux 目录下添加头文件 psta.h,比如(千万别忘记 struct 结尾的分号):修改 include/linux 目录下的 Kbuild 文件,把 psta.h 文件加进去。header-y += x25.hheader-y

5、 += psta.hunifdef-y += acct.h在 kernel 目录下新建文件 psta.c,在该文件中实现 sys_psta 函数:宏 asmlinkage 定义在 linux/linkage.h 中,表示函数的参数通过栈传递,而不是寄存器,所有的系统调用都遵循这种参数传递方式。在上面的函数返回之前,可以插入打印一句话到内核日志,方便后面验证执行结果。printk(“Hello worldn“);注意顶上包含下面头文件,实现了 printk。#include 。3. 修改文件 kernel/Makefile,使得 psta.c 在编译时可见:另外,第 2 步中 psta 的实现不

6、一定要在一个新文件中,例如文件 kernel/sys.c 也许是添加这个系统调用的合适位置,这样的话第 3 步就不需要了。4. 在 include/asm-i386/unistd.h 里加上系统调用号的宏定义:其中 NR_syscalls 表示的值应该是最大的系统调用号加一。5. 修改 include/linux/syscalls.h,加上函数 sys_psta 的声明。先在头上加入结构体申明 struct pinfo; 在该文件的头文件引用列表的末尾添加:这算是 pinfo 结构体的实现。在函数申明列表的最后添加:6. 重新编译内核在清理上次编译生成的中间文件之前,最好将配置好的.confi

7、g 文件备份至别的目录下以防删除,否则必须再执行实验 1 中的第 2 步配置.config 文件。$ make mrproper在实验 1 中就已提到该命令,用于清理编译内核代码的中间文件,它也会删除.config 文件。在清理执行完成后,将备份的.config 文件复制回来。然后执行实验 1 中的第 3 步就可以编译安装新内核了。在这个过程里面可以换一个内核版本名称,以示区别,比如 EXTRAVERSION = -seu2。安装好的内核必须 reboot 后才能生效。以上 6 步成功执行后系统调用 psta 就已被添加到系统中,下面来进行测试。首先,可以用 uname -r 命令测试目前所使

8、用的内核版本号。然后,随便写一个 test.c 文件,在里面使用 glic 库提供的函数 syscall 来间接地使用新系统调用,调用 syscall 必须添加以下两个头文件,以及头文件#include 。函数的原型如下图,syscall 的第一个参数是系统调用号,后面的参数是该系统调用的各个参数,返回值就是系统调用的返回值。例如函数 psta 的系统调用号是 320,且接受一个类型为 struct pinfo *的参数。具体的测试代码请大家根据自己实现的 psta 来编写,只要体现出调用了 psta 函数即可。编译的时候可以用命令 gcc -o test test.c -I/home/seu

9、/Desktop/linux-2.6.21/usr/include。关于为什么这里编译用户态程序的时候还需要用 I 参数强行指定内核头文件路径,请查考实验末尾的文章。如果有需要的话,可以自己修改 kernel headers 文件的存放位置。最后,如果系统调用执行成功,用 dmesg 命令可以再内核消息列表的最后看到 hello world。=Exporting kernel headers for use by userspacehttps:/www.kernel.org/doc/Documentation/kbuild/headers_install.txtThe “make header

10、s_install“ command exports the kernels header files in a form suitable for use by userspace programs.The linux kernels exported header files describe the API for user space programs attempting to use kernel services. These kernel header files are used by the systems C library (such as glibc or uClib

11、c) to define available system calls, as well as constants and structures to be used with these system calls. The C librarys header files include the kernel header files from the “linux“ subdirectory. The systems libc headers are usually installed at the default location /usr/include and the kernel h

12、eaders in subdirectories under that (most notably /usr/include/linux and /usr/include/asm).Kernel headers are backwards compatible, but not forwards compatible. This means that a program built against a C library using older kernel headers should run on a newer kernel (although it may not have acces

13、s to new features), but a program built against newer kernel headers may not work on an older kernel.The “make headers_install“ command can be run in the top level directory of the kernel source code (or using a standard out-of-tree build). It takes two optional arguments:make headers_install ARCH=i

14、386 INSTALL_HDR_PATH=/usrARCH indicates which architecture to produce headers for, and defaults to the current architecture. The linux/asm directory of the exported kernel headers is platform-specific, to see a complete list of supported architectures use the command:ls -d include/asm-* | sed s/.*-/

15、INSTALL_HDR_PATH indicates where to install the headers. It defaults to“./usr“.An include directory is automatically created inside INSTALL_HDR_PATH and headers are installed in INSTALL_HDR_PATH/include.The command “make headers_install_all“ exports headers for all architectures simultaneously. (Thi

16、s is mostly of interest to distribution maintainers, who create an architecture-independent tarball from the resulting include directory.) You also can use HDR_ARCH_LIST to specify list of architectures. Remember to provide the appropriate linux/asm directory via “mv“ or “ln -s“ before building a C library with headers exported this way.The kernel header export infrastructure is maintained by David Woodhouse.

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。