Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: src/x64/code-stubs-x64.cc

Issue 1469793002: [builtins] Sanitize the machinery around Construct calls. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: mips64 fix. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/x64/builtins-x64.cc ('k') | src/x64/interface-descriptors-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if V8_TARGET_ARCH_X64 5 #if V8_TARGET_ARCH_X64
6 6
7 #include "src/bootstrapper.h" 7 #include "src/bootstrapper.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/codegen.h" 9 #include "src/codegen.h"
10 #include "src/ic/handler-compiler.h" 10 #include "src/ic/handler-compiler.h"
(...skipping 1735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 __ TailCallRuntime( 1746 __ TailCallRuntime(
1747 is_strong(strength()) ? Runtime::kCompare_Strong : Runtime::kCompare, 3, 1747 is_strong(strength()) ? Runtime::kCompare_Strong : Runtime::kCompare, 3,
1748 1); 1748 1);
1749 } 1749 }
1750 1750
1751 __ bind(&miss); 1751 __ bind(&miss);
1752 GenerateMiss(masm); 1752 GenerateMiss(masm);
1753 } 1753 }
1754 1754
1755 1755
1756 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub, 1756 static void CallStubInRecordCallTarget(MacroAssembler* masm, CodeStub* stub) {
1757 bool is_super) {
1758 // rax : number of arguments to the construct function 1757 // rax : number of arguments to the construct function
1759 // rbx : feedback vector 1758 // rbx : feedback vector
1760 // rcx : new target (for IsSuperConstructorCall)
1761 // rdx : slot in feedback vector (Smi) 1759 // rdx : slot in feedback vector (Smi)
1762 // rdi : the function to call 1760 // rdi : the function to call
1763 FrameScope scope(masm, StackFrame::INTERNAL); 1761 FrameScope scope(masm, StackFrame::INTERNAL);
1764 1762
1765 // Number-of-arguments register must be smi-tagged to call out. 1763 // Number-of-arguments register must be smi-tagged to call out.
1766 __ Integer32ToSmi(rax, rax); 1764 __ Integer32ToSmi(rax, rax);
1767 __ Push(rax); 1765 __ Push(rax);
1768 __ Push(rdi); 1766 __ Push(rdi);
1769 __ Integer32ToSmi(rdx, rdx); 1767 __ Integer32ToSmi(rdx, rdx);
1770 __ Push(rdx); 1768 __ Push(rdx);
1771 __ Push(rbx); 1769 __ Push(rbx);
1772 if (is_super) {
1773 __ Push(rcx);
1774 }
1775 1770
1776 __ CallStub(stub); 1771 __ CallStub(stub);
1777 1772
1778 if (is_super) {
1779 __ Pop(rcx);
1780 }
1781 __ Pop(rbx); 1773 __ Pop(rbx);
1782 __ Pop(rdx); 1774 __ Pop(rdx);
1783 __ Pop(rdi); 1775 __ Pop(rdi);
1784 __ Pop(rax); 1776 __ Pop(rax);
1785 __ SmiToInteger32(rax, rax); 1777 __ SmiToInteger32(rax, rax);
1786 } 1778 }
1787 1779
1788 1780
1789 static void GenerateRecordCallTarget(MacroAssembler* masm, bool is_super) { 1781 static void GenerateRecordCallTarget(MacroAssembler* masm) {
1790 // Cache the called function in a feedback vector slot. Cache states 1782 // Cache the called function in a feedback vector slot. Cache states
1791 // are uninitialized, monomorphic (indicated by a JSFunction), and 1783 // are uninitialized, monomorphic (indicated by a JSFunction), and
1792 // megamorphic. 1784 // megamorphic.
1793 // rax : number of arguments to the construct function 1785 // rax : number of arguments to the construct function
1794 // rbx : feedback vector 1786 // rbx : feedback vector
1795 // rcx : new target (for IsSuperConstructorCall)
1796 // rdx : slot in feedback vector (Smi) 1787 // rdx : slot in feedback vector (Smi)
1797 // rdi : the function to call 1788 // rdi : the function to call
1798 Isolate* isolate = masm->isolate(); 1789 Isolate* isolate = masm->isolate();
1799 Label initialize, done, miss, megamorphic, not_array_function, 1790 Label initialize, done, miss, megamorphic, not_array_function,
1800 done_no_smi_convert; 1791 done_no_smi_convert;
1801 1792
1802 // Load the cache state into r11. 1793 // Load the cache state into r11.
1803 __ SmiToInteger32(rdx, rdx); 1794 __ SmiToInteger32(rdx, rdx);
1804 __ movp(r11, 1795 __ movp(r11,
1805 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize)); 1796 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 // An uninitialized cache is patched with the function or sentinel to 1844 // An uninitialized cache is patched with the function or sentinel to
1854 // indicate the ElementsKind if function is the Array constructor. 1845 // indicate the ElementsKind if function is the Array constructor.
1855 __ bind(&initialize); 1846 __ bind(&initialize);
1856 1847
1857 // Make sure the function is the Array() function 1848 // Make sure the function is the Array() function
1858 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r11); 1849 __ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, r11);
1859 __ cmpp(rdi, r11); 1850 __ cmpp(rdi, r11);
1860 __ j(not_equal, &not_array_function); 1851 __ j(not_equal, &not_array_function);
1861 1852
1862 CreateAllocationSiteStub create_stub(isolate); 1853 CreateAllocationSiteStub create_stub(isolate);
1863 CallStubInRecordCallTarget(masm, &create_stub, is_super); 1854 CallStubInRecordCallTarget(masm, &create_stub);
1864 __ jmp(&done_no_smi_convert); 1855 __ jmp(&done_no_smi_convert);
1865 1856
1866 __ bind(&not_array_function); 1857 __ bind(&not_array_function);
1867 CreateWeakCellStub weak_cell_stub(isolate); 1858 CreateWeakCellStub weak_cell_stub(isolate);
1868 CallStubInRecordCallTarget(masm, &weak_cell_stub, is_super); 1859 CallStubInRecordCallTarget(masm, &weak_cell_stub);
1869 __ jmp(&done_no_smi_convert); 1860 __ jmp(&done_no_smi_convert);
1870 1861
1871 __ bind(&done); 1862 __ bind(&done);
1872 __ Integer32ToSmi(rdx, rdx); 1863 __ Integer32ToSmi(rdx, rdx);
1873 1864
1874 __ bind(&done_no_smi_convert); 1865 __ bind(&done_no_smi_convert);
1875 } 1866 }
1876 1867
1877 1868
1878 void CallConstructStub::Generate(MacroAssembler* masm) { 1869 void CallConstructStub::Generate(MacroAssembler* masm) {
1879 // rax : number of arguments 1870 // rax : number of arguments
1880 // rbx : feedback vector 1871 // rbx : feedback vector
1881 // rcx : new target (for IsSuperConstructorCall) 1872 // rdx : slot in feedback vector (Smi)
1882 // rdx : slot in feedback vector (Smi, for RecordCallTarget)
1883 // rdi : constructor function 1873 // rdi : constructor function
1884 1874
1885 Label non_function; 1875 Label non_function;
1886 // Check that the constructor is not a smi. 1876 // Check that the constructor is not a smi.
1887 __ JumpIfSmi(rdi, &non_function); 1877 __ JumpIfSmi(rdi, &non_function);
1888 // Check that constructor is a JSFunction. 1878 // Check that constructor is a JSFunction.
1889 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, r11); 1879 __ CmpObjectType(rdi, JS_FUNCTION_TYPE, r11);
1890 __ j(not_equal, &non_function); 1880 __ j(not_equal, &non_function);
1891 1881
1892 if (RecordCallTarget()) { 1882 GenerateRecordCallTarget(masm);
1893 GenerateRecordCallTarget(masm, IsSuperConstructorCall());
1894 1883
1895 __ SmiToInteger32(rdx, rdx); 1884 __ SmiToInteger32(rdx, rdx);
1896 Label feedback_register_initialized; 1885 Label feedback_register_initialized;
1897 // Put the AllocationSite from the feedback vector into rbx, or undefined. 1886 // Put the AllocationSite from the feedback vector into rbx, or undefined.
1898 __ movp(rbx, FieldOperand(rbx, rdx, times_pointer_size, 1887 __ movp(rbx,
1899 FixedArray::kHeaderSize)); 1888 FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize));
1900 __ CompareRoot(FieldOperand(rbx, 0), Heap::kAllocationSiteMapRootIndex); 1889 __ CompareRoot(FieldOperand(rbx, 0), Heap::kAllocationSiteMapRootIndex);
1901 __ j(equal, &feedback_register_initialized); 1890 __ j(equal, &feedback_register_initialized, Label::kNear);
1902 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex); 1891 __ LoadRoot(rbx, Heap::kUndefinedValueRootIndex);
1903 __ bind(&feedback_register_initialized); 1892 __ bind(&feedback_register_initialized);
1904 1893
1905 __ AssertUndefinedOrAllocationSite(rbx); 1894 __ AssertUndefinedOrAllocationSite(rbx);
1906 }
1907 1895
1908 // Pass new target to construct stub. 1896 // Pass new target to construct stub.
1909 if (IsSuperConstructorCall()) { 1897 __ movp(rdx, rdi);
1910 __ movp(rdx, rcx);
1911 } else {
1912 __ movp(rdx, rdi);
1913 }
1914 1898
1915 // Tail call to the function-specific construct stub (still in the caller 1899 // Tail call to the function-specific construct stub (still in the caller
1916 // context at this point). 1900 // context at this point).
1917 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); 1901 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
1918 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset)); 1902 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset));
1919 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize)); 1903 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize));
1920 __ jmp(rcx); 1904 __ jmp(rcx);
1921 1905
1922 __ bind(&non_function); 1906 __ bind(&non_function);
1923 __ movp(rdx, rdi); 1907 __ movp(rdx, rdi);
(...skipping 3483 matching lines...) Expand 10 before | Expand all | Expand 10 after
5407 kStackSpace, nullptr, return_value_operand, NULL); 5391 kStackSpace, nullptr, return_value_operand, NULL);
5408 } 5392 }
5409 5393
5410 5394
5411 #undef __ 5395 #undef __
5412 5396
5413 } // namespace internal 5397 } // namespace internal
5414 } // namespace v8 5398 } // namespace v8
5415 5399
5416 #endif // V8_TARGET_ARCH_X64 5400 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/x64/builtins-x64.cc ('k') | src/x64/interface-descriptors-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698