Benny
Benny

Reputation: 627

How to get stack size and stack limit of any thread using Win32 API

Is it possible to obtain the size and limit of the stack of ANY thread using the Win32 API? I know that this is possible for the current thread in the following way:

NT_TIB *tib = (NT_TIB*)NtCurrentTeb();
DWORD stackBase = (DWORD)tib->StackBase;
DWORD stackLimit = (DWORD) tib->StackLimit;

However, I haven't found a Win32 API function that returns the NT_TIB structure for any given thread HANDLE or TID as input parameter.

Upvotes: 7

Views: 4129

Answers (1)

Igor Skochinsky
Igor Skochinsky

Reputation: 25268

If you're debugging the process, you can get the TIB/TEB address from the lpThreadLocalBase field in the CREATE_THREAD_DEBUG_INFO structure.

Otherwise you'll have to rely on the semi-documented NtQueryInformationThread API. If you use the ThreadBasicInformation category, the returned THREAD_BASIC_INFORMATION struct has a TebBaseAddress field.

Upvotes: 5

Related Questions