<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Yep. Windows has 2 calling conventions - stdcall for the Microsoft Win32 API, and the default cdecl for everything else. </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"><a href="https://en.wikipedia.org/wiki/X86_calling_conventions#stdcall">https://en.wikipedia.org/wiki/X86_calling_conventions#stdcall</a></font><br></div><div class="gmail_extra"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">​</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">Basically you need to know which calling convention the function is expecting, and you need to tell the FFI, otherwise your stack will explode.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">​- Bert -​</div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 4, 2017 at 10:47 AM, Jakob Reschke <span dir="ltr"><<a href="mailto:jakob.reschke@student.hpi.de" target="_blank">jakob.reschke@student.hpi.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>Here is what I found, experts please double-check (and I only looked up x86):<div dir="auto"><br></div><div dir="auto">The Windows API uses the stdcall calling convention, which has the same argument order and register preservation rules as cdecl, but the callee is responsible to pop arguments from the stack.</div><div dir="auto"><br></div><div dir="auto">In IA32FFIPlugin there is a macro PLATFORM_API_USES_CALLEE_POPS_<wbr>CONVENTION, which is only 1 on Windows. If this is 1 and apicall is used (isCalleePopsConvention), the foreign function invocation code knows that the callee modifies the stack pointer and reacts accordingly.</div><div dir="auto"><br></div><div dir="auto">So, apicall does stdcall instead of cdecl on Windows, but not on the other x86 platforms.</div><div dir="auto"><br></div><div dir="auto">Stdcall is not the same as the Pascal calling convention, which pushes arguments from left to right, contrary to cdecl and stdcall, which push from right to left.</div><div dir="auto"><br></div><div dir="auto">Best,</div><div dir="auto">Jakob</div><div><div class="gmail-h5"><br><div class="gmail_extra"><br><div class="gmail_quote">Am 04.08.2017 3:45 vorm. schrieb "tim Rowledge" <<a href="mailto:tim@rowledge.org" target="_blank">tim@rowledge.org</a>>:<br type="attribution"><blockquote class="gmail-m_-336314656228453850quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Whilst looking at ancient OpenGL code I noted that many primitive calls used apicall and not cdecl. The swiki entry (<a href="http://wiki.squeak.org/squeak/2426" rel="noreferrer" target="_blank">http://wiki.squeak.org/squeak<wbr>/2426</a>) for FFI is… vague, and explicitly mentions confusion about the matter. It wold be nice to clear this up, document it on the swiki and maybe even make a Help page to go into the image.<br>
<br>
tim<br>
--<br>
tim Rowledge; <a href="mailto:tim@rowledge.org" target="_blank">tim@rowledge.org</a>; <a href="http://www.rowledge.org/tim" rel="noreferrer" target="_blank">http://www.rowledge.org/tim</a><br>
Strange OpCodes: MII: Mask all Interrupts and then Interrupt<br>
<br>
<br>
<br>
</blockquote></div><br></div></div></div></div></div>
<br><br>
<br></blockquote></div><br></div></div>