没有合适的资源?快使用搜索试试~ 我知道了~
张逸凯_171840708_操作系统实验三1
需积分: 0 0 下载量 179 浏览量
2022-08-03
13:10:25
上传
评论
收藏 5.53MB PDF 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/86281697/0001-435dfdc2569151f8127421807dee6159_thumbnail.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
40页
1. 分配系统调用号, 修改系统调用表 2. 申明系统调用原型 3. 实现系统调用 1. 清除残留的.config 和.o 文件
资源详情
资源评论
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/86281697/bg1.jpg)
张
逸
凯
171840708
第二题: 添加一个新的系统调用 memsys (第一题阅读源码与分析请见下一小节)
实验环境
大致实验思路
实验过程
设计并添加系统调用
编译内核
编写用户态测试程序
最后结果如下:
第一题: 阅读新版内核中的内存管理模块, 详细了解 Linux 分页机制的实现方法;
Linux 源码内存管理部分阅读
页框
mapping
lru
virtual
分配和释放页面
页面分配函数
页面释放函数
分配掩码 gfp_mask
虚拟内存管理
进程地址空间
内存描述符 mm_struct
缺页异常
do_page_fault()
4级页表结构
寻址过程
来看分配内存的具体过程
还原线性地址到物理地址的转换
为了顺利进行第二题的 Linux源码理解 准备工作
PCB 与地址信息
附录: 辛酸的实验过程细节与截图
碰到了GRUB引导出现错误的情况, 了解了一下 GRUB 以及Linux启动的具体过程:
一些trivial的细节
遇到的bug们
达成成就截图
总结
参考文献
![](https://csdnimg.cn/release/download_crawler_static/86281697/bg2.jpg)
第
二
题
:
添
加
一个
新
的
系
统
调
用
memsys
(
第
一
题
阅
读
源
码
与
分
析
请
见
下一
小
节
)
说明
:
为内核添加一个新的系统调用 memsys , 其从调用者接收一个代表进程 ID 的字符串参数,打印分
配给该进程用户空间的所有物理页框;并编译、安装内核, 测试 memsys 系统调用.
实
验
环
境
内核源码是The Linux Kernel Archives下载的 4.4.205 (stable).
大
致
实
验
思
路
因为需要打印物理页框号, 如果
没
有
地址
转
换
也
就
没
有
所
谓
页
框
号
,
所
以
需
要
从
地址
转
换
入
手
. 大体可概
括为查分配给用户进程的内存空间的线性地址
,
查页表解析出页框号.
实
验
过
程
设计
并
添
加
系
统
调
用
1. 分配系统调用号
,
修改系统调用表
./arch/x86/entry/syscalls/syscall_64.tbl
![](https://csdnimg.cn/release/download_crawler_static/86281697/bg3.jpg)
2. 申明系统调用原型
./include/linux/syscalls.h
3. 实现系统调用
./kernel/sys.c
SYSCALL_DEFINE1(memsys, pid_t, pid) {
struct pid * tPid;
struct task_struct * task;
tPid = find_get_pid(pid);
task = pid_task(tPid, PIDTYPE_PID);
printk("state: %ld\n", task->state);
printk("pid: %d\n", task->pid);
printk("tgid: %d\n", task->tgid);
struct vm_area_struct *curMmap;
curMmap = task->mm->mmap;
int myIndex = 0;
do {
printk("vaddr %d: %08lx~%08lx",
myIndex,
curMmap->vm_start,
curMmap->vm_end);
unsigned long tmpStart = curMmap->vm_start,
tmpEnd = curMmap->vm_end;
if (tmpStart >= __START_KERNEL_map) {
tmpStart -= __START_KERNEL_map;
printk("WARNING: is start >= KERNEL_IMAGE_SIZE:
%d\n", (tmpStart >= KERNEL_IMAGE_SIZE));
tmpStart += phys_base;
} else {
printk("WARNING: is start < PAGE_OFFSET: %d\n",
(tmpStart < PAGE_OFFSET));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
![](https://csdnimg.cn/release/download_crawler_static/86281697/bg4.jpg)
tmpStart -= PAGE_OFFSET;
// printk("WARNING: is valid ...");
}
if (tmpEnd >= __START_KERNEL_map) {
tmpEnd -= __START_KERNEL_map;
printk("WARNING: is end >= KERNEL_IMAGE_SIZE: %d\n",
(tmpEnd >= KERNEL_IMAGE_SIZE));
tmpEnd += phys_base;
} else {
printk("WARNING: is end < PAGE_OFFSET: %d\n",
(tmpEnd < PAGE_OFFSET));
tmpEnd -= PAGE_OFFSET;
// printk("WARNING: is valid ...");
}
printk("paddr %d: %08lx~%08lx",
myIndex,
tmpStart,
tmpEnd);
printk("PAGE FRAME No. (addr %d): %08lx~%08lx",
myIndex,
(tmpStart >> 12),
(tmpEnd >> 12));
++myIndex;
curMmap = curMmap->vm_next;
} while(curMmap != NULL);
printk("nice: %d\n", task_nice(task));
printk("priority: %d\n", task_prio(task));
return 0;
}
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SYSCALL_DEFINE1(memsys, pid_t, pid) {
struct pid * tPid;
struct task_struct * task;
tPid = find_get_pid(pid);
task = pid_task(tPid, PIDTYPE_PID);
struct vm_area_struct *curMmap;
curMmap = task->mm->mmap;
struct inode *inode;
do {
unsigned long tmpStart = curMmap->vm_start,
tmpEnd = curMmap->vm_end;
if (tmpStart >= __START_KERNEL_map) {
tmpStart -= __START_KERNEL_map;
printk("WARNING: is start >= KERNEL_IMAGE_SIZE:
%d\n", (tmpStart >= KERNEL_IMAGE_SIZE));
tmpStart += phys_base;
} else {
printk("WARNING: is start < PAGE_OFFSET: %d\n",
(tmpStart < PAGE_OFFSET));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
![](https://csdnimg.cn/release/download_crawler_static/86281697/bg5.jpg)
注
意
:
传入的参数就是进程ID(pid), 上面引入了宏 SYSCALL_DEFINEN(sname) 对原型进行了封装, 其中的
N 是该系统调用所需要参数的个数.
编
译
内
核
1. 清除残留的
.con
fi
g
和
.o
文件
tmpStart -= PAGE_OFFSET;
// printk("WARNING: is valid ...");
}
if (tmpEnd >= __START_KERNEL_map) {
tmpEnd -= __START_KERNEL_map;
printk("WARNING: is end >= KERNEL_IMAGE_SIZE: %d\n",
(tmpEnd >= KERNEL_IMAGE_SIZE));
tmpEnd += phys_base;
} else {
printk("WARNING: is end < PAGE_OFFSET: %d\n",
(tmpEnd < PAGE_OFFSET));
tmpEnd -= PAGE_OFFSET;
// printk("WARNING: is valid ...");
}
printk("%08lx~%08lx",
(tmpStart >> 12),
(tmpEnd >> 12));
printk("%08llx",
((loff_t)vma->vm_pgoff) << PAGE_SHIFT);
if (vma->vm_file) {
inode = curMmap->vm_file->f_path.dentry->d_inode;
printk("%lu",
inode->i_ino);
}
printk("\n");
// 打印的第一个是分配的块号范围, 第二个是区域从文件(使用mmap)映射的偏
移量, 第三个是inode号.
++myIndex;
curMmap = curMmap->vm_next;
} while(curMmap != NULL);
return 0;
}
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
make mrproper1
剩余39页未读,继续阅读
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![avatar](https://profile-avatar.csdnimg.cn/e0fdb61cbfd64e3b880ac74ae45ab000_weixin_35734209.jpg!1)
销号le
- 粉丝: 26
- 资源: 289
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0