]> Zhao Yanbai Git Server - kernel.git/commitdiff
add kernel_fork
authoracevest <zhaoyanbai@126.com>
Mon, 1 Nov 2021 10:53:10 +0000 (18:53 +0800)
committeracevest <zhaoyanbai@126.com>
Wed, 3 Nov 2021 02:45:46 +0000 (10:45 +0800)
kernel/fork.c
kernel/init.c

index bb72222fab6780ce9f8d0e9ce199834228e07550..fd3d36832068b3898fa5295639a992cd861729ca 100644 (file)
@@ -22,6 +22,7 @@ extern void ret_from_fork_user();
 extern void ret_from_fork_krnl();
 extern pid_t get_next_pid();
 extern list_head_t all_tasks;
+
 int do_fork(pt_regs_t *regs, unsigned long flags)
 {
     task_union *tsk;
index 794abbf2ee06e345c57b62feec4e4e4ae69a82d4..73b8fc6b5d843f1bced0abd054ec6e387a750e6a 100644 (file)
@@ -49,12 +49,30 @@ void init_task_entry()
     }
 }
 
+int kernel_fork()
+{
+    int pid = 0;
+
+    pt_regs_t *regs = ((pt_regs_t *)(TASK_SIZE + ((unsigned long)current))) - 1;
+    unsigned long *pedx = &(regs->edx);
+
+    asm volatile(
+        "movl $1f, %[pedx];"
+        "call do_fork;"
+        "1:"
+        : "=a"(pid)
+        : [pedx] "m"(pedx));
+
+    return pid;
+}
+
 void kernel_task(void *entry)
 {
     pt_regs_t regs;
     memset((void *)&regs, 0, sizeof(regs));
     regs.edx = (unsigned long)entry;
-    int pid = do_fork(&regs, FORK_KRNL);
+    //int pid = do_fork(&regs, FORK_KRNL);
+    int pid = kernel_fork();
     printk("kernel task pid is %d\n", pid);
     enable_irq();
 }