// mmaptest never passed a non-zero addr argument. // so addr here is ignored and a new unmapped va region is found to // map the file // our implementation maps file right below where the trapframe is, // from high addresses to low addresses.
// Find a free vma, and calculate where to map the file along the way. for (int i = 0; i < NVMA; i++){ structvma *vv = &p->vmas[i]; if (vv->valid == 0){ if (v == 0){ v = &p->vmas[i]; // found free vma; v->valid = 1; } } elseif (vv->vastart < vaend){ vaend = PGROUNDDOWN(vv->vastart); } }
// read data from disk begin_op(); ilock(v->f->ip); readi(v->f->ip, 0, (uint64)pa, v->offset + PGROUNDDOWN(va - v->vastart), PGSIZE); iunlock(v->f->ip); end_op();
// set appropriate perms, then map it. int perm = PTE_U; if (v->prot & PROT_READ) perm |= PTE_R; if (v->prot & PROT_WRITE) perm |= PTE_W; if (v->prot & PROT_EXEC) perm |= PTE_X;
if (mappages(p->pagetable, va, PGSIZE, (uint64)pa, PTE_R | PTE_W | PTE_U) < 0) { panic("vmalazytouch: mappages"); }