[SDK:NDK/XDK] Sync NtCurrentTeb() definitions between NDK and PSDK winnt.h (#6542)

The definitions in the NDK inline_ntcurrentteb.h and psfuncs.h files are
synced togther with those of winnt.h (in the winnt_old.h generator file).

See commits c1929445d (r49627) and 925c587c8 (r56318).

IMPORTANT NOTE: The ARM64 definition does not exist yet in our headers!
This commit is contained in:
Hermès Bélusca-Maïto 2024-02-23 22:58:06 +01:00
parent cec7adb97f
commit 352b7f6785
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 47 additions and 37 deletions

View file

@ -1,29 +1,31 @@
#ifndef _INLINE_NT_CURRENTTEB_H_ #ifndef _INLINE_NT_CURRENTTEB_H_
#define _INLINE_NT_CURRENTTEB_H_ #define _INLINE_NT_CURRENTTEB_H_
#ifdef __cplusplus
extern "C" {
#endif
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
{
#if defined(_M_IX86) #if defined(_M_IX86)
FORCEINLINE struct _TEB * NtCurrentTeb(void)
{
return (struct _TEB *)__readfsdword(0x18); return (struct _TEB *)__readfsdword(0x18);
}
#elif defined(_M_ARM)
FORCEINLINE struct _TEB * NtCurrentTeb(void)
{
__debugbreak();
return (struct _TEB *)0;
}
#elif defined(_M_AMD64) #elif defined(_M_AMD64)
FORCEINLINE struct _TEB * NtCurrentTeb(void)
{
return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self)); return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self));
} #elif defined(_M_ARM)
#elif defined(_M_PPC) // return (struct _TEB *)KeGetPcr()->Used_Self;
FORCEINLINE struct _TEB * NtCurrentTeb(void) return (struct _TEB *)(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW);
{ #elif defined (_M_ARM64)
return (struct _TEB *)__readfsdword_winnt(0x18); //UNIMPLEMENTED;
} return 0;
// #elif defined(_M_PPC)
// return (struct _TEB *)_read_teb_dword(0x18);
#else #else
#error Unsupported architecture #error Unsupported architecture
#endif #endif
}
#endif//_INLINE_NT_CURRENTTEB_H_ #ifdef __cplusplus
}
#endif
#endif // _INLINE_NT_CURRENTTEB_H_

View file

@ -420,15 +420,23 @@ NtCreateThread(
FORCEINLINE struct _TEB * NtCurrentTeb(VOID) FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
{ {
#if defined(_M_IX86) #if defined(_M_IX86)
return (PTEB)__readfsdword(0x18); return (struct _TEB *)__readfsdword(0x18);
#elif defined (_M_AMD64) #elif defined (_M_AMD64)
return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self)); return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self));
#elif defined (_M_ARM) #elif defined (_M_ARM)
return (struct _TEB *)KeGetPcr()->Used_Self; // return (struct _TEB *)KeGetPcr()->Used_Self;
return (struct _TEB *)(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW);
#elif defined (_M_ARM64)
//UNIMPLEMENTED;
return 0;
// #elif defined(_M_PPC)
// return (struct _TEB *)_read_teb_dword(0x18);
#else
#error Unsupported architecture
#endif #endif
} }
#else #else
struct _TEB * NtCurrentTeb(void); struct _TEB * NtCurrentTeb(VOID);
#endif #endif
NTSYSCALLAPI NTSYSCALLAPI

View file

