X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/095a899a9749b85443e546b1062026747445658c..c166bd62fbb907f95f79f621e2a2fb4fdde08e01:/lunaix-os/kernel/process/thread.c diff --git a/lunaix-os/kernel/process/thread.c b/lunaix-os/kernel/process/thread.c index e74718e..4ad4653 100644 --- a/lunaix-os/kernel/process/thread.c +++ b/lunaix-os/kernel/process/thread.c @@ -3,8 +3,7 @@ #include #include #include -#include -#include +#include #include #include @@ -64,17 +63,16 @@ __alloc_kernel_thread_stack(struct proc_info* proc, ptr_t vm_mnt) return 0; found:; - ptr_t pa = pmm_alloc_cpage(KSTACK_PAGES - 1, 0); + // KSTACK_PAGES = 3, removal one guardian pte, give order 1 page + struct leaflet* leaflet = alloc_leaflet(1); - if (!pa) { + if (!leaflet) { WARN("failed to create kernel stack: nomem\n"); return 0; } set_pte(ptep, guard_pte); - - pte_t pte = mkpte(pa, KERNEL_DATA); - vmm_set_ptes_contig(ptep + 1, pte, LFT_SIZE, KSTACK_PAGES - 1); + ptep_map_leaflet(ptep + 1, mkpte_prot(KERNEL_DATA), leaflet); ptep += KSTACK_PAGES; return align_stack(ptep_va(ptep, LFT_SIZE) - 1); @@ -83,6 +81,7 @@ found:; void thread_release_mem(struct thread* thread) { + struct leaflet* leaflet; struct proc_mm* mm = vmspace(thread->process); ptr_t vm_mnt = mm->vm_mnt; @@ -90,9 +89,13 @@ thread_release_mem(struct thread* thread) assert(vm_mnt); pte_t* ptep = mkptep_va(vm_mnt, thread->kstack); + leaflet = pte_leaflet(*ptep); ptep -= KSTACK_PAGES - 1; - vmm_unset_ptes(ptep, KSTACK_PAGES); + set_pte(ptep, null_pte); + ptep_unmap_leaflet(ptep + 1, leaflet); + + leaflet_return(leaflet); if (thread->ustack) { if ((thread->ustack->start & 0xfff)) {