Win32 入口点是否必须保留任何寄存器值(被调用者保存的寄存器)?
Does the Win32 entry point have to preserve any registers values (callee-saved registers)?
我正在 NASM 中编写程序,我不想 link 使用 CRT,因此我将指定入口点(这将是 Win32 入口点) .这是程序源码:
global _myEntryPoint
section .text
_myEntryPoint:
mov eax, 12345
下面是我对Win32入口点的了解(如有错误请指正):
- Win32 入口点不像正常值那样return
函数确实(退出我必须调用的 Win32 入口点
ExitProcess()
).
- Win32 入口点不接受任何参数。
现在不知道的是:
- Win32 入口点是否必须保留任何寄存器值(被调用者保存的寄存器)?我认为答案是 否 ,因为当 Win32 入口点退出时,它会终止进程,而不是 return 执行期望保留某些寄存器值的函数。
如, you shouldn't return from the Win32 entry point at all, in which case there is obviously no need for you to preserve any registers. The way your question is phrased vaguely suggests that you were worried that you night need to restore registers before calling ExitProcess
but this is definitely not the case; calling ExitProcess
does not cause you to return from the entry point, it just stops running your code. (See also here for an update, and this may also be of interest所述。)
您是否应该从入口点忽略该建议和 return,好吧,实际上答案是相同的:您实际上不需要保留任何寄存器。然而,据我所知,这种行为没有记录在案,因此如果您想谨慎行事,您可以选择严格遵守 stdcall
约定。
我正在 NASM 中编写程序,我不想 link 使用 CRT,因此我将指定入口点(这将是 Win32 入口点) .这是程序源码:
global _myEntryPoint
section .text
_myEntryPoint:
mov eax, 12345
下面是我对Win32入口点的了解(如有错误请指正):
- Win32 入口点不像正常值那样return
函数确实(退出我必须调用的 Win32 入口点
ExitProcess()
). - Win32 入口点不接受任何参数。
现在不知道的是:
- Win32 入口点是否必须保留任何寄存器值(被调用者保存的寄存器)?我认为答案是 否 ,因为当 Win32 入口点退出时,它会终止进程,而不是 return 执行期望保留某些寄存器值的函数。
如ExitProcess
but this is definitely not the case; calling ExitProcess
does not cause you to return from the entry point, it just stops running your code. (See also here for an update, and this may also be of interest所述。)
您是否应该从入口点忽略该建议和 return,好吧,实际上答案是相同的:您实际上不需要保留任何寄存器。然而,据我所知,这种行为没有记录在案,因此如果您想谨慎行事,您可以选择严格遵守 stdcall
约定。