Use __cdecl rather than __stdcall for icalls on Windows 32-bit
authorNiklas Therning <niklas@therning.org>
Mon, 28 Nov 2016 14:25:01 +0000 (15:25 +0100)
committerNiklas Therning <niklas@therning.org>
Mon, 28 Nov 2016 14:25:01 +0000 (15:25 +0100)
commit61c239fb7f55bf802cb0bfc71a8680e21e324be9
tree96e8aaf45ce93c49610293dd7f91be5d62a3ee0f
parent700a511bac54d497c75036c40f800c7ebfe211d6
Use __cdecl rather than __stdcall for icalls on Windows 32-bit

Mono assumes the same calling convention for icalls as the default P/Invoke
calling convention which is __stdcall on Windows. But none of the icalls are
marked with the required __stdcall attribute on Windows so there will be a
mismatch between the caller and callee.

This is the reason why the System.Web.HttpUtilityTest.JavaScriptStringEncode()
test crashes on Windows 32-bit. It generates a call to an icall
(char.ToString() inlines to new string(char,int)) which is assumed to be
__stdcall while it's actually __cdecl. The caller will decrement ESP as if the
callee was __stdcall resulting in ESP decreasing on each iteration. After a
couple of thousand iterations in the loop in that test the stack guard page is
hit and a stack overflow occurs.
mono/metadata/loader.c