// ntddk.h
PVOID PsGetCurrentThreadTeb();
View the official Windows Driver Kit DDI referenceNo description available.
The PsGetCurrentThreadTeb routine returns the Thread Environment Block (TEB) of the current thread, or NULL. The call must be made in kernel-mode.
A pointer to the thread environment block of the current thread. The TEB should be accessed within a try/catch exception block.
PsGetCurrentThreadTeb returns NULL in the following cases:
While PsGetCurrentThreadTeb can be called at any IRQL without causing a bugcheck, the TEB is not safe to access at DISPATCH_LEVEL or above (it could be paged out). Also, if you're calling at elevated IRQL from the context of an interrupt or DPC, the current thread is whatever happened to be running on the current processor when your interrupt was delivered there. As a result, it is recommended that you call PsGetCurrentThreadTeb from thread context below DISPATCH_LEVEL.
Process and Thread Manager Routines