VMMCP: initialization
[akaros.git] / kern / src / env.c
index 181fc3e..5187e9d 100644 (file)
@@ -83,6 +83,8 @@ WRITES(e->env_pgdir, e->env_cr3, e->procinfo, e->procdata)
                goto env_setup_vm_error_i;
        if (!(e->procdata = get_cont_pages(LOG2_UP(PROCDATA_NUM_PAGES), 0)))
                goto env_setup_vm_error_d;
+       /* Normally we'd 0 the pages here.  We handle it in proc_init_proc*.  Don't
+        * start the process without calling those. */
        for (int i = 0; i < PROCINFO_NUM_PAGES; i++) {
                if (page_insert(e->env_pgdir, kva2page((void*)e->procinfo + i *
                                PGSIZE), (void*SNT)(UINFO + i*PGSIZE), PTE_USER_RO) < 0)
@@ -93,9 +95,6 @@ WRITES(e->env_pgdir, e->env_cr3, e->procinfo, e->procdata)
                                PGSIZE), (void*SNT)(UDATA + i*PGSIZE), PTE_USER_RW) < 0)
                        goto env_setup_vm_error;
        }
-       memset(e->procinfo, 0, sizeof(struct procinfo));
-       memset(e->procdata, 0, sizeof(struct procdata));
-
        /* Finally, set up the Global Shared Data page for all processes.  Can't be
         * trusted, but still very useful at this stage for us.  Consider removing
         * when we have real processes (TODO). 
@@ -138,17 +137,14 @@ void env_user_mem_free(env_t* e, void* start, size_t len)
        assert((uintptr_t)start + len <= UVPT); //since this keeps fucking happening
        int user_page_free(env_t* e, pte_t* pte, void* va, void* arg)
        {
-               if(PAGE_PRESENT(*pte))
-               {
-                       page_t* page = ppn2page(PTE2PPN(*pte));
-                       *pte = 0;
-                       page_decref(page);
-               } else {
-                       assert(PAGE_PAGED_OUT(*pte));
-                       /* TODO: (SWAP) deal with this */
-                       panic("Swapping not supported!");
-                       *pte = 0;
-               }
+               if (!PAGE_PRESENT(*pte))
+                       return 0;
+               page_t *page = ppn2page(PTE2PPN(*pte));
+               *pte = 0;
+               page_decref(page);
+               /* TODO: consider other states here (like !P, yet still tracking a page,
+                * for VM tricks, page map stuff, etc.  Should be okay: once we're
+                * freeing, everything else about this proc is dead. */
                return 0;
        }