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.
size() method in Java is used to get the size of the Stack or the number of elements present in the Stack. Parameters: The method does not take any parameter. Return Value: The method returns the size or the number of elements present in the Stack.
Thread or fiber creation fails if there is not enough memory to reserve or commit the number of bytes requested. The default stack reservation size used by the linker is 1 MB.
In Visual Studio the default stack size is 1 MB i think, so with a recursion depth of 10,000 each stack frame can be at most ~100 bytes which should be sufficient for a DFS algorithm. Most compilers including Visual Studio let you specify the stack size.
For ARM64, x86, and x64 machines, the default stack size is 1 MB. The commit value is subject to interpretation by the operating system. In WindowsRT, it specifies the amount of physical memory to allocate at a time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With