X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/9b8e0c494de6b447b44454112748f702dffec90d..8c6f505faaa66e18cdca108dca549d4ad806a077:/lunaix-os/kernel/process/process.c diff --git a/lunaix-os/kernel/process/process.c b/lunaix-os/kernel/process/process.c index 1647e10..23ff6a4 100644 --- a/lunaix-os/kernel/process/process.c +++ b/lunaix-os/kernel/process/process.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -134,6 +135,12 @@ __DEFINE_LXSYSCALL2(int, setpgid, pid_t, pid, pid_t, pgid) return 0; } +void +__stack_copied(struct mm_region* region) +{ + mm_index((void**)®ion->proc_vms->stack, region); +} + void init_proc_user_space(struct proc_info* pcb) { @@ -141,18 +148,22 @@ init_proc_user_space(struct proc_info* pcb) /*--- 分配用户栈 ---*/ - struct mm_region* stack_vm; - - stack_vm = region_create_range( - USTACK_END, USTACK_SIZE, REGION_RW | REGION_RSHARED | REGION_ANON); - // 注册用户栈区域 - region_add(&pcb->mm.regions, stack_vm); - - // 预留地址空间,具体物理页将由Page Fault Handler按需分配。 - for (uintptr_t i = PG_ALIGN(USTACK_END); i < USTACK_TOP; i += PG_SIZE) { - vmm_set_mapping(VMS_MOUNT_1, i, 0, PG_ALLOW_USER | PG_WRITE, VMAP_NULL); + struct mm_region* mapped; + struct mmap_param param = { .vms_mnt = VMS_MOUNT_1, + .pvms = &pcb->mm, + .mlen = USTACK_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); } + mapped->region_copied = __stack_copied; + mm_index((void**)&pcb->mm.stack, mapped); + // TODO other uspace initialization stuff vmm_unmount_pd(VMS_MOUNT_1); @@ -194,7 +205,6 @@ pid_t dup_proc() { struct proc_info* pcb = alloc_process(); - pcb->mm.u_heap = __current->mm.u_heap; pcb->intr_ctx = __current->intr_ctx; pcb->parent = __current; @@ -206,7 +216,7 @@ dup_proc() } __copy_fdtable(pcb); - region_copy(&__current->mm.regions, &pcb->mm.regions); + region_copy(&__current->mm, &pcb->mm); setup_proc_mem(pcb, VMS_SELF);