+ // impossible cases or accessing privileged page
+ goto segv_term;
+ }
+
+ // an anonymous page and not present
+ // -> a new page need to be alloc
+ if ((hit_region->attr & REGION_ANON)) {
+ if (!PG_IS_PRESENT(*pte)) {
+ cpu_invplg((ptr_t)pte);
+
+ ptr_t pa = pmm_alloc_page(__current->pid, 0);
+ if (!pa) {
+ goto oom;
+ }
+
+ *pte = *pte | pa | PG_PRESENT | PG_ALLOW_USER;
+ memset((void*)PG_ALIGN(ptr), 0, PG_SIZE);
+ goto resolved;
+ }
+ // permission denied on anon page (e.g., write on readonly page)
+ goto segv_term;
+ }
+
+ // if mfile is set (Non-anonymous), then it is a mem map
+ if (hit_region->mfile && !PG_IS_PRESENT(*pte)) {
+ struct v_file* file = hit_region->mfile;
+
+ ptr = PG_ALIGN(ptr);
+
+ u32_t mseg_off = (ptr - hit_region->start);
+ u32_t mfile_off = mseg_off + hit_region->foff;
+ ptr_t pa = pmm_alloc_page(__current->pid, 0);
+
+ if (!pa) {
+ goto oom;
+ }
+
+ cpu_invplg((ptr_t)pte);
+ *pte = (*pte & 0xFFF) | pa | PG_PRESENT | PG_ALLOW_USER;
+
+ memset((void*)ptr, 0, PG_SIZE);
+
+ int errno = 0;
+ if (mseg_off < hit_region->flen) {
+ errno =
+ file->ops->read_page(file->inode, (void*)ptr, PG_SIZE, mfile_off);