简体   繁体   English

如何在__stdcall中使用varargs而不使编译器破坏堆栈

[英]How to use varargs with __stdcall without the compiler corrupting the stack

I've encountered the problem with MSVC and ICC: 我遇到了MSVC和ICC的问题:

I need to use a varadic arguments with an stdcall calling convention, but the compiler ignores it for varadic functions and corrupts the stack. 我需要使用带有stdcall调用约定的变量参数,但是对于变量函数,编译器将其忽略,并破坏了堆栈。

Easy way to fix this would be to just take the number of arguments as one of the arguments and offset ESP before it's corrupted, but in this case I don't need the number of args for the context of the function so would rather avoid it if possible. 解决此问题的简单方法是仅将参数数量作为参数之一,并在损坏之前抵消ESP ,但在这种情况下,我不需要该函数上下文的args数量,因此宁愿避免使用它如果可能的话。

Does somebody know if there's a way to do this? 有人知道有没有办法做到这一点?

As per the documentation : 根据文档

The callee cleans the stack, so the compiler makes vararg functions __cdecl . 被调用者清理堆栈,因此编译器使vararg函数__cdecl

Given this, I'm not sure how you expect to proceed. 鉴于此,我不确定您的期望如何。 If stdcall requires the callee to clean the stack, but in vararg functions the callee cannot know what's on the stack at compile-time, how would it work? 如果stdcall要求被调用方清理堆栈,但是在vararg函数中,被调用方无法在编译时知道堆栈中的内容,它将如何工作? Would you expect the stdarg va_list macros to manipulate the call frame? 您希望stdarg va_list宏能够操纵调用帧吗? I don't think that's how Microsoft sees it, so what you're asking doesn't seem possible, at least not by writing C using the Microsoft compiler. 我不认为这是Microsoft的看法,因此您的要求似乎不可能实现,至少不能通过使用Microsoft编译器编写C来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM