<div dir="ltr"><div><div>Hi,<br><br></div><div>I want to write a new syscall in which
caller process would create kernel thread which shares the process
address space, file descriptor table, parent pid etc. <br>The new kernel thread would be clone of current thread but it would never execute any userspace code.<br><br></div><div>The kernel_thread() function with following arguments would be ideal to achieve this task:<br></div><div>kernel_thread(some_function, some_args, CLONE_FS | CLONE_FILES | CLONE_PARENT)<br></div><div><br></div><div>In latest kernels (v3.1x), this function causes segmentation fault in the user process.<br></div><div>However same code works perfectly in older kernels (v2.6).<br><br></div><div>According to this <a href="https://groups.google.com/forum/#%21searchin/linux.kernel/kernel_thread%28%29/linux.kernel/LPWuY2DMMuA/L2hv1x23YqQJ" target="_blank">link</a>, and this <a href="http://lxr.free-electrons.com/source/arch/x86/kernel/process_64.c?v=3.16#L177" target="_blank">code</a>
(call chain: kernel_thread -> do_fork -> copy_process ->
copy_thread), it looks like only the kernel thread can spawn another
kernel thread. (I tried to set PF_KTHREAD flag in current->flags
before calling kernel_thread function, but the system crashed.)<br><br></div><div>Is there any clean way of creating kernel thread that shares process address space, file descriptor table, parent pid etc?</div><div><br></div><div><br></div>Thanks,<br></div>Shashank Khasare</div>