在 ppc64 上相当于 X64_64 的 arch_prctl(ARCH_GET_FS, &addr)
Equivalent of X64_64's arch_prctl(ARCH_GET_FS, &addr) on ppc64
我有一个 X86_64 代码可以检索指向线程状态的指针:
uintptr_t addr;
arch_prctl(ARCH_GET_FS, &addr);
正如我在 ABI, I guess this is what the r13
is for. I implemented the following code that I expect to behave the same as arch_prctl 上看到的:
uintptr_t addr;
__asm__ ("\tmr %0, 13" : "=r" (addr));
有这么简单吗?有没有更好的方法?
在 ppc64le 机器上使用 debian 8.1
我不清楚你真正想做什么。
但是如果你想要线程指针,r13 是 ppc64 和 ppc64le 上的正确寄存器,而 r2 是 ppc 上的正确寄存器。
您仍然需要注意如何访问线程本地存储中的字段,因为它们是特定于 ABI 的。
PPC64 ELF V2 ABI 中的第 3.7.2 章将为您提供有关如何访问 TLS 中某些字段的更多详细信息。
如果您更喜欢阅读一些代码,this file 是真正发生魔法的地方。
我有一个 X86_64 代码可以检索指向线程状态的指针:
uintptr_t addr;
arch_prctl(ARCH_GET_FS, &addr);
正如我在 ABI, I guess this is what the r13
is for. I implemented the following code that I expect to behave the same as arch_prctl 上看到的:
uintptr_t addr;
__asm__ ("\tmr %0, 13" : "=r" (addr));
有这么简单吗?有没有更好的方法?
在 ppc64le 机器上使用 debian 8.1
我不清楚你真正想做什么。
但是如果你想要线程指针,r13 是 ppc64 和 ppc64le 上的正确寄存器,而 r2 是 ppc 上的正确寄存器。 您仍然需要注意如何访问线程本地存储中的字段,因为它们是特定于 ABI 的。
PPC64 ELF V2 ABI 中的第 3.7.2 章将为您提供有关如何访问 TLS 中某些字段的更多详细信息。 如果您更喜欢阅读一些代码,this file 是真正发生魔法的地方。