lab3
前言
这是中山大学数据科学与计算机学院2019年操作系统实验中关于Ucore的项目以及实验报告,实验要求与Ucore手则有少量出入。
所有源代码已经上传至github。
github个人主页: https://starashzero.github.io
项目地址: https://github.com/StarashZero/Ucore-homework
【实验题目】
实验 4 虚拟内存管理
【实验目的】
- 了解虚拟内存的 Page Fault 异常处理实现
- 了解页替换算法在操作系统中的实现
【实验要求】
练习 0 :填写已有实验
练习 1 :给未被映射的地址映射上物理页(需要编程
练习 2 :补充完成基于 FIFO 的页面替换算法(需要编程)
【实验方案】
练习 0
这里使用的是系统自带的meld 工具进行整合,只需要选择两个文件夹,然后进行比较,在需要修改的文件中点击 Compare, 填充代码。
练习 1
do_pgfault 函数是这次要填写的内容
/* do_pgfault - interrupt handler to process the page fault execption
* @mm : the control struct for a set of vma using the same PDT
* @error_code : the error code recorded in trapframe->tf_err which is setted by x86 hardware
* @addr : the addr which causes a memory access exception, (the contents of the CR2 register)
*
* CALL GRAPH: trap--> trap_dispatch-->pgfault_handler-->do_pgfault
* The processor provides ucore's do_pgfault function with two items of information to aid in diagnosing
* the exception and recovering from it.
* (1) The contents of the CR2 register. The processor loads the CR2 register with the
* 32-bit linear address that generated the exception. The do_pgfault fun can
* use this address to locate the corresponding page directory and page-table
* entries.
* (2) An error code on the kernel stack. The error code for a page fault has a format different from
* that for other exceptions. The error code tells the exception handler three things:
* -- The P flag (bit 0) indicates whether the exception was due to a not-present page (0)
* or to either an access rights violation or the use of a reserved bit (1).
* -- The W/R flag (bit 1) indicates whether the memory access that caused the exception
* was a read (0) or write (1).
* -- The U/S flag (bit 2) indicates whether the processor was executing at user mode (1)
* or supervisor mode (0) at the time of the exception.
*/
用于处理 page fault 产生的异常,其中异常主要分为三种,页不存在、页在外存、没有权限等。
在函数中出现两个新出现的结构体 mm_struct:
// the control struct for a set of vma using the same PDT
struct mm_struct {
list_entry_t mmap_list; // linear list link which sorted by start addr of vma
struct vma_struct *mmap_cache; // current accessed vma, used for speed purpose
pde_t *pgdir; // the PDT of these vma
int map_count; // the count of these vma
void *sm_priv; // the private data for swap manager
}