X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/04ee277abd77fc51c5ab02ee58790a859607ea24..7c7b5f05d39b7739d990f71256a2267ec67a6913:/lunaix-os/kernel/process/process.c?ds=inline diff --git a/lunaix-os/kernel/process/process.c b/lunaix-os/kernel/process/process.c index 63fc7ad..370a542 100644 --- a/lunaix-os/kernel/process/process.c +++ b/lunaix-os/kernel/process/process.c @@ -1,7 +1,5 @@ -#include #include #include -#include #include #include #include @@ -13,6 +11,9 @@ #include #include +#include +#include + LOG_MODULE("PROC") ptr_t @@ -24,7 +25,7 @@ __dup_pagetable(pid_t pid, ptr_t mount_point) x86_page_table* ptd = (x86_page_table*)PG_MOUNT_1; x86_page_table* pptd = (x86_page_table*)(mount_point | (0x3FF << 12)); - size_t kspace_l1inx = L1_INDEX(KERNEL_MM_BASE); + size_t kspace_l1inx = L1_INDEX(KERNEL_EXEC); for (size_t i = 0; i < PG_MAX_ENTRIES - 1; i++) { @@ -63,7 +64,7 @@ __del_pagetable(pid_t pid, ptr_t mount_point) x86_page_table* pptd = (x86_page_table*)(mount_point | (0x3FF << 12)); // only remove user address space - for (size_t i = 0; i < L1_INDEX(KERNEL_MM_BASE); i++) { + for (size_t i = 0; i < L1_INDEX(KERNEL_EXEC); i++) { x86_pte_t ptde = pptd->entry[i]; if (!ptde || !(ptde & PG_PRESENT)) { continue; @@ -152,13 +153,13 @@ init_proc_user_space(struct proc_info* pcb) struct mm_region* mapped; struct mmap_param param = { .vms_mnt = VMS_MOUNT_1, .pvms = &pcb->mm, - .mlen = USTACK_SIZE, + .mlen = USR_STACK_SIZE, .proct = PROT_READ | PROT_WRITE, .flags = MAP_ANON | MAP_PRIVATE | MAP_FIXED, .type = REGION_TYPE_STACK }; int status = 0; - if ((status = mem_map(NULL, &mapped, USTACK_END, NULL, ¶m))) { + if ((status = mem_map(NULL, &mapped, USR_STACK, NULL, ¶m))) { kprint_panic("fail to alloc user stack: %d", status); } @@ -177,12 +178,12 @@ __mark_region(ptr_t start_vpn, ptr_t end_vpn, int attr) x86_pte_t* curproc = &PTE_MOUNTED(VMS_SELF, i); x86_pte_t* newproc = &PTE_MOUNTED(VMS_MOUNT_1, i); - cpu_invplg((ptr_t)newproc); + cpu_flush_page((ptr_t)newproc); if ((attr & REGION_MODE_MASK) == REGION_RSHARED) { // 如果读共享,则将两者的都标注为只读,那么任何写入都将会应用COW策略。 - cpu_invplg((ptr_t)curproc); - cpu_invplg((ptr_t)(i << 12)); + cpu_flush_page((ptr_t)curproc); + cpu_flush_page((ptr_t)(i << 12)); *curproc = *curproc & ~PG_WRITE; *newproc = *newproc & ~PG_WRITE; @@ -249,7 +250,7 @@ dup_proc() return pcb->pid; } -extern void __kernel_end; +extern void __kexec_end; void copy_kernel_stack(struct proc_info* proc, ptr_t usedMnt) @@ -261,7 +262,7 @@ copy_kernel_stack(struct proc_info* proc, ptr_t usedMnt) vmm_mount_pd(VMS_MOUNT_1, pt_copy); // 将新进程的页表挂载到挂载点#2 // copy the kernel stack - for (size_t i = KSTACK_START >> 12; i <= KSTACK_TOP >> 12; i++) { + for (size_t i = KERNEL_STACK >> 12; i <= KERNEL_STACK_END >> 12; i++) { volatile x86_pte_t* ppte = &PTE_MOUNTED(VMS_MOUNT_1, i); /* @@ -272,7 +273,7 @@ copy_kernel_stack(struct proc_info* proc, ptr_t usedMnt) In the name of Celestia our glorious goddess, I will fucking HATE the TLB for the rest of my LIFE! */ - cpu_invplg((ptr_t)ppte); + cpu_flush_page((ptr_t)ppte); x86_pte_t p = *ppte; ptr_t ppa = vmm_dup_page(pid, PG_ENTRY_ADDR(p));