Can anyone help me interpret this simple disassembly from WinDbg?

前端 未结 5 1126
野性不改
野性不改 2020-12-23 08:34

I got the following simple C++ code:

#include 
int main(void)
{
    ::printf(\"\\nHello,debugger!\\n\");
}

And from WinDbg,

5条回答
  •  一个人的身影
    2020-12-23 09:14

    The 40 bytes is the worst case stack allocation for any called or subsequently called function. This is explained in glorious detail here.

    What is this space reserved on the top of the stack for? First, space is created for any local variables. In this case, FunctionWith6Params() has two. However, those two local variables only account for 0x10 bytes. What’s the deal with the rest of the space created on the top of the stack?
    On the x64 platform, when code prepares the stack for calling another function, it does not use push instructions to put the parameters on the stack as is commonly the case in x86 code. Instead, the stack pointer typically remains fixed for a particular function. The compiler looks at all of the functions the code in the current function calls, it finds the one with the maximum number of parameters, and then creates enough space on the stack to accommodate those parameters. In this example, FunctionWith6Params() calls printf() passing it 8 parameters. Since that is the called function with the maximum number of parameters, the compiler creates 8 slots on the stack. The top four slots on the stack will then be the home space used by any functions FunctionWith6Params() calls.

提交回复
热议问题