Merge branch 'master' into prog-loader
[lunaix-os.git] / lunaix-os / kernel / process / process.c
index 65384d16cc7e7cabe40aaa17217494382df160b0..23ff6a4dcc3e9a24ae115ebb532f4bed10de17bf 100644 (file)
@@ -135,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**)&region->proc_vms->stack, region);
+}
+
 void
 init_proc_user_space(struct proc_info* pcb)
 {
@@ -144,8 +150,8 @@ init_proc_user_space(struct proc_info* pcb)
 
     struct mm_region* mapped;
     struct mmap_param param = { .vms_mnt = VMS_MOUNT_1,
-                                .regions = &pcb->mm.regions,
-                                .length = USTACK_SIZE,
+                                .pvms = &pcb->mm,
+                                .mlen = USTACK_SIZE,
                                 .proct = PROT_READ | PROT_WRITE,
                                 .flags = MAP_ANON | MAP_PRIVATE | MAP_FIXED,
                                 .type = REGION_TYPE_STACK };
@@ -155,6 +161,9 @@ init_proc_user_space(struct proc_info* pcb)
         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);
@@ -196,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;
 
@@ -208,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);