From: lrn@chromium.org Date: Fri, 28 May 2010 08:37:44 +0000 (+0000) Subject: X64: Fix issue 678. Bug in some Win64 C calls from generated code. X-Git-Tag: upstream/4.7.83~21718 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1be589d8447c04c51c45397b260598228d495e62;p=platform%2Fupstream%2Fv8.git X64: Fix issue 678. Bug in some Win64 C calls from generated code. Win 64 C call ABI implementation requires space allocated on stack for four argument registers, even when passing fewer arguments in registers. Review URL: http://codereview.chromium.org/2365001 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4748 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc index b851fec..3823cad 100644 --- a/src/x64/macro-assembler-x64.cc +++ b/src/x64/macro-assembler-x64.cc @@ -2641,20 +2641,27 @@ void MacroAssembler::LoadContext(Register dst, int context_chain_length) { } } + int MacroAssembler::ArgumentStackSlotsForCFunctionCall(int num_arguments) { - // On Windows stack slots are reserved by the caller for all arguments - // including the ones passed in registers. On Linux 6 arguments are passed in - // registers and the caller does not reserve stack slots for them. + // On Windows 64 stack slots are reserved by the caller for all arguments + // including the ones passed in registers, and space is always allocated for + // the four register arguments even if the function takes fewer than four + // arguments. + // On AMD64 ABI (Linux/Mac) the first six arguments are passed in registers + // and the caller does not reserve stack slots for them. ASSERT(num_arguments >= 0); #ifdef _WIN64 - static const int kArgumentsWithoutStackSlot = 0; + static const int kMinimumStackSlots = 4; + if (num_arguments < kMinimumStackSlots) return kMinimumStackSlots; + return num_arguments; #else - static const int kArgumentsWithoutStackSlot = 6; + static const int kRegisterPassedArguments = 6; + if (num_arguments < kRegisterPassedArguments) return 0; + return num_arguments - kRegisterPassedArguments; #endif - return num_arguments > kArgumentsWithoutStackSlot ? - num_arguments - kArgumentsWithoutStackSlot : 0; } + void MacroAssembler::PrepareCallCFunction(int num_arguments) { int frame_alignment = OS::ActivationFrameAlignment(); ASSERT(frame_alignment != 0);