From: acevest Date: Mon, 1 Nov 2021 10:53:10 +0000 (+0800) Subject: add kernel_fork X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/migration?a=commitdiff_plain;h=442b488b60a0802a3f35db4d1812d5a510a6772d;p=kernel.git add kernel_fork --- diff --git a/kernel/fork.c b/kernel/fork.c index bb72222..fd3d368 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -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; diff --git a/kernel/init.c b/kernel/init.c index 794abbf..73b8fc6 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -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 *)®s, 0, sizeof(regs)); regs.edx = (unsigned long)entry; - int pid = do_fork(®s, FORK_KRNL); + //int pid = do_fork(®s, FORK_KRNL); + int pid = kernel_fork(); printk("kernel task pid is %d\n", pid); enable_irq(); }