@ -4297,7 +4297,7 @@ RtlSecureZeroMemory(_Out_writes_bytes_all_(Length) PVOID Buffer,
} }
#if defined(_M_IX86) #if defined(_M_IX86)
FORCEINLINE struct _TEB * NtCurrentTeb(void) FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
{ {
return (struct _TEB *)__readfsdword(0x18); return (struct _TEB *)__readfsdword(0x18);
} }
@ -4306,17 +4306,17 @@ FORCEINLINE PVOID GetCurrentFiber(VOID)
return (PVOID)(ULONG_PTR)__readfsdword(0x10); return (PVOID)(ULONG_PTR)__readfsdword(0x10);
} }
#elif defined (_M_AMD64) #elif defined (_M_AMD64)
FORCEINLINE struct _TEB * NtCurrentTeb(void) FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
{ {
return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self)); return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self));
} }
FORCEINLINE PVOID GetCurrentFiber(VOID) FORCEINLINE PVOID GetCurrentFiber(VOID)
{ {
#ifdef NONAMELESSUNION #ifdef NONAMELESSUNION
return (PVOID)__readgsqword(FIELD_OFFSET(NT_TIB, DUMMYUNIONNAME.FiberData)); return (PVOID)__readgsqword(FIELD_OFFSET(NT_TIB, DUMMYUNIONNAME.FiberData));
#else #else
return (PVOID)__readgsqword(FIELD_OFFSET(NT_TIB, FiberData)); return (PVOID)__readgsqword(FIELD_OFFSET(NT_TIB, FiberData));
#endif #endif
} }
#elif defined (_M_ARM) #elif defined (_M_ARM)
#define CP15_PMSELR 15, 0, 9, 12, 5 #define CP15_PMSELR 15, 0, 9, 12, 5
@ -4324,20 +4324,20 @@ FORCEINLINE PVOID GetCurrentFiber(VOID)
#define CP15_TPIDRURW 15, 0, 13, 0, 2 #define CP15_TPIDRURW 15, 0, 13, 0, 2
#define CP15_TPIDRURO 15, 0, 13, 0, 3 #define CP15_TPIDRURO 15, 0, 13, 0, 3
#define CP15_TPIDRPRW 15, 0, 13, 0, 4 #define CP15_TPIDRPRW 15, 0, 13, 0, 4
FORCEINLINE struct _TEB * NtCurrentTeb(void) FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
{ {
return (struct _TEB *)(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW); return (struct _TEB *)(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW);
} }
FORCEINLINE PVOID GetCurrentFiber(VOID) FORCEINLINE PVOID GetCurrentFiber(VOID)
{ {
#ifdef NONAMELESSUNION #ifdef NONAMELESSUNION
return ((PNT_TIB )(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW))->DUMMYUNIONNAME.FiberData; return ((PNT_TIB)(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW))->DUMMYUNIONNAME.FiberData;
#else #else
return ((PNT_TIB )(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW))->FiberData; return ((PNT_TIB)(ULONG_PTR)_MoveFromCoprocessor(CP15_TPIDRURW))->FiberData;
#endif #endif
} }
#elif defined (_M_ARM64) #elif defined (_M_ARM64)
FORCEINLINE struct _TEB * NtCurrentTeb(void) FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
{ {
//UNIMPLEMENTED; //UNIMPLEMENTED;
return 0; return 0;
@ -4358,11 +4358,11 @@ FORCEINLINE unsigned long _read_teb_dword(const unsigned long Offset)
: "r7"); : "r7");
return result; return result;
} }
FORCEINLINE struct _TEB * NtCurrentTeb(void) FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
{ {
return (struct _TEB *)_read_teb_dword(0x18); return (struct _TEB *)_read_teb_dword(0x18);
} }
FORCEINLINE PVOID GetCurrentFiber(void) FORCEINLINE PVOID GetCurrentFiber(VOID)
{ {
return _read_teb_dword(0x10); return _read_teb_dword(0x10);
} }
@ -4370,7 +4370,7 @@ FORCEINLINE PVOID GetCurrentFiber(void)
#error Unknown architecture #error Unknown architecture
#endif #endif
FORCEINLINE PVOID GetFiberData(void) FORCEINLINE PVOID GetFiberData(VOID)
{ {
return *((PVOID *)GetCurrentFiber()); return *((PVOID *)GetCurrentFiber());
} }
@ -4397,7 +4397,7 @@ FORCEINLINE PVOID GetFiberData(void)
#if defined(_MSC_VER) #if defined(_MSC_VER)
FORCEINLINE FORCEINLINE
VOID VOID
MemoryBarrier (VOID) MemoryBarrier(VOID)
{ {
LONG Barrier; LONG Barrier;
__asm { xchg Barrier, eax } __asm { xchg Barrier, eax }