Kernel threads basically executes a function. They are created using the kernel_thread()
function which receives the address of the function to execute, the arguments to that function and some clone flags as arguments.
This function essentially invokes a common do_fork()
passing it the address of the Kernel Mode stack where copy_thread()
will find the initial values of the CPU registers for the kernel thread.
Basically kernel_thread()
builds the stack in a way that:
ebx
andedx
register will be set bycopy_thread()
to the valuesfn
andarg
eip
will be set to a small routine that will load the arguments andcall fn
This way the new kernel thread starts executing fn(arg)
.
As you can see, a kernel thread knows about what code to execute by the address of fn
. This function normally is already defined somewhere inside the kernel, by setting eip
to point there, this way the kernel thread knows the instructions to execute. No need for text segment
because there's no need to map an executable file to a memory region.