[英]Compiler ignore __stdcall
It seems to me, that MSVS ignores __stdcall directive on my functions. 在我看来,MSVS忽略了我的函数的__stdcall指令。 I'm cleaning up the stack manually, but the compiler still append
ADD ESP
instructions after each CALL
. 我正在手动清理堆栈,但编译器在每次
CALL
后仍会附加ADD ESP
指令。
This is how I declare the function: 这是我声明函数的方式:
extern "C" void * __stdcall core_call(int addr, ...);
#define function(...) (DWORD WINAPI) core_call(12345, __VA_ARGS__)
return function("Hello", 789);
And this is how the output looks like: 这就是输出的样子:
(source: server4u.cz ) (来源: server4u.cz )
I've marked with arrows redundant ADD
instructions, which MSVS automatically append after each call, despite the fact, that cleaining the stack is a callee responsibility (reference: http://en.wikipedia.org/wiki/X86_calling_conventions#List_of_x86_calling_conventions ) and this causes the crash of my progrm. 我用箭头标记了冗余
ADD
指令,MSVS在每次调用后自动附加,尽管事实上,清理堆栈是被调用者的责任(参考: http : //en.wikipedia.org/wiki/X86_calling_conventions#List_of_x86_calling_conventions )和这会导致我的程序崩溃。 If I manually replace the ADD
instructions with NOPs
, program works as supposed. 如果我用
NOPs
手动替换ADD
指令,程序将按预期工作。 So, my question is... Is there a way how to force the compiler to stop addaing these instructions? 所以,我的问题是......有没有办法强制编译器停止添加这些指令?
Thanks. 谢谢。
The problem is here: , ...)
. 问题在于:
, ...)
。
Functions with variable number of arguments cannot be __stdcall
. 具有可变数量参数的函数不能
__stdcall
。
__stdcall
functions must remove all their stack arguments from the stack at the end, but they can't know in advance how much stuff they will receive as parameters. __stdcall
函数必须在最后从堆栈中删除所有堆栈参数,但它们无法预先知道它们将作为参数接收多少内容。
The same holds for __fastcall
functions. 这同样适用于
__fastcall
函数。
The only applicable calling convention for functions with variable number of arguments is __cdecl
, where the caller has to remove the stack parameters after the call. 具有可变参数个数的函数的唯一适用调用约定是
__cdecl
,其中调用者必须在调用后删除堆栈参数。 And that's what the compiler uses despite your request to use __stdcall
. 这就是编译器使用尽管您使用
__stdcall
的请求所使用的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.