1 #ifndef _INLINE_NT_CURRENTTEB_H_
2 #define _INLINE_NT_CURRENTTEB_H_
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
9 {
10 #if defined(_M_IX86)
11     return (struct _TEB *)__readfsdword(0x18);
12 #elif defined(_M_AMD64)
13     return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self));
14 #elif defined(_M_ARM)
15     // return (struct _TEB *)KeGetPcr()->Used_Self;
16     return (struct _TEB *)(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW);
17 #elif defined (_M_ARM64)
18     //UNIMPLEMENTED;
19     return 0;
20 // #elif defined(_M_PPC)
21 //     return (struct _TEB *)_read_teb_dword(0x18);
22 #else
23 #error Unsupported architecture
24 #endif
25 }
26 
27 #ifdef __cplusplus
28 }
29 #endif
30 
31 #endif // _INLINE_NT_CURRENTTEB_H_
32