I am trying to understand how current macro retrieves struct task_struct of the process.
I am trying to understand for x86 architecture, and after exploring kernel source, struck at the following code:
#include <linux/compiler.h>
#include <asm/percpu.h>
#ifndef __ASSEMBLY__
struct task_struct;
DECLARE_PER_CPU(struct task_struct *, current_task);
static __always_inline struct task_struct *get_current(void)
{
return percpu_read_stable(current_task);
}
#define current get_current()
#endif /* __ASSEMBLY__ */
#endif /* _ASM_X86_CURRENT_H */
- Where are the variables declared in DECLARE_PER_CPU stored in memory.
- Are they at fixed location or in CPU Registers.
- I am still unable to get, how this will give the task_struct pointer
Can anyone explain it. Thanks for your time and patience