I always have a question about how to calculate the stretch of the stack. For example, when I have more than 8 parameters in arm64, he actually uses the area of my previous function call stack. After BL enters the function, he uses SP to add back to get the parameters, which is equivalent to crossing a stack. How can he avoid polluting the previous stack in this case? Thank you for your answer
Asked
Active
Viewed 43 times
1
-
2stack args are owned by the callee, not part of the caller's stack frame even though they were pushed by the caller. Some old calling conventions (for ISAs like x86) only ever used stack args, not registers. Better calling conventions only fall back to stack args if they run out of registers, but the same principle applies: it's not the caller's stack frame. e.g. diagram in [How exactly does the callstack work?](https://stackoverflow.com/a/23981489) – Peter Cordes Apr 29 '21 at 09:44
1 Answers
0
You are correct: the function arguments which do not fit in registers will be pushed onto the stack before calling your function. Therefore, they will be at addresses with positive offsets from SP
on entry to your function, and I can see why you might be concerned that it is not safe to access this memory. However, this memory is in fact "yours".
The ARM Procedure Call Standard section 6.4.2 states "A callee is permitted to modify any stack space used for receiving parameter values from the caller". So, there is no need to worry. The caller is expecting you to access this memory, and even to modify it if you want, and nothing will break if you do.

apt1002
- 969
- 6
- 15