feat: heap support and re-worked
[lunaix-os.git] / lunaix-os / kernel / asm / x86 / pfault.c
index 4f0ccdaffa59b53896acedb8ecb00097639e5558..0d5131f53def4ce02ea288afdaf1efa1391fdb9c 100644 (file)
@@ -89,7 +89,7 @@ intr_routine_page_fault(const isr_param* param)
     if (hit_region->mfile && !PG_IS_PRESENT(*pte)) {
         struct v_file* file = hit_region->mfile;
         u32_t offset =
-          (ptr - hit_region->start) & (PG_SIZE - 1) + hit_region->offset;
+          (ptr - hit_region->start) & (PG_SIZE - 1) + hit_region->foff;
         uintptr_t pa = pmm_alloc_page(__current->pid, 0);
 
         if (!pa) {
@@ -102,9 +102,15 @@ intr_routine_page_fault(const isr_param* param)
         ptr = PG_ALIGN(ptr);
         memset(ptr, 0, PG_SIZE);
 
-        int errno = file->ops->read_page(file->inode, ptr, PG_SIZE, offset);
+        int errno = 0;
+        if (hit_region->init_page) {
+            errno = hit_region->init_page(hit_region, ptr, offset);
+        } else {
+            errno = file->ops->read_page(file->inode, ptr, PG_SIZE, offset);
+        }
+
         if (errno < 0) {
-            kprintf(KERROR "fail to read page (%d)\n", errno);
+            kprintf(KERROR "fail to populate page (%d)\n", errno);
             goto segv_term;
         }