简体   繁体   English

获取线程信息/环境块(TIB / TEB)的官方方式

[英]Official way to get the Thread Information/Environment Block (TIB/TEB)

In Windows, it's long been common, if undocumented, knowledge that the Thread Information Block (TIB) of the current thread can be found at FS:0. 在Windows中,长期以来很常见的是,如果没有记录,可以在FS:0找到当前线程的线程信息块(TIB)。 But that only works on Intel CPUs, where the FS register exists in the first place. 但这仅适用于首先存在FS寄存器的Intel CPU。 Now I wanna get to the TIB on an ARM-based Windows system (Windows Phone and maybe Windows RT). 现在我想在基于ARM的Windows系统(Windows Phone和Windows RT)上访问TIB。 Is there an API for that, please? 请问有API吗?

EDIT: I want to get the thread stack base for crash reporting purposes. 编辑:我想获得崩溃报告的线程堆栈基础。

Information about TIB/TEB: http://www.microsoft.com/msj/archive/S2CE.aspx 有关TIB / TEB的信息: http//www.microsoft.com/msj/archive/S2CE.aspx

The macro NtCurrentTeb() is available in winnt.h for all supported architectures, including ARM (Windows RT): 对于所有支持的体系结构,包括ARM(Windows RT), winnt.h中都提供了宏NtCurrentTeb() ):

#if defined(_M_ARM) && !defined(__midl) && !defined(_M_CEE_PURE)

__forceinline
struct _TEB *
NtCurrentTeb (
    VOID
    )
{
    return (struct _TEB *)(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW);
}

要回答您发布的问题,您可以使用NtQueryInformationThread()来检索THREAD_BASIC_INFORMATION结构,该结构包含指向其TebBaseAddress成员中线程的TIB的指针。

Igor nailed it. 伊戈尔钉了它。 But FYI, in ARM assembly it goes like this: 但仅供参考,在ARM组装中,它是这样的:

mrc p15, 0, r12, c13, c0, 2 ; r12 now points at TEB/TIB
ldr r12, [r12, #4] ; r12 now holds stack base

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM