X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/946c3fdd31300074cc78841795bd47af908ddddb..9eed27f6f2f002145667fb4abfc5e476b53630e5:/lunaix-os/kernel/process/process.c?ds=sidebyside diff --git a/lunaix-os/kernel/process/process.c b/lunaix-os/kernel/process/process.c index 4e8fa0a..bdd9049 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,14 +153,14 @@ 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))) { - kprint_panic("fail to alloc user stack: %d", status); + if ((status = mem_map(NULL, &mapped, USR_STACK, NULL, ¶m))) { + kprintf(KFATAL "fail to alloc user stack: %d", status); } mapped->region_copied = __stack_copied; @@ -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; @@ -211,15 +212,13 @@ dup_proc() pcb->intr_ctx = __current->intr_ctx; pcb->parent = __current; - memcpy(pcb->fxstate, __current->fxstate, 512); - if (__current->cwd) { pcb->cwd = __current->cwd; vfs_ref_dnode(pcb->cwd); } __copy_fdtable(pcb); - region_copy(&__current->mm, &pcb->mm); + region_copy_mm(&__current->mm, &pcb->mm); /* * store the return value for forked process. @@ -251,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) @@ -263,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); /* @@ -274,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));