Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identifying if an address belongs to heap or stack or registers

I have a pointer available with me to a C/C++ variable. Is it possible to exactly make out which segment of the memory this variable belongs to ? If yes, how ?

Note: I just have the address of this variable, no further information if the variable is local/global etc.

like image 926
Amit Tomar Avatar asked Aug 06 '12 11:08

Amit Tomar


People also ask

How do I know if my address is stack or heap?

All it does is extend the data segment, which begins at a some address and grows upwards. All allocations will be greater than or equal to this starting address. On the other hand, the stack starts at the "top" of memory and grows downwards towards the current end of the heap.

Are addresses stored on the stack?

The address of a local variable isn't stored anywhere, unless you have a pointer pointing to the local variable. The local variables themselves are typically stored on the stack on most modern systems.

Is there a difference between the stack and the heap?

Heap memory is used by all the parts of the application whereas stack memory is used only by one thread of execution. Whenever an object is created, it's always stored in the Heap space and stack memory contains the reference to it.

What memory address is in the stack?

A stack frame is identified by a memory address in a register called the base-pointer, EBP (this is specific to IA-32 architecture, but other CPU's might have a similar register). The EBP contains the base of the current stack frame, that is, the highest numbered address in the stack frame.


1 Answers

Find out whether your architecture has pointers to your heap or stack region. Usually there are some stackpointers or framepointers..

Then compare your actual address to those addresses and decide where they belong.

like image 73
duedl0r Avatar answered Sep 28 '22 17:09

duedl0r