Getting the size of the callstack

2019-04-09 23:07发布

问题:

Is there a way to get the size of the callstack (in bytes) in C++?
Or at least the bottom address of it (and then I can subtract it from the ESP register?

回答1:

You can try using VirtualQuery twice.

The first time you can use the address of any value on the stack to get the base address and size (in bytes) of the committed stack space.

Subtract the size from the base address and call VirtualQuery again. This way you get the space reserved for the stack.

Adding the two sizes you obtain the total stack size.



回答2:

StackWalk64()

http://msdn.microsoft.com/en-us/library/ms680650