【发布时间】:2019-05-26 21:10:58
【问题描述】:
我正在尝试了解当前宏如何检索进程的 struct task_struct。
我正在尝试了解 x86 架构,在探索内核源代码后,发现以下代码:
#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 */
- DECLARE_PER_CPU 中声明的变量存储在内存中的什么位置。
- 它们是在固定位置还是在 CPU 寄存器中。
- 我还是无法得到,这将如何给task_struct指针
谁能解释一下。感谢您的时间和耐心
【问题讨论】:
标签: c linux process linux-kernel macros