I am trying to locate the address of task_struct
of a thread. First of all, I need to get the address of task_struct
of the init_task
, then I iterate the whole list and finally get the task_struct
of a specific thread. The task_struct
of the init_task
can be easily obtained from /proc/kallsyms
by the command
grep "\<init_task\>" /proc/kallsyms
.
This worked when I use older kernel version (3.12). But when I switched to newer version (4.5), this idea failed at the very beginning. Because the symbol init_task
disappears from /proc/kallsyms
. But when I checked the source code, I can see that the symbol init_task
is exported (http://lxr.free-electrons.com/source/init/init_task.c?v=4.5#L18). Why it doesn't show up in the /proc/kallsyms
? Or is there any other approach to get the address of init_task
from user space programs?
CONFIG_ARCH_INIT_TASK
is set toy
in your kernel.config
.CONFIG_ARCH_INIT_TASK
option. I also checked the.config
file of the old kernel version (3.12) which hasinit_task
symbol exported, there is also no such option. It seems that the problem is not because of the.config
file -:((.config
for new kernel:CONFIG_UNUSED_SYMBOLS
andTRIM_UNUSED_KSYMS
? It's unlikely some of them is enabled, but if yes -- it can be the cause.CONFIG_UNUSED_SYMBOLS=y
, but noTRIM_UNUSED_KSYMS
option was found. To my understanding, enabling theCONFIG_UNUSED_SYMBOLS
option will export unused symbols, that means if theinit_task
is not used, it will be exported anyway. So this doesn't seem to be the cause. Or am I misunderstanding ?init_task()
symbol: 1. IfCONFIG_ARCH_INIT_TASK=y
2.CONFIG_TRIM_UNUSED_KSYMS=y
and symbol is not used in kernel. Probably there is some another mechanism in place that strips unused symbols out, but I'm not aware of it.