Statically align the stack at function boundaries (bug 5842, r=ds).
authorDavid Anderson <dvander@alliedmods.net>
Sun Aug 11 11:27:19 2013 -0700 (2013-08-11)
changeset 398346f4122981c2
parent 3982 be7835a7c28f
child 3984 d94a0d3bc008
Statically align the stack at function boundaries (bug 5842, r=ds).
sourcepawn/jit/dll_exports.cpp
sourcepawn/jit/x86/jit_x86.cpp
     1.1 --- a/sourcepawn/jit/dll_exports.cpp	Sat Aug 10 21:23:02 2013 -0700
     1.2 +++ b/sourcepawn/jit/dll_exports.cpp	Sun Aug 11 11:27:19 2013 -0700
     1.3 @@ -146,6 +146,11 @@
     1.4  	return 1;
     1.5  }
     1.6  
     1.7 +static cell_t DoNothing(IPluginContext *cx, const cell_t *params)
     1.8 +{
     1.9 +	return 1;
    1.10 +}
    1.11 +
    1.12  static void BindNative(IPluginRuntime *rt, const char *name, SPVM_NATIVE_FUNC fn)
    1.13  {
    1.14  	int err;
    1.15 @@ -185,6 +190,7 @@
    1.16  	BindNative(rt, "printnum", PrintNum);
    1.17  	BindNative(rt, "printnums", PrintNums);
    1.18  	BindNative(rt, "printfloat", PrintFloat);
    1.19 +	BindNative(rt, "donothing", DoNothing);
    1.20  
    1.21  	IPluginFunction *fun = rt->GetFunctionByName("main");
    1.22  	if (!fun)
     2.1 --- a/sourcepawn/jit/x86/jit_x86.cpp	Sat Aug 10 21:23:02 2013 -0700
     2.2 +++ b/sourcepawn/jit/x86/jit_x86.cpp	Sun Aug 11 11:27:19 2013 -0700
     2.3 @@ -614,6 +614,9 @@
     2.4        __ movl(frm, stk);
     2.5        __ subl(tmp, dat);
     2.6        __ movl(Operand(info, AMX_INFO_FRAME), tmp);
     2.7 +
     2.8 +      // Align the stack to 16-bytes (each call adds 4 bytes).
     2.9 +      __ subl(esp, 12);
    2.10        break;
    2.11  
    2.12      case OP_IDXADDR_B:
    2.13 @@ -988,6 +991,7 @@
    2.14        // Remove parameters.
    2.15        __ movl(tmp, Operand(stk, 0));
    2.16        __ lea(stk, Operand(stk, tmp, ScaleFour, 4));
    2.17 +      __ addl(esp, 12);
    2.18        __ ret();
    2.19        break;
    2.20      }
    2.21 @@ -1585,12 +1589,6 @@
    2.22    // Save registers.
    2.23    __ push(edx);
    2.24  
    2.25 -  // Align the stack to 16 bytes.
    2.26 -  __ push(ebx);
    2.27 -  __ movl(ebx, esp);
    2.28 -  __ andl(esp, 0xfffffff0);
    2.29 -  __ subl(esp, 4);
    2.30 -
    2.31    // Push the parameters for the C++ function.
    2.32    __ push(stk);
    2.33    __ push(native_index);
    2.34 @@ -1616,9 +1614,8 @@
    2.35    __ j(not_zero, &extern_error_);
    2.36    
    2.37    // Restore local state.
    2.38 -  __ movl(esp, ebx);
    2.39 -  __ pop(ebx);
    2.40    __ addl(stk, dat);
    2.41 +  __ addl(esp, 12);
    2.42    __ pop(edx);
    2.43  
    2.44    if (op == OP_SYSREQ_N) {
    2.45 @@ -1786,7 +1783,10 @@
    2.46    __ movl(ebx, edi);
    2.47    __ movl(Operand(esi, AMX_INFO_NSTACK), esp);
    2.48  
    2.49 -  // Call into plugin.
    2.50 +  // Align the stack.
    2.51 +  __ andl(esp, 0xfffffff0);
    2.52 +
    2.53 +  // Call into plugin (align the stack first).
    2.54    __ call(ecx);
    2.55  
    2.56    __ movl(ecx, Operand(info, AMX_INFO_RETVAL));