Official way to get the Thread Information/Environment Block (TIB/TEB)
winapi, windows, windows-runtime
Solution
The macro `NtCurrentTeb()` is available in `winnt.h` for all supported architectures, including ARM (Windows RT):
#if defined(_M_ARM) && !defined(__midl) && !defined(_M_CEE_PURE)
__forceinline
struct _TEB *
NtCurrentTeb (
VOID
)
{
return (struct _TEB *)(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW);
}
Problem
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. But that only works on Intel CPUs, where the FS register exists in the first place. Now I wanna get to the TIB on an ARM-based Windows system (Windows Phone and maybe Windows RT). Is there an API for that, please? 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