Win32入口点是否必须保留任何寄存器值(被调用者保存的寄存器)? [英] Does the Win32 entry point have to preserve any registers values (callee-saved registers)?
问题描述
我正在用NASM编写程序,并且不想将其与CRT链接,因此我将指定入口点(将是Win32入口点).这是程序源代码:
I am writing a program in NASM, and I do not want to link it with the CRT, and so I will specify the entry point (which will be the Win32 entry point). This is the program source code:
global _myEntryPoint
section .text
_myEntryPoint:
mov eax, 12345
现在这是我对Win32入口点的了解(如果我错了,请纠正我):
Now this is what I know about the Win32 entry point (please correct me if I am wrong):
- Win32入口点不返回正常值
函数确实(要退出Win32入口点,我必须调用
ExitProcess()
). - Win32入口点不带任何参数.
- The Win32 entry point does not return a value like a normal
function does (to exit the Win32 entry point I have to call
ExitProcess()
). - The Win32 entry point does not take any arguments.
现在我不知道的是以下内容:
Now what I don't know is the following:
- Win32入口点是否必须保留任何寄存器值(被调用者保存的寄存器)?我认为答案是 No ,因为当Win32入口点退出时,它将终止进程,并且不会将执行返回给希望保留某些寄存器值的函数.
- Does the Win32 entry point have to preserve any registers values (callee-saved registers)? I think the answer is No, since when the Win32 entry point exits, it terminates the process and not return execution to a function that expects some registers values to be preserved.
推荐答案
如我对拟议副本的回答中所述,您根本不应该从Win32入口点返回,在这种情况下,显然不需要保留任何寄存器.问题的模棱两可的表达方式暗示您担心您晚上需要在调用ExitProcess
之前恢复寄存器,但这绝对不是这种情况.调用ExitProcess
不会导致您从入口点它只是停止运行您的代码. (另请参见此处以获得更新,以及这也可能很有趣.)
As described in my answer to the proposed duplicate, 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.)
您还是应该忽略该建议并从入口点返回,实际上,答案是相同的:您实际上不需要保留任何寄存器.据我所知,这种行为并未得到记录,因此,如果您要谨慎,可以选择严格遵循stdcall
约定.
Should you ignore that advice and return from the entry point anyway, well, in practice the answer is the same: you don't actually need to have preserved any registers. To the best of my knowledge this behaviour is not documented, however, so if you wanted to be cautious you might choose to strictly follow the stdcall
convention.
这篇关于Win32入口点是否必须保留任何寄存器值(被调用者保存的寄存器)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!