amd64下基于per_cpu变量current_task获取task_struct
amd64下基于per_cpu变量current_task获取task_struct
获取current_task地址
1
nm vmlinux | grep current_task
获取task_struct指针
获取当前正在运行的cpu所属线程:
1
info threads
从上图看到有8个cpu,可以改动qemu虚拟化时
-smp 8参数调整cpu个数。1
(struct task_struct*)(*(unsigned long*)((char*)__per_cpu_offset[4] + 0x15cc0))__per_cpu_offset[4]中的下标4需要与info threads对应上。0x15cc0为nm vmlinux | grep current_task获取的current_task地址。获取进程号
1
p ((struct task_struct*)(*(unsigned long*)((char*)__per_cpu_offset[4] + 0x15cc0)))->pid获取进程名
1
p ((struct task_struct*)(*(unsigned long*)((char*)__per_cpu_offset[4] + 0x15cc0)))->comm
如果上述
__per_cpu_offset[4]下标不对,获取的都是内核0号idle进程。
More
amd64下基于per_cpu变量current_task获取task_struct
https://realwujing.github.io/linux/kernel/kvm/amd64下基于per_cpu变量current_task获取task_struct/