【问题标题】:Frame pointer, epb, and return address帧指针、epb 和返回地址
【发布时间】:2011-05-24 12:00:05
【问题描述】:

以下图片来自维基百科entry调用堆栈,有些东西我完全不明白:

我认为存储在 ebp 寄存器中的帧指针在 prologue* 中是这样初始化的:

push ebp  ; Preserve current frame pointer 
mov ebp, esp ; Create new frame pointer pointing to current stack top 
sub esp, 20 ; allocate 20 bytes worth of locals on stack. 

如果是这样,那么图像中的帧指针不应该指向返回地址之后,它应该是前一个帧指针地址,然后是返回地址吗?我错过了什么?

谢谢!

*取自:What is exactly the base pointer and stack pointer? To what do they point?

【问题讨论】:

    标签: assembly windbg callstack calling-convention


    【解决方案1】:

    是的,你是对的,帧指针指向一个地址,在返回地址之前存储前一个帧指针。正确的图片应该是

                   | locals
                   +---------
    frame pointer->| prev frame pointer
                   +--------
                   | return address
                   +--------
    

    【讨论】:

    • 谢谢 - 这是否意味着 esp 实际上不是指向堆栈的顶部,而是指向堆栈中的最后一项?
    • @SpeksETC : 最后一项在栈顶
    【解决方案2】:

    当函数被调用时。返回地址被压入堆栈,堆栈指针现在指向返回地址。 这是函数内部发生的事情:

    push ebp  ; Push the ebp; The ebp address will pushed on stack and sp will be decremented
    mov ebp, esp ;  EBP will now point the same as ESP which is previous value of EBP
    sub esp, 20 ;    ESP will be subtracted further to create frame for local variables
    

    结果是: EBP 指向 EBP 的先前值。 ESP 指向 ESP 的另外 20 个字节。这 20 个字节将用于本地变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-02
      • 2016-03-16
      • 1970-01-01
      • 1970-01-01
      • 2016-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多