您的位置:首页 > 其它

How To Create a kernel thread

2016-03-05 00:07 441 查看
kernel_thread() -->
do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, pregs, 0, NULL, NULL);


The CLONE_VM flag avoids the duplication of the page tables of the calling process: this duplication would be a waste of time and memory, because the new kernel thread will not access the User Mode address space anyway.

The CLONE_UNTRACED flag ensures that no process will be able to trace the new kernel thread, even if the calling process is being traced.

The kernel_thread() function builds up the Kernel Mode Stack area ,so that:

• The ebx and edx registers will be set by copy_thread() to the values of the parameters fn and arg, respectively.

• The eip register will be set to the address of the following assembly language fragment:

movl %edx,%eax
pushl %edx
call *%ebx
pushl %eax
call do_exit


Therefore, the new kernel thread starts by executing the fn(arg) function. If this function terminates, the kernel thread executes the _exit() system call passing to it the return value of fn().

From:《Understanding The Linux Kernel》3rd Edition.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: