views:

36

answers:

1

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  A: 

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).

Sergius