voidprintwalk(pagetable_t pagetable,int level){
char* prefix;if(level ==2) prefix ="..";elseif(level ==1) prefix =".. ..";else prefix =".. .. ..";for(int i =0; i <512; i++){
pte_t pte = pagetable[i];if(pte & PTE_V){
uint64 pa =PTE2PA(pte);printf("%s%d: pte %p pa %p\n", prefix, i, pte, pa);if((pte &(PTE_R|PTE_W|PTE_X))==0){
printwalk((pagetable_t)pa, level -1);}}}}intvmprint(pagetable_t pagetable){
printf("page table %p\n", pagetable);printwalk(pagetable,2);return0;}
2. A kernel page table per process
这一题是要为每个进程分配一个内核页表。为第三题做准备
添加一个kernel pagetable项到struct proc结构体中
struct proc {
struct spinlock lock;
// p->lock must be held when using these:
enum procstate state; // Process state
struct proc *parent; // Parent process
void *chan; // If non-zero, sleeping on chan
int killed; // If non-zero, have been killed
int xstate; // Exit status to be returned to parent's wait
int pid; // Process ID
// these are private to the process, so p->lock need not be held.
uint64 kstack; // Virtual address of kernel stack
uint64 sz; // Size of process memory (bytes)
pagetable_t pagetable; // User page table
struct trapframe *trapframe; // data page for trampoline.S
struct context context; // swtch() here to run process
struct file *ofile[NOFILE]; // Open files
struct inode *cwd; // Current directory
char name[16]; // Process name (debugging)
pagetable_t kpagetable; //每个进程保存一个kernel pagetable
};