Zoey
Zoey

Reputation: 175

Is it valid for the Stack Pointer and Frame pointer to point to the same address in ARM 64?

I am having a bit of trouble understanding how stack frames work in ARM. It is my current understanding that a stack frame is region of memory between the Stack Pointer and the Frame Pointer, and that this is the space programs store information in. However, a program I am debugging has both the stack pointer and frame pointer, pointing to the same memory address.

Does anyone know if this is a valid state? I haven't been able to find any documentation on this condition, I'm wondering if anyone else would know how the computer handles this kind of condition.

Upvotes: 3

Views: 2583

Answers (1)

user3124812
user3124812

Reputation: 1986

I think you want to look on Procedure Call Standard for the Arm 64-bit Architecture

In section 6.2.3 there is

Conforming code shall construct a linked list of stack-frames. Each frame shall link to the frame of its caller by means of a frame record of two 64-bit values on the stack (independent of the data model). The frame record for the innermost frame (belonging to the most recent routine invocation) shall be pointed to by the Frame Pointer register (FP). The lowest addressed double-word shall point to the previous frame record and the highest addressed double-word shall contain the value passed in LR on entry to the current function.

So if function uses stack to pass arguments to a callee function or makes 'dynamic allocations', SP would not be same as FP. Otherwise addresses in SP and FP are same.

PS: this document is very stingy on details, imho. I'd appreciate being corrected if I got this specification wrong

Frame Pointer Scheme

Upvotes: 2

Related Questions