【发布时间】:2012-09-25 08:25:29
【问题描述】:
我的一个朋友问我这个问题,我不知道这个函数的含义。也许就像他们上面的注释/* sign-extend to 32 bits */。但我想知道函数如何实现角色“符号扩展”的细节到 32 位”。
来自 Linux 内核的函数。谢谢大家。
就像@unwind 说的,函数的完整定义是这样的:
/* Convert a prel31 symbol to an absolute address */
#define prel31_to_addr(ptr) \
({ \
/* sign-extend to 32 bits */ \
long offset = (((long)*(ptr)) << 1) >> 1; \
(unsigned long)(ptr) + offset; \
})
它会在函数中使用:
int __init unwind_init(void)
{
struct unwind_idx *idx;
/* Convert the symbol addresses to absolute values */
for (idx = __start_unwind_idx; idx < __stop_unwind_idx; idx++)
idx->addr = prel31_to_addr(&idx->addr);
pr_debug("unwind: ARM stack unwinding initialised\n");
return 0;
}
【问题讨论】:
-
不是函数,是宏。而宏定义上面的注释实际上是说:/*将prel31符号转换为绝对地址*/,这是ARM架构特有的东西
-
thx,请牢记“特定于 ARM 架构”?