大佬教程收集整理的这篇文章主要介绍了linux – 了解从进程内核堆栈获取task_struct指针,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的问题是:
>据我所知,如果我们将十进制值表示为一组位,那么集合中只有一个最低有效位,不是吗?
>什么是神奇的数字13?
对于将阅读本主题的人,我所提出的问题可以得出结论,即作者不能正确理解内存分配和管理的过程.好吧,这可能是正确的,因为在我看来,我可以将为堆栈分配的内存表示为带满位(或字节).所有这些字节都可以通过特定的存储器地址访问,表示为一些十进制值.堆栈的原点是最低的内存地址,堆栈的fin是内存地址的最高值.但是,我们如何才能获得指向位于堆栈末端的thread_info结构的指针,只需通过屏蔽13个位于堆栈指针的ARBITRARY的最低有效位(如果我理解正确的话,我们屏蔽掉了堆栈指针ADDRESS表示为十进制值).
26 struct thread_info { 27 struct task_struct *task; /* main task structure */ 28 struct exec_domain *exec_domain; /* execution domain */ 29 __u32 flags; /* low level flags */ 30 __u32 status; /* thread synchronous flags */ 31 __u32 cpu; /* current cpu */ 32 int preempt_count; /* 0 => preemptable,33 <0 => BUG */ 34 mm_segment_t addr_limit; 35 struct restarT_Block restarT_Block; 36 void __user *sysenter_return; 37 #ifdef CONfig_X86_32 38 unsigned long prevIoUs_esp; /* ESP of the prevIoUs stack in 39 case of nested (IRQ) stacks 40 */ 41 __u8 supervisor_stack[0]; 42 #endif 43 unsigned int sig_on_uaccess_error:1; 44 unsigned int uaccess_err:1; /* uaccess Failed */ 45 };
因此,要获取task_struct,您需要从ASM代码获取带有GET_THREAD_INFO的thread_info指针:
183 /* how to get the thread information struct from ASM */ 184 #define GET_THREAD_INFO(reg) \ 185 movl $-THREAD_SIZE,reg; \ 186 andl %esp,reg
…或者使用C代码中的current_thread_info:
174 /* how to get the thread information struct from C */ 175 static inline struct thread_info *current_thread_info(void) 176 { 177 return (struct thread_info *) 178 (current_stack_pointer & ~(THREAD_SIZE - 1)); 179 }
注意,对于x86_32和x86_64,定义为(PAGE_SIZE<<< THREAD_SIZE_ORDER)和THREAD_SIZE_ORDER的THREAD_SIZE等于1,因此THREAD_SIZE导致8192(2 ^ 13或1 <<<<<<< 13).
以上是大佬教程为你收集整理的linux – 了解从进程内核堆栈获取task_struct指针全部内容,希望文章能够帮你解决linux – 了解从进程内核堆栈获取task_struct指针所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。