Fix bug in X64 RegExpExec stub.
Used incorrect register for referencing RegExp data, so it always failed to match the fast case. When modifiying the object layout, it was possible to make it crash instead. BUG=v8:1236 TEST=test/mjsunit/regress/regress-1236.js Review URL: http://codereview.chromium.org/6635041 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7091 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
0c74af3d0f
commit
a8b41a0edd
@ -860,7 +860,9 @@ RegExpEngine::CompilationResult RegExpCompiler::Assemble(
|
||||
if (reg_exp_too_big_) return IrregexpRegExpTooBig();
|
||||
|
||||
Handle<Object> code = macro_assembler_->GetCode(pattern);
|
||||
|
||||
if (FLAG_print_code) {
|
||||
Handle<Code>::cast(code)->Disassemble(*pattern->ToCString());
|
||||
}
|
||||
work_list_ = NULL;
|
||||
#ifdef DEBUG
|
||||
if (FLAG_trace_regexp_assembler) {
|
||||
|
@ -2423,7 +2423,6 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
|
||||
static const int kJSRegExpOffset = 4 * kPointerSize;
|
||||
|
||||
Label runtime;
|
||||
|
||||
// Ensure that a RegExp stack is allocated.
|
||||
ExternalReference address_of_regexp_stack_memory_address =
|
||||
ExternalReference::address_of_regexp_stack_memory_address();
|
||||
@ -2441,32 +2440,32 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
|
||||
__ CmpObjectType(rax, JS_REGEXP_TYPE, kScratchRegister);
|
||||
__ j(not_equal, &runtime);
|
||||
// Check that the RegExp has been compiled (data contains a fixed array).
|
||||
__ movq(rcx, FieldOperand(rax, JSRegExp::kDataOffset));
|
||||
__ movq(rax, FieldOperand(rax, JSRegExp::kDataOffset));
|
||||
if (FLAG_debug_code) {
|
||||
Condition is_smi = masm->CheckSmi(rcx);
|
||||
Condition is_smi = masm->CheckSmi(rax);
|
||||
__ Check(NegateCondition(is_smi),
|
||||
"Unexpected type for RegExp data, FixedArray expected");
|
||||
__ CmpObjectType(rcx, FIXED_ARRAY_TYPE, kScratchRegister);
|
||||
__ CmpObjectType(rax, FIXED_ARRAY_TYPE, kScratchRegister);
|
||||
__ Check(equal, "Unexpected type for RegExp data, FixedArray expected");
|
||||
}
|
||||
|
||||
// rcx: RegExp data (FixedArray)
|
||||
// rax: RegExp data (FixedArray)
|
||||
// Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
|
||||
__ SmiToInteger32(rbx, FieldOperand(rcx, JSRegExp::kDataTagOffset));
|
||||
__ SmiToInteger32(rbx, FieldOperand(rax, JSRegExp::kDataTagOffset));
|
||||
__ cmpl(rbx, Immediate(JSRegExp::IRREGEXP));
|
||||
__ j(not_equal, &runtime);
|
||||
|
||||
// rcx: RegExp data (FixedArray)
|
||||
// rax: RegExp data (FixedArray)
|
||||
// Check that the number of captures fit in the static offsets vector buffer.
|
||||
__ SmiToInteger32(rdx,
|
||||
FieldOperand(rcx, JSRegExp::kIrregexpCaptureCountOffset));
|
||||
FieldOperand(rax, JSRegExp::kIrregexpCaptureCountOffset));
|
||||
// Calculate number of capture registers (number_of_captures + 1) * 2.
|
||||
__ leal(rdx, Operand(rdx, rdx, times_1, 2));
|
||||
// Check that the static offsets vector buffer is large enough.
|
||||
__ cmpl(rdx, Immediate(OffsetsVector::kStaticOffsetsVectorSize));
|
||||
__ j(above, &runtime);
|
||||
|
||||
// rcx: RegExp data (FixedArray)
|
||||
// rax: RegExp data (FixedArray)
|
||||
// rdx: Number of capture registers
|
||||
// Check that the second argument is a string.
|
||||
__ movq(rdi, Operand(rsp, kSubjectOffset));
|
||||
@ -2584,7 +2583,7 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
|
||||
static const int kRegExpExecuteArguments = 7;
|
||||
int argument_slots_on_stack =
|
||||
masm->ArgumentStackSlotsForCFunctionCall(kRegExpExecuteArguments);
|
||||
__ EnterApiExitFrame(argument_slots_on_stack); // Clobbers rax!
|
||||
__ EnterApiExitFrame(argument_slots_on_stack);
|
||||
|
||||
// Argument 7: Indicate that this is a direct call from JavaScript.
|
||||
__ movq(Operand(rsp, (argument_slots_on_stack - 1) * kPointerSize),
|
||||
|
@ -2028,16 +2028,15 @@ void MacroAssembler::EnterExitFramePrologue(bool save_rax) {
|
||||
push(kScratchRegister); // Accessed from EditFrame::code_slot.
|
||||
|
||||
// Save the frame pointer and the context in top.
|
||||
ExternalReference c_entry_fp_address(Top::k_c_entry_fp_address);
|
||||
ExternalReference context_address(Top::k_context_address);
|
||||
if (save_rax) {
|
||||
movq(r14, rax); // Backup rax before we use it.
|
||||
movq(r14, rax); // Backup rax in callee-save register.
|
||||
}
|
||||
|
||||
movq(rax, rbp);
|
||||
store_rax(c_entry_fp_address);
|
||||
movq(rax, rsi);
|
||||
store_rax(context_address);
|
||||
movq(kScratchRegister, ExternalReference(Top::k_c_entry_fp_address));
|
||||
movq(Operand(kScratchRegister, 0), rbp);
|
||||
|
||||
movq(kScratchRegister, ExternalReference(Top::k_context_address));
|
||||
movq(Operand(kScratchRegister, 0), rsi);
|
||||
}
|
||||
|
||||
|
||||
|
34
test/mjsunit/regress/regress-1236.js
Normal file
34
test/mjsunit/regress/regress-1236.js
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2011 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Should not crash.
|
||||
|
||||
pattern = RegExp("",""); // RegExp is irrelevant, as long as it's not an atom.
|
||||
string = 'a'; // Anything non-empty (flat ASCII).
|
||||
pattern.exec(string); // Ensure that JSRegExp is compiled.
|
||||
pattern["@"] = 42; // Change layout of JSRegExp object.
|
||||
pattern.exec(string); // Call again to trigger bug in stub.
|
Loading…
Reference in New Issue
Block a user