Reputation: 4946
On a call stack, we have a frame pointer which gives us the location of the arguments to a procedure and the address of a pointer to the previous frame. We also have a return address. Why it the return address necessary? Could we not just follow the frame pointers back up the stack, popping off the stack frames as we went? Is the return address just an optimisation?
Upvotes: 2
Views: 9193
Reputation: 91
return address refers to address of the code segment or instruction whose function call has created that stack.It is very important data as per vulnerabilities, as in case of buffer overrun,attackers get address space which can lead to compromising state
Upvotes: 2
Reputation: 26376
The frame points to storage space for parameters and local variables. You can bring that in the original state, but that won't restore the instruction pointer, the old value of which was lost when a call to a function was made.
The return address is just that, the saved instruction pointer.
Upvotes: 0
Reputation: 262684
The return address does not point to the previous stack frame, it points into the code segment to the next instruction in the calling method.
Upvotes: 12