I learned thread_info is stored in the bottom of stack.
While looking in the source code of kernel, I'm trying to understand how to get current thread_info in linux kernel?
Source code below is 13bits masking of current_stack_pointer.
This is what I cannot get it. I don't understand that the position of thread_info changes. Why is it current stack pointer instead of start of stack?
Please help me to understand this code
/*
* how to get the current stack pointer in C
*/
register unsigned long current_stack_pointer asm ("sp");
/*
* how to get the thread information struct from C
*/
static inline struct thread_info *current_thread_info(void) __attribute_const__;
static inline struct thread_info *current_thread_info(void)
{
return (struct thread_info *)
(current_stack_pointer & ~(THREAD_SIZE - 1));
}
include/asm/current.hand#define current. On x86, we have#define current get_current()but on IBM s390, we have#define current ((struct task_struct *const)S390_lowcore.current_task). So, be careful with doing it by riffing off the stack pointer. - Craig Estey