Stack and Stack Base Address

血红的双手。 提交于 2019-12-09 23:18:01

问题


In the MEMORY_BASIC_INFORMATION structure one finds two PVOID variables, called BaseAddress and AllocationBaserespectively.

I'm reading a book on Threading and its going over how to get the stackspace left on the stack in quite some detail, however there's something I'm not sure I understand correctly.

The BaseAddress in the structure mentioned above, does it point to the highest address in the current thread stack or the lowest address? Since the stack grows downwards, the lowest would be at the top and the highest at the bottom.

What exactly is the difference between the AllocationBase and BaseAddress field? I don't find the MSDN documentation very explanatory, so I'm hoping someone can clarify a bit more?

In my book it also says that the 'AllocationBase' address is the same as the 'DeallocationStack' field in the TEB structure, which it says points to the end of the stack, which I thought was the highest address, however since its BASE, I'm guessing it should be the lowest address, as the stack grows downward. So I'm kind of confused as to what's what?

Per this page, 'DeallocationStack' is: The maximum stack size is stored in the field DeallocationStack

Can someone help me understand my confusion?


回答1:


In MEMORY_BASIC_INFORMATION structure:

  • BaseAddress - the address of the queried memory page ( VirtualQuery(LPCVOID lpAddress,... ).
  • AllocationBase - the beginning of the allocated memory block. It is used for deallocation. BaseAddress >= AllocationBase.

If you are querying stack then AllocationBase will be the lowest address of the stack (the stack top).



来源:https://stackoverflow.com/questions/3171475/stack-and-stack-base-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!