小编sil*_*sse的帖子

在Linux内核中使用修饰符"P"和约束"p"超过"m"的gcc内联汇编

我正在阅读Linux内核源代码(3.12.5 x86_64)以了解如何处理进程描述符.

我发现获取当前进程描述符我可以使用current_thread_info()函数,其实现如下:

static inline struct thread_info *current_thread_info(void)
{
    struct thread_info *ti;
    ti = (void *)(this_cpu_read_stable(kernel_stack) +
         KERNEL_STACK_OFFSET - THREAD_SIZE);
    return ti;
}
Run Code Online (Sandbox Code Playgroud)

然后我调查了this_cpu_read_stable():

#define this_cpu_read_stable(var)       percpu_from_op("mov", var, "p" (&(var)))

#define percpu_from_op(op, var, constraint) \
({ \
typeof(var) pfo_ret__; \
switch (sizeof(var)) { \
...
case 8: \
    asm(op "q "__percpu_arg(1)",%0" \
    : "=r" (pfo_ret__) \
    : constraint); \
    break; \
default: __bad_percpu_size(); \
} \
pfo_ret__; \
})

#define __percpu_arg(x)         __percpu_prefix "%P" #x

#ifdef CONFIG_SMP
#define __percpu_prefix …
Run Code Online (Sandbox Code Playgroud)

c assembly gcc linux-kernel

10
推荐指数
1
解决办法
1392
查看次数

标签 统计

assembly ×1

c ×1

gcc ×1

linux-kernel ×1