Commit b64c1f02 authored by zhengxing.li's avatar zhengxing.li Committed by Commit bot

X87: [builtins] Make sure argument count is always valid for C++ builtins.

    port 9c8262f1 (r31120).

    original commit message:
    When calling into C++ builtins, we need to make sure that the argument
    count register contains the correct number of arguments, otherwise the
    CEntryStub will not be able to leave the stack in the correct state.

BUG=

Review URL: https://codereview.chromium.org/1418533009

Cr-Commit-Position: refs/heads/master@{#31503}
parent c38e4290
......@@ -22,12 +22,13 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- eax : number of arguments excluding receiver
// -- edi : called function (only guaranteed when
// extra_args requires it)
// (only guaranteed when the called function
// is not marked as DontAdaptArguments)
// -- edi : called function
// -- esp[0] : return address
// -- esp[4] : last argument
// -- ...
// -- esp[4 * argc] : first argument (argc == eax)
// -- esp[4 * argc] : first argument
// -- esp[4 * (argc +1)] : receiver
// -----------------------------------
__ AssertFunction(edi);
......@@ -52,8 +53,22 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
}
// JumpToExternalReference expects eax to contain the number of arguments
// including the receiver and the extra arguments.
// including the receiver and the extra arguments. But eax is only valid
// if the called function is marked as DontAdaptArguments, otherwise we
// need to load the argument count from the SharedFunctionInfo.
Label argc, done_argc;
__ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
__ mov(ebx,
FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset));
__ SmiUntag(ebx);
__ cmp(ebx, SharedFunctionInfo::kDontAdaptArgumentsSentinel);
__ j(equal, &argc, Label::kNear);
__ lea(eax, Operand(ebx, num_extra_args + 1));
__ jmp(&done_argc, Label::kNear);
__ bind(&argc);
__ add(eax, Immediate(num_extra_args + 1));
__ bind(&done_argc);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment