Stack alignment in x64 assembly

前端 未结 2 1636
小鲜肉
小鲜肉 2020-12-11 17:19

how is the value of 28h (decimal 40) that is subtracted from rsp calculated in the following:

    option casemap:none

    includel         


        
相关标签:
2条回答
  • 2020-12-11 17:42

    I had stumbled upon the same case. Tried lurker answer and was fine. Later added some code(by the way, i'm using my own compiler) and got problems.

    The problem was that the shadow space address was ending with 8 on the stack. When the shadow space address was ending with 0 ("Stack aligned on 16 bytes"), the call was OK. Adding 8 bytes will crash the app in my last case.

    0 讨论(0)
  • 2020-12-11 17:52

    I believe it's because before main is called, the stack is aligned. Then after the call, the act of the call was to push an 8-byte pointer (address of the caller) onto the stack. So at the beginning of main, it's 8 bytes off of the 16-byte alignment. Therefore, instead of 20h you need 28h, bringing the actual total to 28h + 8h (from the call) or 30h. Alignment. :)

    0 讨论(0)
提交回复
热议问题