Statically align the stack at function boundaries (bug 5842, r=ds).
This commit is contained in:
parent
ce542ac5f6
commit
449617474b
@ -146,6 +146,11 @@ static cell_t PrintNums(IPluginContext *cx, const cell_t *params)
|
|||||||
return 1;
|
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)
|
static void BindNative(IPluginRuntime *rt, const char *name, SPVM_NATIVE_FUNC fn)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -185,6 +190,7 @@ static int Execute(const char *file)
|
|||||||
BindNative(rt, "printnum", PrintNum);
|
BindNative(rt, "printnum", PrintNum);
|
||||||
BindNative(rt, "printnums", PrintNums);
|
BindNative(rt, "printnums", PrintNums);
|
||||||
BindNative(rt, "printfloat", PrintFloat);
|
BindNative(rt, "printfloat", PrintFloat);
|
||||||
|
BindNative(rt, "donothing", DoNothing);
|
||||||
|
|
||||||
IPluginFunction *fun = rt->GetFunctionByName("main");
|
IPluginFunction *fun = rt->GetFunctionByName("main");
|
||||||
if (!fun)
|
if (!fun)
|
||||||
|
@ -614,6 +614,9 @@ Compiler::emitOp(OPCODE op)
|
|||||||
__ movl(frm, stk);
|
__ movl(frm, stk);
|
||||||
__ subl(tmp, dat);
|
__ subl(tmp, dat);
|
||||||
__ movl(Operand(info, AMX_INFO_FRAME), tmp);
|
__ movl(Operand(info, AMX_INFO_FRAME), tmp);
|
||||||
|
|
||||||
|
// Align the stack to 16-bytes (each call adds 4 bytes).
|
||||||
|
__ subl(esp, 12);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OP_IDXADDR_B:
|
case OP_IDXADDR_B:
|
||||||
@ -988,6 +991,7 @@ Compiler::emitOp(OPCODE op)
|
|||||||
// Remove parameters.
|
// Remove parameters.
|
||||||
__ movl(tmp, Operand(stk, 0));
|
__ movl(tmp, Operand(stk, 0));
|
||||||
__ lea(stk, Operand(stk, tmp, ScaleFour, 4));
|
__ lea(stk, Operand(stk, tmp, ScaleFour, 4));
|
||||||
|
__ addl(esp, 12);
|
||||||
__ ret();
|
__ ret();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1585,12 +1589,6 @@ Compiler::emitNativeCall(OPCODE op)
|
|||||||
// Save registers.
|
// Save registers.
|
||||||
__ push(edx);
|
__ 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 the parameters for the C++ function.
|
||||||
__ push(stk);
|
__ push(stk);
|
||||||
__ push(native_index);
|
__ push(native_index);
|
||||||
@ -1616,9 +1614,8 @@ Compiler::emitNativeCall(OPCODE op)
|
|||||||
__ j(not_zero, &extern_error_);
|
__ j(not_zero, &extern_error_);
|
||||||
|
|
||||||
// Restore local state.
|
// Restore local state.
|
||||||
__ movl(esp, ebx);
|
|
||||||
__ pop(ebx);
|
|
||||||
__ addl(stk, dat);
|
__ addl(stk, dat);
|
||||||
|
__ addl(esp, 12);
|
||||||
__ pop(edx);
|
__ pop(edx);
|
||||||
|
|
||||||
if (op == OP_SYSREQ_N) {
|
if (op == OP_SYSREQ_N) {
|
||||||
@ -1786,7 +1783,10 @@ GenerateEntry(void **retp)
|
|||||||
__ movl(ebx, edi);
|
__ movl(ebx, edi);
|
||||||
__ movl(Operand(esi, AMX_INFO_NSTACK), esp);
|
__ 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);
|
__ call(ecx);
|
||||||
|
|
||||||
__ movl(ecx, Operand(info, AMX_INFO_RETVAL));
|
__ movl(ecx, Operand(info, AMX_INFO_RETVAL));
|
||||||
|
Loading…
Reference in New Issue
Block a user