# HG changeset patch # User David Anderson # Date 1376245639 25200 # Node ID 46f4122981c277f246f4b6c3dc8bad72d3a64db7 # Parent be7835a7c28faffe6a0f8670ff0a031182fc8b93 Statically align the stack at function boundaries (bug 5842, r=ds). diff -r be7835a7c28f -r 46f4122981c2 sourcepawn/jit/dll_exports.cpp --- a/sourcepawn/jit/dll_exports.cpp Sat Aug 10 21:23:02 2013 -0700 +++ b/sourcepawn/jit/dll_exports.cpp Sun Aug 11 11:27:19 2013 -0700 @@ -146,6 +146,11 @@ return 1; } +static cell_t DoNothing(IPluginContext *cx, const cell_t *params) +{ + return 1; +} + static void BindNative(IPluginRuntime *rt, const char *name, SPVM_NATIVE_FUNC fn) { int err; @@ -185,6 +190,7 @@ BindNative(rt, "printnum", PrintNum); BindNative(rt, "printnums", PrintNums); BindNative(rt, "printfloat", PrintFloat); + BindNative(rt, "donothing", DoNothing); IPluginFunction *fun = rt->GetFunctionByName("main"); if (!fun) diff -r be7835a7c28f -r 46f4122981c2 sourcepawn/jit/x86/jit_x86.cpp --- a/sourcepawn/jit/x86/jit_x86.cpp Sat Aug 10 21:23:02 2013 -0700 +++ b/sourcepawn/jit/x86/jit_x86.cpp Sun Aug 11 11:27:19 2013 -0700 @@ -614,6 +614,9 @@ __ movl(frm, stk); __ subl(tmp, dat); __ movl(Operand(info, AMX_INFO_FRAME), tmp); + + // Align the stack to 16-bytes (each call adds 4 bytes). + __ subl(esp, 12); break; case OP_IDXADDR_B: @@ -988,6 +991,7 @@ // Remove parameters. __ movl(tmp, Operand(stk, 0)); __ lea(stk, Operand(stk, tmp, ScaleFour, 4)); + __ addl(esp, 12); __ ret(); break; } @@ -1585,12 +1589,6 @@ // Save registers. __ push(edx); - // Align the stack to 16 bytes. - __ push(ebx); - __ movl(ebx, esp); - __ andl(esp, 0xfffffff0); - __ subl(esp, 4); - // Push the parameters for the C++ function. __ push(stk); __ push(native_index); @@ -1616,9 +1614,8 @@ __ j(not_zero, &extern_error_); // Restore local state. - __ movl(esp, ebx); - __ pop(ebx); __ addl(stk, dat); + __ addl(esp, 12); __ pop(edx); if (op == OP_SYSREQ_N) { @@ -1786,7 +1783,10 @@ __ movl(ebx, edi); __ movl(Operand(esi, AMX_INFO_NSTACK), esp); - // Call into plugin. + // Align the stack. + __ andl(esp, 0xfffffff0); + + // Call into plugin (align the stack first). __ call(ecx); __ movl(ecx, Operand(info, AMX_INFO_RETVAL));