WebKit Bugzilla
Attachment 371976 Details for
Bug 198796
: REGRESSION(r246322): "It's a huge page load regression on iOS" (Requested by saamyjoon on #webkit).
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
ROLLOUT of r246322
bug-198796-20190612113731.patch (text/plain), 117.89 KB, created by
WebKit Commit Bot
on 2019-06-12 11:37:31 PDT
(
hide
)
Description:
ROLLOUT of r246322
Filename:
MIME Type:
Creator:
WebKit Commit Bot
Created:
2019-06-12 11:37:31 PDT
Size:
117.89 KB
patch
obsolete
>Subversion Revision: 246367 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 1c08f6039c11084d1187a15c60f0e13526899bdd..b86eae47087383e0ca4daffa73738cc5bf82ef20 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,17 @@ >+2019-06-12 Commit Queue <commit-queue@webkit.org> >+ >+ Unreviewed, rolling out r246322. >+ https://bugs.webkit.org/show_bug.cgi?id=198796 >+ >+ "It's a huge page load regression on iOS" (Requested by >+ saamyjoon on #webkit). >+ >+ Reverted changeset: >+ >+ "Roll out PAC cage" >+ https://bugs.webkit.org/show_bug.cgi?id=198726 >+ https://trac.webkit.org/changeset/246322 >+ > 2019-06-11 Alexey Shvayka <shvaikalesh@gmail.com> > > JSC should throw if proxy set returns falsish in strict mode context >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index f37f7eb1ff7f58535403aedb4a219b517e224704..d3842906e0fd756abef86a811b4785826a387980 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,17 @@ >+2019-06-12 Commit Queue <commit-queue@webkit.org> >+ >+ Unreviewed, rolling out r246322. >+ https://bugs.webkit.org/show_bug.cgi?id=198796 >+ >+ "It's a huge page load regression on iOS" (Requested by >+ saamyjoon on #webkit). >+ >+ Reverted changeset: >+ >+ "Roll out PAC cage" >+ https://bugs.webkit.org/show_bug.cgi?id=198726 >+ https://trac.webkit.org/changeset/246322 >+ > 2019-06-10 Simon Fraser <simon.fraser@apple.com> > > Add logging for UI-side compositing hit-testing >diff --git a/Source/bmalloc/ChangeLog b/Source/bmalloc/ChangeLog >index 93ee2e6e87afe2a86e899453bcf7de97e6db321e..1104926f19b4caf96849106a09101cba3b53ca81 100644 >--- a/Source/bmalloc/ChangeLog >+++ b/Source/bmalloc/ChangeLog >@@ -1,3 +1,17 @@ >+2019-06-12 Commit Queue <commit-queue@webkit.org> >+ >+ Unreviewed, rolling out r246322. >+ https://bugs.webkit.org/show_bug.cgi?id=198796 >+ >+ "It's a huge page load regression on iOS" (Requested by >+ saamyjoon on #webkit). >+ >+ Reverted changeset: >+ >+ "Roll out PAC cage" >+ https://bugs.webkit.org/show_bug.cgi?id=198726 >+ https://trac.webkit.org/changeset/246322 >+ > 2019-06-11 Saam Barati <sbarati@apple.com> > > Roll out PAC cage >diff --git a/Source/JavaScriptCore/assembler/CPU.h b/Source/JavaScriptCore/assembler/CPU.h >index ddccd00a879b517021ceef8fd19966097dbf8757..c1674ec919c7bec2678a374817b719ab6e2cb6bc 100644 >--- a/Source/JavaScriptCore/assembler/CPU.h >+++ b/Source/JavaScriptCore/assembler/CPU.h >@@ -56,6 +56,15 @@ constexpr bool isARM64() > #endif > } > >+constexpr bool isARM64E() >+{ >+#if CPU(ARM64E) >+ return true; >+#else >+ return false; >+#endif >+} >+ > constexpr bool isX86() > { > #if CPU(X86_64) || CPU(X86) >diff --git a/Source/JavaScriptCore/assembler/MacroAssemblerARM64E.h b/Source/JavaScriptCore/assembler/MacroAssemblerARM64E.h >index 9803bd5c1403d047d5965f0f4cca0ae1037f4db0..0b968f6afedfea695a4a3a308d340f076c9cfa40 100644 >--- a/Source/JavaScriptCore/assembler/MacroAssemblerARM64E.h >+++ b/Source/JavaScriptCore/assembler/MacroAssemblerARM64E.h >@@ -82,6 +82,28 @@ public: > m_assembler.xpaci(target); > } > >+ ALWAYS_INLINE void tagArrayPtr(RegisterID length, RegisterID target) >+ { >+ m_assembler.pacdb(target, length); >+ } >+ >+ ALWAYS_INLINE void untagArrayPtr(RegisterID length, RegisterID target) >+ { >+ m_assembler.autdb(target, length); >+ } >+ >+ ALWAYS_INLINE void untagArrayPtr(Address length, RegisterID target) >+ { >+ auto lengthGPR = getCachedDataTempRegisterIDAndInvalidate(); >+ load32(length, lengthGPR); >+ m_assembler.autdb(target, lengthGPR); >+ } >+ >+ ALWAYS_INLINE void removeArrayPtrTag(RegisterID target) >+ { >+ m_assembler.xpacd(target); >+ } >+ > static const RegisterID InvalidGPR = static_cast<RegisterID>(-1); > > enum class CallSignatureType { >diff --git a/Source/JavaScriptCore/b3/B3LowerToAir.cpp b/Source/JavaScriptCore/b3/B3LowerToAir.cpp >index 1b3a92e5226320365dfaae6303c0fe1e2dbb9ee8..b4098bcdd19796a3fb213196d8a03ea92c64cf21 100644 >--- a/Source/JavaScriptCore/b3/B3LowerToAir.cpp >+++ b/Source/JavaScriptCore/b3/B3LowerToAir.cpp >@@ -1274,6 +1274,7 @@ private: > arg = tmp(value.value()); > break; > case ValueRep::SomeRegister: >+ case ValueRep::SomeLateRegister: > arg = tmp(value.value()); > break; > case ValueRep::SomeRegisterWithClobber: { >diff --git a/Source/JavaScriptCore/b3/B3PatchpointSpecial.cpp b/Source/JavaScriptCore/b3/B3PatchpointSpecial.cpp >index daae2432c5b5bf44d8ec3f16f709e03c0cc57a23..1532edff2b94f94dea81da472eeeca0ca3e46d10 100644 >--- a/Source/JavaScriptCore/b3/B3PatchpointSpecial.cpp >+++ b/Source/JavaScriptCore/b3/B3PatchpointSpecial.cpp >@@ -120,6 +120,7 @@ bool PatchpointSpecial::admitsStack(Inst& inst, unsigned argIndex) > case ValueRep::SomeRegister: > case ValueRep::SomeRegisterWithClobber: > case ValueRep::SomeEarlyRegister: >+ case ValueRep::SomeLateRegister: > case ValueRep::Register: > case ValueRep::LateRegister: > return false; >diff --git a/Source/JavaScriptCore/b3/B3StackmapSpecial.cpp b/Source/JavaScriptCore/b3/B3StackmapSpecial.cpp >index 2f07111470188a9ce9aeca3f1ebcf37ebdbd3f3d..298c94c95a5c5d01ddeca45ca4adb6073d5ee31f 100644 >--- a/Source/JavaScriptCore/b3/B3StackmapSpecial.cpp >+++ b/Source/JavaScriptCore/b3/B3StackmapSpecial.cpp >@@ -113,6 +113,7 @@ void StackmapSpecial::forEachArgImpl( > case ValueRep::SomeRegisterWithClobber: > role = Arg::UseDef; > break; >+ case ValueRep::SomeLateRegister: > case ValueRep::LateRegister: > role = Arg::LateUse; > break; >@@ -254,6 +255,7 @@ bool StackmapSpecial::isArgValidForRep(Air::Code& code, const Air::Arg& arg, con > case ValueRep::SomeRegister: > case ValueRep::SomeRegisterWithClobber: > case ValueRep::SomeEarlyRegister: >+ case ValueRep::SomeLateRegister: > return arg.isTmp(); > case ValueRep::LateRegister: > case ValueRep::Register: >diff --git a/Source/JavaScriptCore/b3/B3Validate.cpp b/Source/JavaScriptCore/b3/B3Validate.cpp >index f5cd7d2f0c91e86868d12ef809a150ddffb4d08b..f7b3c55f8eef099b0bd78c405fdff0775b613c7a 100644 >--- a/Source/JavaScriptCore/b3/B3Validate.cpp >+++ b/Source/JavaScriptCore/b3/B3Validate.cpp >@@ -580,6 +580,7 @@ private: > break; > case ValueRep::Register: > case ValueRep::LateRegister: >+ case ValueRep::SomeLateRegister: > if (value.rep().kind() == ValueRep::LateRegister) > VALIDATE(role == ConstraintRole::Use, ("At ", *context, ": ", value)); > if (value.rep().reg().isGPR()) >diff --git a/Source/JavaScriptCore/b3/B3ValueRep.cpp b/Source/JavaScriptCore/b3/B3ValueRep.cpp >index 45a1113e0de435469d93029ba48913b1e71d5da3..d4b47f14b0e89c08cd661b488b5e6eeb9440f195 100644 >--- a/Source/JavaScriptCore/b3/B3ValueRep.cpp >+++ b/Source/JavaScriptCore/b3/B3ValueRep.cpp >@@ -42,6 +42,7 @@ void ValueRep::addUsedRegistersTo(RegisterSet& set) const > case SomeRegister: > case SomeRegisterWithClobber: > case SomeEarlyRegister: >+ case SomeLateRegister: > case Constant: > return; > case LateRegister: >@@ -74,6 +75,7 @@ void ValueRep::dump(PrintStream& out) const > case SomeRegister: > case SomeRegisterWithClobber: > case SomeEarlyRegister: >+ case SomeLateRegister: > return; > case LateRegister: > case Register: >@@ -183,6 +185,9 @@ void printInternal(PrintStream& out, ValueRep::Kind kind) > case ValueRep::SomeEarlyRegister: > out.print("SomeEarlyRegister"); > return; >+ case ValueRep::SomeLateRegister: >+ out.print("SomeLateRegister"); >+ return; > case ValueRep::Register: > out.print("Register"); > return; >diff --git a/Source/JavaScriptCore/b3/B3ValueRep.h b/Source/JavaScriptCore/b3/B3ValueRep.h >index 463f27e40d64e1bfd2e212e368cbea2fbdf370b7..0ff39d9b8769c3af9794ca7429ea8fece959f9e9 100644 >--- a/Source/JavaScriptCore/b3/B3ValueRep.h >+++ b/Source/JavaScriptCore/b3/B3ValueRep.h >@@ -74,7 +74,11 @@ public: > // that the def happens before any of the effects of the stackmap. This is only valid for > // the result constraint of a Patchpoint. > SomeEarlyRegister, >- >+ >+ // As an input representation, this tells us that B3 should pick some register, but implies >+ // the use happens after any defs. This is only works for patchpoints. >+ SomeLateRegister, >+ > // As an input representation, this forces a particular register. As an output > // representation, this tells us what register B3 picked. > Register, >@@ -111,7 +115,7 @@ public: > ValueRep(Kind kind) > : m_kind(kind) > { >- ASSERT(kind == WarmAny || kind == ColdAny || kind == LateColdAny || kind == SomeRegister || kind == SomeRegisterWithClobber || kind == SomeEarlyRegister); >+ ASSERT(kind == WarmAny || kind == ColdAny || kind == LateColdAny || kind == SomeRegister || kind == SomeRegisterWithClobber || kind == SomeEarlyRegister || kind == SomeLateRegister); > } > > static ValueRep reg(Reg reg) >@@ -185,7 +189,7 @@ public: > > bool isAny() const { return kind() == WarmAny || kind() == ColdAny || kind() == LateColdAny; } > >- bool isReg() const { return kind() == Register || kind() == LateRegister; } >+ bool isReg() const { return kind() == Register || kind() == LateRegister || kind() == SomeLateRegister; } > > Reg reg() const > { >diff --git a/Source/JavaScriptCore/dfg/DFGOperations.cpp b/Source/JavaScriptCore/dfg/DFGOperations.cpp >index 9c70494388116511ee553c625bf491693aa92295..5cb276f3f19fcf81ebff3efdcd7be0153947e96b 100644 >--- a/Source/JavaScriptCore/dfg/DFGOperations.cpp >+++ b/Source/JavaScriptCore/dfg/DFGOperations.cpp >@@ -198,7 +198,7 @@ char* newTypedArrayWithSize(ExecState* exec, Structure* structure, int32_t size, > } > > if (vector) >- return bitwise_cast<char*>(ViewClass::createWithFastVector(exec, structure, size, vector)); >+ return bitwise_cast<char*>(ViewClass::createWithFastVector(exec, structure, size, untagArrayPtr(vector, size))); > > RELEASE_AND_RETURN(scope, bitwise_cast<char*>(ViewClass::create(exec, structure, size))); > } >diff --git a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp >index 68ef1bd932b9e553aeaa9dce78857a99e11917b0..7b96ec03e96439d108586506fa9e409626f9420e 100644 >--- a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp >+++ b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp >@@ -40,6 +40,7 @@ > #include "DFGSlowPathGenerator.h" > #include "DFGSnippetParams.h" > #include "DirectArguments.h" >+#include "DisallowMacroScratchRegisterUsage.h" > #include "JITAddGenerator.h" > #include "JITBitAndGenerator.h" > #include "JITBitOrGenerator.h" >@@ -2871,9 +2872,21 @@ JITCompiler::Jump SpeculativeJIT::jumpForTypedArrayIsNeuteredIfOutOfBounds(Node* > MacroAssembler::Address(base, JSArrayBufferView::offsetOfMode()), > TrustedImm32(WastefulTypedArray)); > >- JITCompiler::Jump hasNullVector = m_jit.branchTestPtr( >+ JITCompiler::Jump hasNullVector; >+#if !GIGACAGE_ENABLED && CPU(ARM64E) >+ { >+ GPRReg scratch = m_jit.scratchRegister(); >+ DisallowMacroScratchRegisterUsage disallowScratch(m_jit); >+ >+ m_jit.loadPtr(MacroAssembler::Address(base, JSArrayBufferView::offsetOfVector()), scratch); >+ m_jit.removeArrayPtrTag(scratch); >+ hasNullVector = m_jit.branchTestPtr(MacroAssembler::Zero, scratch); >+ } >+#else // !GIGACAGE_ENABLED && CPU(ARM64E) >+ hasNullVector = m_jit.branchTestPtr( > MacroAssembler::Zero, > MacroAssembler::Address(base, JSArrayBufferView::offsetOfVector())); >+#endif > speculationCheck(Uncountable, JSValueSource(), node, hasNullVector); > notWasteful.link(&m_jit); > } >@@ -6745,9 +6758,10 @@ void SpeculativeJIT::compileConstantStoragePointer(Node* node) > storageResult(storageGPR, node); > } > >-void SpeculativeJIT::cageTypedArrayStorage(GPRReg storageReg) >+void SpeculativeJIT::cageTypedArrayStorage(GPRReg baseReg, GPRReg storageReg) > { > #if GIGACAGE_ENABLED >+ UNUSED_PARAM(baseReg); > if (!Gigacage::shouldBeEnabled()) > return; > >@@ -6759,7 +6773,10 @@ void SpeculativeJIT::cageTypedArrayStorage(GPRReg storageReg) > } > > m_jit.cage(Gigacage::Primitive, storageReg); >+#elif CPU(ARM64E) >+ m_jit.untagArrayPtr(MacroAssembler::Address(baseReg, JSArrayBufferView::offsetOfLength()), storageReg); > #else >+ UNUSED_PARAM(baseReg); > UNUSED_PARAM(storageReg); > #endif > } >@@ -6783,16 +6800,17 @@ void SpeculativeJIT::compileGetIndexedPropertyStorage(Node* node) > > m_jit.loadPtr(MacroAssembler::Address(storageReg, StringImpl::dataOffset()), storageReg); > break; >- >- default: >+ >+ default: { > auto typedArrayType = node->arrayMode().typedArrayType(); > ASSERT_UNUSED(typedArrayType, isTypedView(typedArrayType)); > > m_jit.loadPtr(JITCompiler::Address(baseReg, JSArrayBufferView::offsetOfVector()), storageReg); >- cageTypedArrayStorage(storageReg); >+ cageTypedArrayStorage(baseReg, storageReg); > break; > } >- >+ } >+ > storageResult(storageReg, node); > } > >@@ -6817,17 +6835,24 @@ void SpeculativeJIT::compileGetTypedArrayByteOffset(Node* node) > TrustedImm32(WastefulTypedArray)); > > m_jit.loadPtr(MacroAssembler::Address(baseGPR, JSArrayBufferView::offsetOfVector()), vectorGPR); >+ >+ // FIXME: This should mask the PAC bits >+ // https://bugs.webkit.org/show_bug.cgi?id=197701 > JITCompiler::Jump nullVector = m_jit.branchTestPtr(JITCompiler::Zero, vectorGPR); > > m_jit.loadPtr(MacroAssembler::Address(baseGPR, JSObject::butterflyOffset()), dataGPR); > m_jit.cage(Gigacage::JSValue, dataGPR); > >- cageTypedArrayStorage(vectorGPR); >+ cageTypedArrayStorage(baseGPR, vectorGPR); > > m_jit.loadPtr(MacroAssembler::Address(dataGPR, Butterfly::offsetOfArrayBuffer()), arrayBufferGPR); > // FIXME: This needs caging. > // https://bugs.webkit.org/show_bug.cgi?id=175515 > m_jit.loadPtr(MacroAssembler::Address(arrayBufferGPR, ArrayBuffer::offsetOfData()), dataGPR); >+#if CPU(ARM64E) >+ m_jit.removeArrayPtrTag(dataGPR); >+#endif >+ > m_jit.subPtr(dataGPR, vectorGPR); > > JITCompiler::Jump done = m_jit.jump(); >@@ -9820,6 +9845,11 @@ void SpeculativeJIT::compileNewTypedArrayWithSize(Node* node) > MacroAssembler::BaseIndex(storageGPR, scratchGPR, MacroAssembler::TimesFour)); > m_jit.branchTest32(MacroAssembler::NonZero, scratchGPR).linkTo(loop, &m_jit); > done.link(&m_jit); >+#if !GIGACAGE_ENABLED && CPU(ARM64E) >+ // sizeGPR is still boxed as a number and there is no 32-bit variant of the PAC instructions. >+ m_jit.zeroExtend32ToPtr(sizeGPR, scratchGPR); >+ m_jit.tagArrayPtr(scratchGPR, storageGPR); >+#endif > > auto butterfly = TrustedImmPtr(nullptr); > emitAllocateJSObject<JSArrayBufferView>( >@@ -9841,7 +9871,7 @@ void SpeculativeJIT::compileNewTypedArrayWithSize(Node* node) > addSlowPathGenerator(slowPathCall( > slowCases, this, operationNewTypedArrayWithSizeForType(typedArrayType), > resultGPR, structure, sizeGPR, storageGPR)); >- >+ > cellResult(resultGPR, node); > } > >diff --git a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h >index 153cb77735e0c761cf95d757137f316da2b32c7d..9f1d893b87c15cea4559ed775b09941aa0101a3a 100644 >--- a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h >+++ b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h >@@ -1652,7 +1652,7 @@ public: > template<bool strict> > GPRReg fillSpeculateInt32Internal(Edge, DataFormat& returnFormat); > >- void cageTypedArrayStorage(GPRReg); >+ void cageTypedArrayStorage(GPRReg, GPRReg); > > void recordSetLocal( > VirtualRegister bytecodeReg, VirtualRegister machineReg, DataFormat format) >diff --git a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp >index b7feeb373c82abdf23695023f8a6935704e2be1a..2d62faa8c33ac9499f503fdb240476db63a61e92 100644 >--- a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp >+++ b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp >@@ -4682,7 +4682,7 @@ void SpeculativeJIT::compile(Node* node) > m_jit.branch64(MacroAssembler::AboveOrEqual, t2, t1)); > > m_jit.loadPtr(JITCompiler::Address(dataViewGPR, JSArrayBufferView::offsetOfVector()), t2); >- cageTypedArrayStorage(t2); >+ cageTypedArrayStorage(dataViewGPR, t2); > > m_jit.zeroExtend32ToPtr(indexGPR, t1); > auto baseIndex = JITCompiler::BaseIndex(t2, t1, MacroAssembler::TimesOne); >@@ -4878,7 +4878,7 @@ void SpeculativeJIT::compile(Node* node) > m_jit.branch64(MacroAssembler::AboveOrEqual, t2, t1)); > > m_jit.loadPtr(JITCompiler::Address(dataViewGPR, JSArrayBufferView::offsetOfVector()), t2); >- cageTypedArrayStorage(t2); >+ cageTypedArrayStorage(dataViewGPR, t2); > > m_jit.zeroExtend32ToPtr(indexGPR, t1); > auto baseIndex = JITCompiler::BaseIndex(t2, t1, MacroAssembler::TimesOne); >diff --git a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp >index 046dffd149553bde199a55e4a69bf42fef14c522..d72af41b41368c1c0f9e159040afd51cf5fb1602 100644 >--- a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp >+++ b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp >@@ -3883,7 +3883,7 @@ private: > > DFG_ASSERT(m_graph, m_node, isTypedView(m_node->arrayMode().typedArrayType()), m_node->arrayMode().typedArrayType()); > LValue vector = m_out.loadPtr(cell, m_heaps.JSArrayBufferView_vector); >- setStorage(caged(Gigacage::Primitive, vector)); >+ setStorage(caged(Gigacage::Primitive, vector, cell)); > } > > void compileCheckArray() >@@ -3927,14 +3927,15 @@ private: > > m_out.appendTo(notNull, continuation); > >- LValue butterflyPtr = caged(Gigacage::JSValue, m_out.loadPtr(basePtr, m_heaps.JSObject_butterfly)); >+ LValue butterflyPtr = caged(Gigacage::JSValue, m_out.loadPtr(basePtr, m_heaps.JSObject_butterfly), basePtr); > LValue arrayBufferPtr = m_out.loadPtr(butterflyPtr, m_heaps.Butterfly_arrayBuffer); > >- LValue vectorPtr = caged(Gigacage::Primitive, vector); >+ LValue vectorPtr = caged(Gigacage::Primitive, vector, basePtr); > > // FIXME: This needs caging. > // https://bugs.webkit.org/show_bug.cgi?id=175515 > LValue dataPtr = m_out.loadPtr(arrayBufferPtr, m_heaps.ArrayBuffer_data); >+ dataPtr = removeArrayPtrTag(dataPtr); > > ValueFromBlock wastefulOut = m_out.anchor(m_out.sub(vectorPtr, dataPtr)); > >@@ -6484,6 +6485,20 @@ private: > m_out.int64Zero, > m_heaps.typedArrayProperties); > >+#if !GIGACAGE_ENABLED && CPU(ARM64E) >+ { >+ LValue sizePtr = m_out.zeroExtPtr(size); >+ PatchpointValue* authenticate = m_out.patchpoint(pointerType()); >+ authenticate->appendSomeRegister(storage); >+ authenticate->append(sizePtr, B3::ValueRep(B3::ValueRep::SomeLateRegister)); >+ authenticate->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) { >+ jit.move(params[1].gpr(), params[0].gpr()); >+ jit.tagArrayPtr(params[2].gpr(), params[0].gpr()); >+ }); >+ storage = authenticate; >+ } >+#endif >+ > ValueFromBlock haveStorage = m_out.anchor(storage); > > LValue fastResultValue = >@@ -12702,7 +12717,7 @@ private: > indexToCheck = m_out.add(indexToCheck, m_out.constInt64(data.byteSize - 1)); > speculate(OutOfBounds, noValue(), nullptr, m_out.aboveOrEqual(indexToCheck, length)); > >- LValue vector = caged(Gigacage::Primitive, m_out.loadPtr(dataView, m_heaps.JSArrayBufferView_vector)); >+ LValue vector = caged(Gigacage::Primitive, m_out.loadPtr(dataView, m_heaps.JSArrayBufferView_vector), dataView); > > TypedPointer pointer(m_heaps.typedArrayProperties, m_out.add(vector, m_out.zeroExtPtr(index))); > >@@ -12861,7 +12876,7 @@ private: > RELEASE_ASSERT_NOT_REACHED(); > } > >- LValue vector = caged(Gigacage::Primitive, m_out.loadPtr(dataView, m_heaps.JSArrayBufferView_vector)); >+ LValue vector = caged(Gigacage::Primitive, m_out.loadPtr(dataView, m_heaps.JSArrayBufferView_vector), dataView); > TypedPointer pointer(m_heaps.typedArrayProperties, m_out.add(vector, m_out.zeroExtPtr(index))); > > if (data.isFloatingPoint) { >@@ -14108,10 +14123,42 @@ private: > m_out.appendTo(performStore, lastNext); > } > } >- >- LValue caged(Gigacage::Kind kind, LValue ptr) >+ >+ LValue untagArrayPtr(LValue ptr, LValue size) >+ { >+#if CPU(ARM64E) >+ PatchpointValue* authenticate = m_out.patchpoint(pointerType()); >+ authenticate->appendSomeRegister(ptr); >+ authenticate->append(size, B3::ValueRep(B3::ValueRep::SomeLateRegister)); >+ authenticate->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) { >+ jit.move(params[1].gpr(), params[0].gpr()); >+ jit.untagArrayPtr(params[2].gpr(), params[0].gpr()); >+ }); >+ return authenticate; >+#else >+ UNUSED_PARAM(size); >+ return ptr; >+#endif >+ } >+ >+ LValue removeArrayPtrTag(LValue ptr) >+ { >+#if CPU(ARM64E) >+ PatchpointValue* authenticate = m_out.patchpoint(pointerType()); >+ authenticate->appendSomeRegister(ptr); >+ authenticate->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) { >+ jit.move(params[1].gpr(), params[0].gpr()); >+ jit.removeArrayPtrTag(params[0].gpr()); >+ }); >+ return authenticate; >+#endif >+ return ptr; >+ } >+ >+ LValue caged(Gigacage::Kind kind, LValue ptr, LValue base) > { > #if GIGACAGE_ENABLED >+ UNUSED_PARAM(base); > if (!Gigacage::isEnabled(kind)) > return ptr; > >@@ -14140,8 +14187,16 @@ private: > // and possibly other smart things if we want to be able to remove this opaque. > // https://bugs.webkit.org/show_bug.cgi?id=175493 > return m_out.opaque(result); >+#elif CPU(ARM64E) >+ if (kind == Gigacage::Primitive) { >+ LValue size = m_out.load32(base, m_heaps.JSArrayBufferView_length); >+ return untagArrayPtr(ptr, size); >+ } >+ >+ return ptr; > #else > UNUSED_PARAM(kind); >+ UNUSED_PARAM(base); > return ptr; > #endif > } >@@ -16555,6 +16610,9 @@ private: > > LBasicBlock lastNext = m_out.appendTo(isWasteful, continuation); > LValue vector = m_out.loadPtr(base, m_heaps.JSArrayBufferView_vector); >+ // FIXME: We could probably make this a mask. >+ // https://bugs.webkit.org/show_bug.cgi?id=197701 >+ vector = removeArrayPtrTag(vector); > speculate(Uncountable, jsValueValue(vector), m_node, m_out.isZero64(vector)); > m_out.jump(continuation); > >diff --git a/Source/JavaScriptCore/heap/ConservativeRoots.cpp b/Source/JavaScriptCore/heap/ConservativeRoots.cpp >index a420fe8e625c993ed594d0acf58aecb76c8c995e..2a5589241c4f44b2d349484d7b45ea2ba211802f 100644 >--- a/Source/JavaScriptCore/heap/ConservativeRoots.cpp >+++ b/Source/JavaScriptCore/heap/ConservativeRoots.cpp >@@ -68,6 +68,7 @@ void ConservativeRoots::grow() > template<typename MarkHook> > inline void ConservativeRoots::genericAddPointer(void* p, HeapVersion markingVersion, HeapVersion newlyAllocatedVersion, TinyBloomFilter filter, MarkHook& markHook) > { >+ p = removeArrayPtrTag(p); > markHook.mark(p); > > HeapUtil::findGCObjectPointersForMarking( >diff --git a/Source/JavaScriptCore/jit/AssemblyHelpers.h b/Source/JavaScriptCore/jit/AssemblyHelpers.h >index 7602b2a93dab7a17b29d5b5eb832c15da253663e..d9268e83691421ffedc1541217c867f351edb8d4 100644 >--- a/Source/JavaScriptCore/jit/AssemblyHelpers.h >+++ b/Source/JavaScriptCore/jit/AssemblyHelpers.h >@@ -1569,7 +1569,7 @@ public: > #endif > } > >- void cageConditionally(Gigacage::Kind kind, GPRReg storage, GPRReg scratch) >+ void cageConditionally(Gigacage::Kind kind, GPRReg storage, GPRReg scratchOrLength) > { > #if GIGACAGE_ENABLED > if (!Gigacage::isEnabled(kind)) >@@ -1578,15 +1578,18 @@ public: > if (kind != Gigacage::Primitive || Gigacage::isDisablingPrimitiveGigacageDisabled()) > return cage(kind, storage); > >- loadPtr(&Gigacage::basePtr(kind), scratch); >- Jump done = branchTestPtr(Zero, scratch); >+ loadPtr(&Gigacage::basePtr(kind), scratchOrLength); >+ Jump done = branchTestPtr(Zero, scratchOrLength); > andPtr(TrustedImmPtr(Gigacage::mask(kind)), storage); >- addPtr(scratch, storage); >+ addPtr(scratchOrLength, storage); > done.link(this); >+#elif CPU(ARM64E) >+ if (kind == Gigacage::Primitive) >+ untagArrayPtr(scratchOrLength, storage); > #else > UNUSED_PARAM(kind); > UNUSED_PARAM(storage); >- UNUSED_PARAM(scratch); >+ UNUSED_PARAM(scratchOrLength); > #endif > } > >diff --git a/Source/JavaScriptCore/jit/IntrinsicEmitter.cpp b/Source/JavaScriptCore/jit/IntrinsicEmitter.cpp >index cae39e935cb93ed97618370ed71b9945b55425d0..1a6b432fdbdbff763a136003afd386c564f214ab 100644 >--- a/Source/JavaScriptCore/jit/IntrinsicEmitter.cpp >+++ b/Source/JavaScriptCore/jit/IntrinsicEmitter.cpp >@@ -114,8 +114,14 @@ void IntrinsicGetterAccessCase::emitIntrinsicGetter(AccessGenerationState& state > > jit.loadPtr(MacroAssembler::Address(baseGPR, JSObject::butterflyOffset()), scratchGPR); > jit.loadPtr(MacroAssembler::Address(baseGPR, JSArrayBufferView::offsetOfVector()), valueGPR); >+#if CPU(ARM64E) >+ jit.removeArrayPtrTag(valueGPR); >+#endif > jit.loadPtr(MacroAssembler::Address(scratchGPR, Butterfly::offsetOfArrayBuffer()), scratchGPR); > jit.loadPtr(MacroAssembler::Address(scratchGPR, ArrayBuffer::offsetOfData()), scratchGPR); >+#if CPU(ARM64E) >+ jit.removeArrayPtrTag(scratchGPR); >+#endif > jit.subPtr(scratchGPR, valueGPR); > > CCallHelpers::Jump done = jit.jump(); >diff --git a/Source/JavaScriptCore/jit/JITPropertyAccess.cpp b/Source/JavaScriptCore/jit/JITPropertyAccess.cpp >index 798f173ccab6a4d14a51b345e41a486c3fde3aff..9d621481f77474efb831bd4e5f1f58229e332556 100644 >--- a/Source/JavaScriptCore/jit/JITPropertyAccess.cpp >+++ b/Source/JavaScriptCore/jit/JITPropertyAccess.cpp >@@ -1589,7 +1589,7 @@ JIT::JumpList JIT::emitDirectArgumentsGetByVal(const Instruction*, PatchableJump > load32(Address(base, DirectArguments::offsetOfLength()), scratch2); > slowCases.append(branch32(AboveOrEqual, property, scratch2)); > slowCases.append(branchTestPtr(NonZero, Address(base, DirectArguments::offsetOfMappedArguments()))); >- >+ > loadValue(BaseIndex(base, property, TimesEight, DirectArguments::storageOffset()), result); > > return slowCases; >@@ -1669,7 +1669,8 @@ JIT::JumpList JIT::emitIntTypedArrayGetByVal(const Instruction*, PatchableJump& > > load8(Address(base, JSCell::typeInfoTypeOffset()), scratch); > badType = patchableBranch32(NotEqual, scratch, TrustedImm32(typeForTypedArrayType(type))); >- slowCases.append(branch32(AboveOrEqual, property, Address(base, JSArrayBufferView::offsetOfLength()))); >+ load32(Address(base, JSArrayBufferView::offsetOfLength()), scratch2); >+ slowCases.append(branch32(AboveOrEqual, property, scratch2)); > loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), scratch); > cageConditionally(Gigacage::Primitive, scratch, scratch2); > >@@ -1732,7 +1733,8 @@ JIT::JumpList JIT::emitFloatTypedArrayGetByVal(const Instruction*, PatchableJump > > load8(Address(base, JSCell::typeInfoTypeOffset()), scratch); > badType = patchableBranch32(NotEqual, scratch, TrustedImm32(typeForTypedArrayType(type))); >- slowCases.append(branch32(AboveOrEqual, property, Address(base, JSArrayBufferView::offsetOfLength()))); >+ load32(Address(base, JSArrayBufferView::offsetOfLength()), scratch2); >+ slowCases.append(branch32(AboveOrEqual, property, scratch2)); > loadPtr(Address(base, JSArrayBufferView::offsetOfVector()), scratch); > cageConditionally(Gigacage::Primitive, scratch, scratch2); > >@@ -1782,7 +1784,8 @@ JIT::JumpList JIT::emitIntTypedArrayPutByVal(Op bytecode, PatchableJump& badType > > load8(Address(base, JSCell::typeInfoTypeOffset()), earlyScratch); > badType = patchableBranch32(NotEqual, earlyScratch, TrustedImm32(typeForTypedArrayType(type))); >- Jump inBounds = branch32(Below, property, Address(base, JSArrayBufferView::offsetOfLength())); >+ load32(Address(base, JSArrayBufferView::offsetOfLength()), lateScratch2); >+ Jump inBounds = branch32(Below, property, lateScratch2); > emitArrayProfileOutOfBoundsSpecialCase(profile); > slowCases.append(jump()); > inBounds.link(this); >@@ -1857,7 +1860,8 @@ JIT::JumpList JIT::emitFloatTypedArrayPutByVal(Op bytecode, PatchableJump& badTy > > load8(Address(base, JSCell::typeInfoTypeOffset()), earlyScratch); > badType = patchableBranch32(NotEqual, earlyScratch, TrustedImm32(typeForTypedArrayType(type))); >- Jump inBounds = branch32(Below, property, Address(base, JSArrayBufferView::offsetOfLength())); >+ load32(Address(base, JSArrayBufferView::offsetOfLength()), lateScratch2); >+ Jump inBounds = branch32(Below, property, lateScratch2); > emitArrayProfileOutOfBoundsSpecialCase(profile); > slowCases.append(jump()); > inBounds.link(this); >diff --git a/Source/JavaScriptCore/jit/PolymorphicCallStubRoutine.cpp b/Source/JavaScriptCore/jit/PolymorphicCallStubRoutine.cpp >index 7cf74b164d3cbb06428a73432ce774245d6e18d0..91bb5856d178beaa4b9f77917a0cc35d2bd9c116 100644 >--- a/Source/JavaScriptCore/jit/PolymorphicCallStubRoutine.cpp >+++ b/Source/JavaScriptCore/jit/PolymorphicCallStubRoutine.cpp >@@ -57,9 +57,6 @@ void PolymorphicCallNode::unlink(VM& vm) > > void PolymorphicCallNode::clearCallLinkInfo() > { >- if (Options::dumpDisassembly()) >- dataLog("Clearing call link info for polymorphic call at ", m_callLinkInfo->callReturnLocation(), ", ", m_callLinkInfo->codeOrigin(), "\n"); >- > m_callLinkInfo = nullptr; > } > >diff --git a/Source/JavaScriptCore/jit/RegisterSet.h b/Source/JavaScriptCore/jit/RegisterSet.h >index ae4232376358da6b8b9c661932b73b1c964d96d7..8c01842d6949ea48a62ea36a4ebf0695ffe68cd6 100644 >--- a/Source/JavaScriptCore/jit/RegisterSet.h >+++ b/Source/JavaScriptCore/jit/RegisterSet.h >@@ -84,7 +84,9 @@ public: > set(regs.tagGPR(), value); > set(regs.payloadGPR(), value); > } >- >+ >+ void set(const RegisterSet& other, bool value = true) { value ? merge(other) : exclude(other); } >+ > void clear(Reg reg) > { > ASSERT(!!reg); >diff --git a/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm b/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm >index 01400a52f5c468ae8eb170c82289dd7ff91bb537..6aaf0dd10c3eb8af6b277713419ac40e3d878397 100644 >--- a/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm >+++ b/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm >@@ -422,20 +422,29 @@ macro checkSwitchToJITForLoop() > end) > end > >-macro uncage(basePtr, mask, ptr, scratch) >- if GIGACAGE_ENABLED and not C_LOOP >- loadp basePtr, scratch >- btpz scratch, .done >+macro uncage(basePtr, mask, ptr, scratchOrLength) >+ if GIGACAGE_ENABLED and not (C_LOOP or C_LOOP_WIN) >+ loadp basePtr, scratchOrLength >+ btpz scratchOrLength, .done > andp mask, ptr >- addp scratch, ptr >- .done: >+ addp scratchOrLength, ptr >+ .done: >+ end >+end >+ >+macro loadCagedPrimitive(source, dest, scratchOrLength) >+ loadp source, dest >+ if GIGACAGE_ENABLED >+ uncage(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, dest, scratchOrLength) >+ elsif ARM64E >+ untagArrayPtr scratchOrLength, dest > end > end > >-macro loadCaged(basePtr, mask, source, dest, scratch) >+macro loadCagedJSValue(source, dest, scratchOrLength) > loadp source, dest >- uncage(basePtr, mask, dest, scratch) >- end >+ uncage(_g_gigacageBasePtrs + Gigacage::BasePtrs::jsValue, constexpr Gigacage::jsValueGigacageMask, dest, scratchOrLength) >+end > > macro loadVariable(get, fieldName, valueReg) > get(fieldName, valueReg) >@@ -1335,7 +1344,7 @@ llintOpWithMetadata(op_get_by_id, OpGetById, macro (size, get, dispatch, metadat > arrayProfile(OpGetById::Metadata::m_modeMetadata.arrayLengthMode.arrayProfile, t0, t2, t5) > btiz t0, IsArray, .opGetByIdSlow > btiz t0, IndexingShapeMask, .opGetByIdSlow >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::jsValue, constexpr Gigacage::jsValueGigacageMask, JSObject::m_butterfly[t3], t0, t1) >+ loadCagedJSValue(JSObject::m_butterfly[t3], t0, t1) > loadi -sizeof IndexingHeader + IndexingHeader::u.lengths.publicLength[t0], t0 > bilt t0, 0, .opGetByIdSlow > orq tagTypeNumber, t0 >@@ -1458,7 +1467,7 @@ llintOpWithMetadata(op_get_by_val, OpGetByVal, macro (size, get, dispatch, metad > loadConstantOrVariableInt32(size, t3, t1, .opGetByValSlow) > sxi2q t1, t1 > >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::jsValue, constexpr Gigacage::jsValueGigacageMask, JSObject::m_butterfly[t0], t3, tagTypeNumber) >+ loadCagedJSValue(JSObject::m_butterfly[t0], t3, tagTypeNumber) > move TagTypeNumber, tagTypeNumber > > andi IndexingShapeMask, t2 >@@ -1502,7 +1511,17 @@ llintOpWithMetadata(op_get_by_val, OpGetByVal, macro (size, get, dispatch, metad > biaeq t2, NumberOfTypedArrayTypesExcludingDataView, .opGetByValSlow > > # Sweet, now we know that we have a typed array. Do some basic things now. >- biaeq t1, JSArrayBufferView::m_length[t0], .opGetByValSlow >+ >+ if ARM64E >+ const scratchOrLength = t6 >+ loadi JSArrayBufferView::m_length[t0], scratchOrLength >+ biaeq t1, scratchOrLength, .opGetByValSlow >+ else >+ const scratchOrLength = t0 >+ biaeq t1, JSArrayBufferView::m_length[t0], .opGetByValSlow >+ end >+ >+ loadCagedPrimitive(JSArrayBufferView::m_vector[t0], t3, scratchOrLength) > > # Now bisect through the various types: > # Int8ArrayType, >@@ -1524,7 +1543,6 @@ llintOpWithMetadata(op_get_by_val, OpGetByVal, macro (size, get, dispatch, metad > bia t2, Int8ArrayType - FirstTypedArrayType, .opGetByValUint8ArrayOrUint8ClampedArray > > # We have Int8ArrayType. >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, JSArrayBufferView::m_vector[t0], t3, t2) > loadbsi [t3, t1], t0 > finishIntGetByVal(t0, t1) > >@@ -1532,13 +1550,11 @@ llintOpWithMetadata(op_get_by_val, OpGetByVal, macro (size, get, dispatch, metad > bia t2, Uint8ArrayType - FirstTypedArrayType, .opGetByValUint8ClampedArray > > # We have Uint8ArrayType. >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, JSArrayBufferView::m_vector[t0], t3, t2) > loadb [t3, t1], t0 > finishIntGetByVal(t0, t1) > > .opGetByValUint8ClampedArray: > # We have Uint8ClampedArrayType. >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, JSArrayBufferView::m_vector[t0], t3, t2) > loadb [t3, t1], t0 > finishIntGetByVal(t0, t1) > >@@ -1547,13 +1563,11 @@ llintOpWithMetadata(op_get_by_val, OpGetByVal, macro (size, get, dispatch, metad > bia t2, Int16ArrayType - FirstTypedArrayType, .opGetByValUint16Array > > # We have Int16ArrayType. >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, JSArrayBufferView::m_vector[t0], t3, t2) > loadhsi [t3, t1, 2], t0 > finishIntGetByVal(t0, t1) > > .opGetByValUint16Array: > # We have Uint16ArrayType. >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, JSArrayBufferView::m_vector[t0], t3, t2) > loadh [t3, t1, 2], t0 > finishIntGetByVal(t0, t1) > >@@ -1565,13 +1579,11 @@ llintOpWithMetadata(op_get_by_val, OpGetByVal, macro (size, get, dispatch, metad > bia t2, Int32ArrayType - FirstTypedArrayType, .opGetByValUint32Array > > # We have Int32ArrayType. >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, JSArrayBufferView::m_vector[t0], t3, t2) > loadi [t3, t1, 4], t0 > finishIntGetByVal(t0, t1) > > .opGetByValUint32Array: > # We have Uint32ArrayType. >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, JSArrayBufferView::m_vector[t0], t3, t2) > # This is the hardest part because of large unsigned values. > loadi [t3, t1, 4], t0 > bilt t0, 0, .opGetByValSlow # This case is still awkward to implement in LLInt. >@@ -1583,7 +1595,6 @@ llintOpWithMetadata(op_get_by_val, OpGetByVal, macro (size, get, dispatch, metad > bieq t2, Float32ArrayType - FirstTypedArrayType, .opGetByValSlow > > # We have Float64ArrayType. >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::primitive, constexpr Gigacage::primitiveGigacageMask, JSArrayBufferView::m_vector[t0], t3, t2) > loadd [t3, t1, 8], ft0 > bdnequn ft0, ft0, .opGetByValSlow > finishDoubleGetByVal(ft0, t0, t1) >@@ -1619,7 +1630,7 @@ macro putByValOp(opcodeName, opcodeStruct) > get(m_property, t0) > loadConstantOrVariableInt32(size, t0, t3, .opPutByValSlow) > sxi2q t3, t3 >- loadCaged(_g_gigacageBasePtrs + Gigacage::BasePtrs::jsValue, constexpr Gigacage::jsValueGigacageMask, JSObject::m_butterfly[t1], t0, tagTypeNumber) >+ loadCagedJSValue(JSObject::m_butterfly[t1], t0, tagTypeNumber) > move TagTypeNumber, tagTypeNumber > btinz t2, CopyOnWrite, .opPutByValSlow > andi IndexingShapeMask, t2 >diff --git a/Source/JavaScriptCore/runtime/ArrayBuffer.cpp b/Source/JavaScriptCore/runtime/ArrayBuffer.cpp >index 8f8556b897ba70ac7e9db38e0f8ab9c045ad3905..671bdb77132fa69f1e14f75d3bd766bb614c8a6a 100644 >--- a/Source/JavaScriptCore/runtime/ArrayBuffer.cpp >+++ b/Source/JavaScriptCore/runtime/ArrayBuffer.cpp >@@ -33,15 +33,17 @@ > > namespace JSC { > >-SharedArrayBufferContents::SharedArrayBufferContents(void* data, ArrayBufferDestructorFunction&& destructor) >- : m_data(data) >+SharedArrayBufferContents::SharedArrayBufferContents(void* data, unsigned size, ArrayBufferDestructorFunction&& destructor) >+ : m_data(data, size) > , m_destructor(WTFMove(destructor)) >+ , m_sizeInBytes(size) > { > } > > SharedArrayBufferContents::~SharedArrayBufferContents() > { >- m_destructor(m_data.getMayBeNull()); >+ // FIXME: we shouldn't use getUnsafe here https://bugs.webkit.org/show_bug.cgi?id=197698 >+ m_destructor(m_data.getUnsafe()); > } > > ArrayBufferContents::ArrayBufferContents() >@@ -56,7 +58,7 @@ ArrayBufferContents::ArrayBufferContents(ArrayBufferContents&& other) > } > > ArrayBufferContents::ArrayBufferContents(void* data, unsigned sizeInBytes, ArrayBufferDestructorFunction&& destructor) >- : m_data(data) >+ : m_data(data, sizeInBytes) > , m_sizeInBytes(sizeInBytes) > { > RELEASE_ASSERT(m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE); >@@ -82,7 +84,8 @@ void ArrayBufferContents::clear() > > void ArrayBufferContents::destroy() > { >- m_destructor(m_data.getMayBeNull()); >+ // FIXME: We shouldn't use getUnsafe here: https://bugs.webkit.org/show_bug.cgi?id=197698 >+ m_destructor(m_data.getUnsafe()); > } > > void ArrayBufferContents::reset() >@@ -103,26 +106,29 @@ void ArrayBufferContents::tryAllocate(unsigned numElements, unsigned elementByte > return; > } > } >- size_t size = static_cast<size_t>(numElements) * static_cast<size_t>(elementByteSize); >- if (!size) >- size = 1; // Make sure malloc actually allocates something, but not too much. We use null to mean that the buffer is neutered. >- m_data = Gigacage::tryMalloc(Gigacage::Primitive, size); >- if (!m_data) { >+ size_t sizeInBytes = static_cast<size_t>(numElements) * static_cast<size_t>(elementByteSize); >+ size_t allocationSize = sizeInBytes; >+ if (!allocationSize) >+ allocationSize = 1; // Make sure malloc actually allocates something, but not too much. We use null to mean that the buffer is neutered. >+ >+ void* data = Gigacage::tryMalloc(Gigacage::Primitive, allocationSize); >+ m_data = DataType(data, sizeInBytes); >+ if (!data) { > reset(); > return; > } > > if (policy == ZeroInitialize) >- memset(m_data.get(), 0, size); >+ memset(data, 0, allocationSize); > >- m_sizeInBytes = numElements * elementByteSize; >+ m_sizeInBytes = sizeInBytes; > RELEASE_ASSERT(m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE); > m_destructor = [] (void* p) { Gigacage::free(Gigacage::Primitive, p); }; > } > > void ArrayBufferContents::makeShared() > { >- m_shared = adoptRef(new SharedArrayBufferContents(m_data.getMayBeNull(), WTFMove(m_destructor))); >+ m_shared = adoptRef(new SharedArrayBufferContents(data(), sizeInBytes(), WTFMove(m_destructor))); > m_destructor = [] (void*) { }; > } > >@@ -143,7 +149,7 @@ void ArrayBufferContents::copyTo(ArrayBufferContents& other) > other.tryAllocate(m_sizeInBytes, sizeof(char), ArrayBufferContents::DontInitialize); > if (!other.m_data) > return; >- memcpy(other.m_data.get(), m_data.get(), m_sizeInBytes); >+ memcpy(other.data(), data(), m_sizeInBytes); > other.m_sizeInBytes = m_sizeInBytes; > RELEASE_ASSERT(other.m_sizeInBytes <= MAX_ARRAY_BUFFER_SIZE); > } >diff --git a/Source/JavaScriptCore/runtime/ArrayBuffer.h b/Source/JavaScriptCore/runtime/ArrayBuffer.h >index baf2b856a21004954ba5c43bf5eb1cd7b6a4404c..7c05bbc5d24d41bdf1e23b7ec189d22694fe300e 100644 >--- a/Source/JavaScriptCore/runtime/ArrayBuffer.h >+++ b/Source/JavaScriptCore/runtime/ArrayBuffer.h >@@ -48,14 +48,16 @@ typedef Function<void(void*)> ArrayBufferDestructorFunction; > > class SharedArrayBufferContents : public ThreadSafeRefCounted<SharedArrayBufferContents> { > public: >- SharedArrayBufferContents(void* data, ArrayBufferDestructorFunction&&); >+ SharedArrayBufferContents(void* data, unsigned size, ArrayBufferDestructorFunction&&); > ~SharedArrayBufferContents(); > >- void* data() const { return m_data.getMayBeNull(); } >+ void* data() const { return m_data.getMayBeNull(m_sizeInBytes); } > > private: >- CagedPtr<Gigacage::Primitive, void> m_data; >+ using DataType = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>; >+ DataType m_data; > ArrayBufferDestructorFunction m_destructor; >+ unsigned m_sizeInBytes; > }; > > class ArrayBufferContents { >@@ -73,7 +75,7 @@ public: > > explicit operator bool() { return !!m_data; } > >- void* data() const { return m_data.getMayBeNull(); } >+ void* data() const { return m_data.getMayBeNull(sizeInBytes()); } > unsigned sizeInBytes() const { return m_sizeInBytes; } > > bool isShared() const { return m_shared; } >@@ -98,7 +100,8 @@ private: > > ArrayBufferDestructorFunction m_destructor; > RefPtr<SharedArrayBufferContents> m_shared; >- CagedPtr<Gigacage::Primitive, void> m_data; >+ using DataType = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>; >+ DataType m_data; > unsigned m_sizeInBytes; > }; > >@@ -174,17 +177,17 @@ public: > > void* ArrayBuffer::data() > { >- return m_contents.m_data.getMayBeNull(); >+ return m_contents.data(); > } > > const void* ArrayBuffer::data() const > { >- return m_contents.m_data.getMayBeNull(); >+ return m_contents.data(); > } > > unsigned ArrayBuffer::byteLength() const > { >- return m_contents.m_sizeInBytes; >+ return m_contents.sizeInBytes(); > } > > bool ArrayBuffer::isShared() const >diff --git a/Source/JavaScriptCore/runtime/ArrayBufferView.cpp b/Source/JavaScriptCore/runtime/ArrayBufferView.cpp >index 9fed7c786b6be97a31e5943526cbbdbeb6050da7..b795fe4f55a3ecd23146e77d5fdfb8c7262fdc1c 100644 >--- a/Source/JavaScriptCore/runtime/ArrayBufferView.cpp >+++ b/Source/JavaScriptCore/runtime/ArrayBufferView.cpp >@@ -25,17 +25,22 @@ > > #include "config.h" > #include "ArrayBufferView.h" >+#include <wtf/CheckedArithmetic.h> > > namespace JSC { > > ArrayBufferView::ArrayBufferView( >- RefPtr<ArrayBuffer>&& buffer, >- unsigned byteOffset) >+ RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned byteLength) > : m_byteOffset(byteOffset) > , m_isNeuterable(true) >+ , m_byteLength(byteLength) > , m_buffer(WTFMove(buffer)) > { >- m_baseAddress = m_buffer ? (static_cast<char*>(m_buffer->data()) + m_byteOffset) : 0; >+ Checked<unsigned, CrashOnOverflow> length(byteOffset); >+ length += byteLength; >+ RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(length <= m_buffer->byteLength()); >+ if (m_buffer) >+ m_baseAddress = BaseAddress(static_cast<char*>(m_buffer->data()) + m_byteOffset, byteLength); > } > > ArrayBufferView::~ArrayBufferView() >diff --git a/Source/JavaScriptCore/runtime/ArrayBufferView.h b/Source/JavaScriptCore/runtime/ArrayBufferView.h >index 754784e864fcc3377b164a8d1af87a7542e7e619..39fe6bbff566b9159ba637193c683a3bcc2dc1ee 100644 >--- a/Source/JavaScriptCore/runtime/ArrayBufferView.h >+++ b/Source/JavaScriptCore/runtime/ArrayBufferView.h >@@ -71,8 +71,8 @@ public: > void* baseAddress() const > { > if (isNeutered()) >- return 0; >- return m_baseAddress.getMayBeNull(); >+ return nullptr; >+ return m_baseAddress.getMayBeNull(byteLength()); > } > > void* data() const { return baseAddress(); } >@@ -84,7 +84,7 @@ public: > return m_byteOffset; > } > >- virtual unsigned byteLength() const = 0; >+ unsigned byteLength() const { return m_byteLength; } > > JS_EXPORT_PRIVATE void setNeuterable(bool flag); > bool isNeuterable() const { return m_isNeuterable; } >@@ -113,13 +113,12 @@ public: > virtual JSArrayBufferView* wrap(ExecState*, JSGlobalObject*) = 0; > > protected: >- JS_EXPORT_PRIVATE ArrayBufferView(RefPtr<ArrayBuffer>&&, unsigned byteOffset); >+ JS_EXPORT_PRIVATE ArrayBufferView(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned byteLength); > > inline bool setImpl(ArrayBufferView*, unsigned byteOffset); > >- // Caller passes in bufferByteLength to avoid a virtual function call. >- inline bool setRangeImpl(const void* data, size_t dataByteLength, unsigned byteOffset, unsigned bufferByteLength); >- inline bool getRangeImpl(void* destination, size_t dataByteLength, unsigned byteOffset, unsigned bufferByteLength); >+ inline bool setRangeImpl(const void* data, size_t dataByteLength, unsigned byteOffset); >+ inline bool getRangeImpl(void* destination, size_t dataByteLength, unsigned byteOffset); > > inline bool zeroRangeImpl(unsigned byteOffset, size_t rangeByteLength); > >@@ -150,9 +149,11 @@ protected: > > unsigned m_byteOffset : 31; > bool m_isNeuterable : 1; >+ unsigned m_byteLength; > >+ using BaseAddress = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>; > // This is the address of the ArrayBuffer's storage, plus the byte offset. >- CagedPtr<Gigacage::Primitive, void> m_baseAddress; >+ BaseAddress m_baseAddress; > > private: > friend class ArrayBuffer; >@@ -173,12 +174,10 @@ bool ArrayBufferView::setImpl(ArrayBufferView* array, unsigned byteOffset) > return true; > } > >-bool ArrayBufferView::setRangeImpl(const void* data, size_t dataByteLength, unsigned byteOffset, unsigned bufferByteLength) >+bool ArrayBufferView::setRangeImpl(const void* data, size_t dataByteLength, unsigned byteOffset) > { >- // Do not replace with RELEASE_ASSERT; we want to avoid the virtual byteLength() function call in release. >- ASSERT_WITH_SECURITY_IMPLICATION(bufferByteLength == byteLength()); >- if (byteOffset > bufferByteLength >- || byteOffset + dataByteLength > bufferByteLength >+ if (byteOffset > byteLength() >+ || byteOffset + dataByteLength > byteLength() > || byteOffset + dataByteLength < byteOffset) { > // Out of range offset or overflow > return false; >@@ -189,12 +188,10 @@ bool ArrayBufferView::setRangeImpl(const void* data, size_t dataByteLength, unsi > return true; > } > >-bool ArrayBufferView::getRangeImpl(void* destination, size_t dataByteLength, unsigned byteOffset, unsigned bufferByteLength) >+bool ArrayBufferView::getRangeImpl(void* destination, size_t dataByteLength, unsigned byteOffset) > { >- // Do not replace with RELEASE_ASSERT; we want to avoid the virtual byteLength() function call in release. >- ASSERT_WITH_SECURITY_IMPLICATION(bufferByteLength == byteLength()); >- if (byteOffset > bufferByteLength >- || byteOffset + dataByteLength > bufferByteLength >+ if (byteOffset > byteLength() >+ || byteOffset + dataByteLength > byteLength() > || byteOffset + dataByteLength < byteOffset) { > // Out of range offset or overflow > return false; >diff --git a/Source/JavaScriptCore/runtime/CachedTypes.cpp b/Source/JavaScriptCore/runtime/CachedTypes.cpp >index b1623695cb63e4e9d96376f1c241f736f9f9be75..03cf164fbccc011e8c85f017772408b1c1154ebb 100644 >--- a/Source/JavaScriptCore/runtime/CachedTypes.cpp >+++ b/Source/JavaScriptCore/runtime/CachedTypes.cpp >@@ -1088,13 +1088,13 @@ public: > void encode(Encoder& encoder, const ScopedArgumentsTable& scopedArgumentsTable) > { > m_length = scopedArgumentsTable.m_length; >- m_arguments.encode(encoder, scopedArgumentsTable.m_arguments.get(), m_length); >+ m_arguments.encode(encoder, scopedArgumentsTable.m_arguments.get(m_length), m_length); > } > > ScopedArgumentsTable* decode(Decoder& decoder) const > { > ScopedArgumentsTable* scopedArgumentsTable = ScopedArgumentsTable::create(decoder.vm(), m_length); >- m_arguments.decode(decoder, scopedArgumentsTable->m_arguments.get(), m_length); >+ m_arguments.decode(decoder, scopedArgumentsTable->m_arguments.get(m_length), m_length); > return scopedArgumentsTable; > } > >diff --git a/Source/JavaScriptCore/runtime/CagedBarrierPtr.h b/Source/JavaScriptCore/runtime/CagedBarrierPtr.h >index 918ddf2f3f7d3d3b862b281dc6dc690751639913..425a87c668e3ced8df727fc9c6c914f7ffb3591f 100644 >--- a/Source/JavaScriptCore/runtime/CagedBarrierPtr.h >+++ b/Source/JavaScriptCore/runtime/CagedBarrierPtr.h >@@ -35,87 +35,41 @@ class VM; > > // This is a convenient combo of AuxiliaryBarrier and CagedPtr. > >-template<Gigacage::Kind passedKind, typename T> >+template<Gigacage::Kind passedKind, typename T, bool shouldTag = false> > class CagedBarrierPtr { > public: > static constexpr Gigacage::Kind kind = passedKind; >- typedef T Type; >+ using Type = T; >+ using CagedType = CagedPtr<kind, Type, shouldTag>; > >- CagedBarrierPtr() { } >+ CagedBarrierPtr() = default; > > template<typename U> >- CagedBarrierPtr(VM& vm, JSCell* cell, U&& value) >+ CagedBarrierPtr(VM& vm, JSCell* cell, U&& value, unsigned size) > { >- m_barrier.set(vm, cell, std::forward<U>(value)); >+ m_barrier.set(vm, cell, CagedType(std::forward<U>(value), size)); > } > > void clear() { m_barrier.clear(); } > > template<typename U> >- void set(VM& vm, JSCell* cell, U&& value) >+ void set(VM& vm, JSCell* cell, U&& value, unsigned size) > { >- m_barrier.set(vm, cell, std::forward<U>(value)); >+ m_barrier.set(vm, cell, CagedType(std::forward<U>(value), size)); > } > >- T* get() const { return m_barrier.get().get(); } >- T* getMayBeNull() const { return m_barrier.get().getMayBeNull(); } >- >- bool operator==(const CagedBarrierPtr& other) const >- { >- return getMayBeNull() == other.getMayBeNull(); >- } >- >- bool operator!=(const CagedBarrierPtr& other) const >- { >- return !(*this == other); >- } >- >- explicit operator bool() const >- { >- return *this != CagedBarrierPtr(); >- } >- >- template<typename U> >- void setWithoutBarrier(U&& value) { m_barrier.setWithoutBarrier(std::forward<U>(value)); } >- >- T& operator*() const { return *get(); } >- T* operator->() const { return get(); } >- >- template<typename IndexType> >- T& operator[](IndexType index) const { return get()[index]; } >- >-private: >- AuxiliaryBarrier<CagedPtr<kind, T>> m_barrier; >-}; >+ T* get(unsigned size) const { return m_barrier.get().get(size); } >+ T* getMayBeNull(unsigned size) const { return m_barrier.get().getMayBeNull(size); } >+ T* getUnsafe() const { return m_barrier.get().getUnsafe(); } >+ >+ // We need the template here so that the type of U is deduced at usage time rather than class time. U should always be T. >+ template<typename U = T> >+ typename std::enable_if<!std::is_same<void, U>::value, T>::type& >+ /* T& */ at(unsigned index, unsigned size) const { return get(size)[index]; } > >-template<Gigacage::Kind passedKind> >-class CagedBarrierPtr<passedKind, void> { >-public: >- static constexpr Gigacage::Kind kind = passedKind; >- typedef void Type; >- >- CagedBarrierPtr() { } >- >- template<typename U> >- CagedBarrierPtr(VM& vm, JSCell* cell, U&& value) >- { >- m_barrier.set(vm, cell, std::forward<U>(value)); >- } >- >- void clear() { m_barrier.clear(); } >- >- template<typename U> >- void set(VM& vm, JSCell* cell, U&& value) >- { >- m_barrier.set(vm, cell, std::forward<U>(value)); >- } >- >- void* get() const { return m_barrier.get().get(); } >- void* getMayBeNull() const { return m_barrier.get().getMayBeNull(); } >- > bool operator==(const CagedBarrierPtr& other) const > { >- return getMayBeNull() == other.getMayBeNull(); >+ return m_barrier.get() == other.m_barrier.get(); > } > > bool operator!=(const CagedBarrierPtr& other) const >@@ -125,14 +79,14 @@ public: > > explicit operator bool() const > { >- return *this != CagedBarrierPtr(); >+ return !!m_barrier.get(); > } > > template<typename U> >- void setWithoutBarrier(U&& value) { m_barrier.setWithoutBarrier(std::forward<U>(value)); } >+ void setWithoutBarrier(U&& value, unsigned size) { m_barrier.setWithoutBarrier(CagedType(std::forward<U>(value), size)); } > > private: >- AuxiliaryBarrier<CagedPtr<kind, void>> m_barrier; >+ AuxiliaryBarrier<CagedType> m_barrier; > }; > > } // namespace JSC >diff --git a/Source/JavaScriptCore/runtime/DataView.cpp b/Source/JavaScriptCore/runtime/DataView.cpp >index 3b5871ba3be2a1ebcf41b3d7b74eaf9f636ede8b..5e073f54f7910873929baf9fd097a48310bf58a5 100644 >--- a/Source/JavaScriptCore/runtime/DataView.cpp >+++ b/Source/JavaScriptCore/runtime/DataView.cpp >@@ -33,8 +33,7 @@ > namespace JSC { > > DataView::DataView(RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned byteLength) >- : ArrayBufferView(WTFMove(buffer), byteOffset) >- , m_byteLength(byteLength) >+ : ArrayBufferView(WTFMove(buffer), byteOffset, byteLength) > { > } > >diff --git a/Source/JavaScriptCore/runtime/DataView.h b/Source/JavaScriptCore/runtime/DataView.h >index 7a397636659b188d9d7b9cec84c70db63d2713ea..22a23fdbb8c6264cb08ccc83da0396fc1e5c2fd6 100644 >--- a/Source/JavaScriptCore/runtime/DataView.h >+++ b/Source/JavaScriptCore/runtime/DataView.h >@@ -38,11 +38,6 @@ public: > JS_EXPORT_PRIVATE static Ref<DataView> create(RefPtr<ArrayBuffer>&&, unsigned byteOffset, unsigned length); > static Ref<DataView> create(RefPtr<ArrayBuffer>&&); > >- unsigned byteLength() const override >- { >- return m_byteLength; >- } >- > TypedArrayType getType() const override > { > return TypeDataView; >@@ -62,7 +57,7 @@ public: > } else > RELEASE_ASSERT(offset + sizeof(T) <= byteLength()); > return flipBytesIfLittleEndian( >- *reinterpret_cast<T*>(static_cast<uint8_t*>(m_baseAddress.get()) + offset), >+ *reinterpret_cast<T*>(static_cast<uint8_t*>(m_baseAddress.get(byteLength())) + offset), > littleEndian); > } > >@@ -86,12 +81,9 @@ public: > *status = true; > } else > RELEASE_ASSERT(offset + sizeof(T) <= byteLength()); >- *reinterpret_cast<T*>(static_cast<uint8_t*>(m_baseAddress.get()) + offset) = >+ *reinterpret_cast<T*>(static_cast<uint8_t*>(m_baseAddress.get(byteLength())) + offset) = > flipBytesIfLittleEndian(value, littleEndian); > } >- >-private: >- unsigned m_byteLength; > }; > > } // namespace JSC >diff --git a/Source/JavaScriptCore/runtime/DirectArguments.cpp b/Source/JavaScriptCore/runtime/DirectArguments.cpp >index e001be294b66829d137afcb7b1b20dfef323cc66..3ee876be72837e778d701da2112ae45b3ab37022 100644 >--- a/Source/JavaScriptCore/runtime/DirectArguments.cpp >+++ b/Source/JavaScriptCore/runtime/DirectArguments.cpp >@@ -101,7 +101,7 @@ void DirectArguments::visitChildren(JSCell* thisCell, SlotVisitor& visitor) > visitor.append(thisObject->m_callee); > > if (thisObject->m_mappedArguments) >- visitor.markAuxiliary(thisObject->m_mappedArguments.get()); >+ visitor.markAuxiliary(thisObject->m_mappedArguments.get(thisObject->internalLength())); > GenericArguments<DirectArguments>::visitChildren(thisCell, visitor); > } > >@@ -120,8 +120,8 @@ void DirectArguments::overrideThings(VM& vm) > > void* backingStore = vm.gigacageAuxiliarySpace(m_mappedArguments.kind).allocateNonVirtual(vm, mappedArgumentsSize(), nullptr, AllocationFailureMode::Assert); > bool* overrides = static_cast<bool*>(backingStore); >- m_mappedArguments.set(vm, this, overrides); >- for (unsigned i = m_length; i--;) >+ m_mappedArguments.set(vm, this, overrides, internalLength()); >+ for (unsigned i = internalLength(); i--;) > overrides[i] = false; > } > >@@ -134,7 +134,7 @@ void DirectArguments::overrideThingsIfNecessary(VM& vm) > void DirectArguments::unmapArgument(VM& vm, unsigned index) > { > overrideThingsIfNecessary(vm); >- m_mappedArguments[index] = true; >+ m_mappedArguments.at(index, internalLength()) = true; > } > > void DirectArguments::copyToArguments(ExecState* exec, VirtualRegister firstElementDest, unsigned offset, unsigned length) >diff --git a/Source/JavaScriptCore/runtime/DirectArguments.h b/Source/JavaScriptCore/runtime/DirectArguments.h >index 32cdd0b7046cc8f6186b58c439d65745efe9dced..9ca01f33c733859206f97039ff5e57ade63d62ae 100644 >--- a/Source/JavaScriptCore/runtime/DirectArguments.h >+++ b/Source/JavaScriptCore/runtime/DirectArguments.h >@@ -86,7 +86,7 @@ public: > > bool isMappedArgument(uint32_t i) const > { >- return i < m_length && (!m_mappedArguments || !m_mappedArguments[i]); >+ return i < m_length && (!m_mappedArguments || !m_mappedArguments.at(i, m_length)); > } > > bool isMappedArgumentInDFG(uint32_t i) const >@@ -182,7 +182,8 @@ private: > WriteBarrier<JSFunction> m_callee; > uint32_t m_length; // Always the actual length of captured arguments and never what was stored into the length property. > uint32_t m_minCapacity; // The max of this and length determines the capacity of this object. It may be the actual capacity, or maybe something smaller. We arrange it this way to be kind to the JITs. >- CagedBarrierPtr<Gigacage::Primitive, bool> m_mappedArguments; // If non-null, it means that length, callee, and caller are fully materialized properties. >+ using MappedArguments = CagedBarrierPtr<Gigacage::Primitive, bool>; >+ MappedArguments m_mappedArguments; // If non-null, it means that length, callee, and caller are fully materialized properties. > }; > > } // namespace JSC >diff --git a/Source/JavaScriptCore/runtime/GenericArguments.h b/Source/JavaScriptCore/runtime/GenericArguments.h >index 6a6380e7f1b9d51e9d3a376f920e3e6d676b7166..b1c78684274145964f71a2b7490fa3c1098641d6 100644 >--- a/Source/JavaScriptCore/runtime/GenericArguments.h >+++ b/Source/JavaScriptCore/runtime/GenericArguments.h >@@ -60,8 +60,9 @@ protected: > bool isModifiedArgumentDescriptor(unsigned index, unsigned length); > > void copyToArguments(ExecState*, VirtualRegister firstElementDest, unsigned offset, unsigned length); >- >- CagedBarrierPtr<Gigacage::Primitive, bool> m_modifiedArgumentsDescriptor; >+ >+ using ModifiedArgumentsPtr = CagedBarrierPtr<Gigacage::Primitive, bool>; >+ ModifiedArgumentsPtr m_modifiedArgumentsDescriptor; > }; > > } // namespace JSC >diff --git a/Source/JavaScriptCore/runtime/GenericArgumentsInlines.h b/Source/JavaScriptCore/runtime/GenericArgumentsInlines.h >index 2be41fe99726cebd9a88f8a429f5de01a3923cd2..d56ebf5b7832595c8bf9a4ed4d554c1db4ca2ba6 100644 >--- a/Source/JavaScriptCore/runtime/GenericArgumentsInlines.h >+++ b/Source/JavaScriptCore/runtime/GenericArgumentsInlines.h >@@ -38,7 +38,7 @@ void GenericArguments<Type>::visitChildren(JSCell* thisCell, SlotVisitor& visito > Base::visitChildren(thisCell, visitor); > > if (thisObject->m_modifiedArgumentsDescriptor) >- visitor.markAuxiliary(thisObject->m_modifiedArgumentsDescriptor.get()); >+ visitor.markAuxiliary(thisObject->m_modifiedArgumentsDescriptor.getUnsafe()); > } > > template<typename Type> >@@ -265,7 +265,7 @@ void GenericArguments<Type>::initModifiedArgumentsDescriptor(VM& vm, unsigned ar > if (argsLength) { > void* backingStore = vm.gigacageAuxiliarySpace(m_modifiedArgumentsDescriptor.kind).allocateNonVirtual(vm, WTF::roundUpToMultipleOf<8>(argsLength), nullptr, AllocationFailureMode::Assert); > bool* modifiedArguments = static_cast<bool*>(backingStore); >- m_modifiedArgumentsDescriptor.set(vm, this, modifiedArguments); >+ m_modifiedArgumentsDescriptor.set(vm, this, modifiedArguments, argsLength); > for (unsigned i = argsLength; i--;) > modifiedArguments[i] = false; > } >@@ -283,7 +283,7 @@ void GenericArguments<Type>::setModifiedArgumentDescriptor(VM& vm, unsigned inde > { > initModifiedArgumentsDescriptorIfNecessary(vm, length); > if (index < length) >- m_modifiedArgumentsDescriptor[index] = true; >+ m_modifiedArgumentsDescriptor.at(index, length) = true; > } > > template<typename Type> >@@ -292,7 +292,7 @@ bool GenericArguments<Type>::isModifiedArgumentDescriptor(unsigned index, unsign > if (!m_modifiedArgumentsDescriptor) > return false; > if (index < length) >- return m_modifiedArgumentsDescriptor[index]; >+ return m_modifiedArgumentsDescriptor.at(index, length); > return false; > } > >diff --git a/Source/JavaScriptCore/runtime/GenericTypedArrayView.h b/Source/JavaScriptCore/runtime/GenericTypedArrayView.h >index ef2e80f4ea03bde6491cf7333a27b7c577f0eb5e..82fdfa1f44a0087865667bc45da645d8694b1254 100644 >--- a/Source/JavaScriptCore/runtime/GenericTypedArrayView.h >+++ b/Source/JavaScriptCore/runtime/GenericTypedArrayView.h >@@ -58,8 +58,7 @@ public: > return setRangeImpl( > reinterpret_cast<const char*>(data), > count * sizeof(typename Adaptor::Type), >- offset * sizeof(typename Adaptor::Type), >- internalByteLength()); >+ offset * sizeof(typename Adaptor::Type)); > } > > bool zeroRange(unsigned offset, size_t count) >@@ -73,12 +72,7 @@ public: > { > if (isNeutered()) > return 0; >- return m_length; >- } >- >- unsigned byteLength() const override >- { >- return internalByteLength(); >+ return byteLength() / sizeof(typename Adaptor::Type); > } > > typename Adaptor::Type item(unsigned index) const >@@ -104,8 +98,7 @@ public: > return getRangeImpl( > reinterpret_cast<char*>(data), > count * sizeof(typename Adaptor::Type), >- offset * sizeof(typename Adaptor::Type), >- internalByteLength()); >+ offset * sizeof(typename Adaptor::Type)); > } > > bool checkInboundData(unsigned offset, size_t count) const >@@ -126,14 +119,6 @@ public: > } > > JSArrayBufferView* wrap(ExecState*, JSGlobalObject*) override; >- >-private: >- unsigned internalByteLength() const >- { >- return length() * sizeof(typename Adaptor::Type); >- } >- >- unsigned m_length; > }; > > } // namespace JSC >diff --git a/Source/JavaScriptCore/runtime/GenericTypedArrayViewInlines.h b/Source/JavaScriptCore/runtime/GenericTypedArrayViewInlines.h >index e660cfcdd4894562d174f646575d5622b1223793..746cbe2fbeb07ce1f9ab3692a44dabe9c8ba2fbe 100644 >--- a/Source/JavaScriptCore/runtime/GenericTypedArrayViewInlines.h >+++ b/Source/JavaScriptCore/runtime/GenericTypedArrayViewInlines.h >@@ -32,9 +32,8 @@ namespace JSC { > > template<typename Adaptor> > GenericTypedArrayView<Adaptor>::GenericTypedArrayView( >- RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned length) >- : ArrayBufferView(WTFMove(buffer), byteOffset) >- , m_length(length) >+RefPtr<ArrayBuffer>&& buffer, unsigned byteOffset, unsigned length) >+ : ArrayBufferView(WTFMove(buffer), byteOffset, length * sizeof(typename Adaptor::Type)) > { > } > >diff --git a/Source/JavaScriptCore/runtime/JSArrayBufferView.cpp b/Source/JavaScriptCore/runtime/JSArrayBufferView.cpp >index c2de003ff6b710dde7ddbbe81994a5828e4572cc..d1d86799054a7570585cc6a40a76b5f545323b54 100644 >--- a/Source/JavaScriptCore/runtime/JSArrayBufferView.cpp >+++ b/Source/JavaScriptCore/runtime/JSArrayBufferView.cpp >@@ -1,5 +1,5 @@ > /* >- * Copyright (C) 2013-2018 Apple Inc. All rights reserved. >+ * Copyright (C) 2013-2019 Apple Inc. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -50,11 +50,12 @@ String JSArrayBufferView::toStringName(const JSObject*, ExecState*) > JSArrayBufferView::ConstructionContext::ConstructionContext( > Structure* structure, uint32_t length, void* vector) > : m_structure(structure) >- , m_vector(vector) >+ , m_vector(vector, length) > , m_length(length) > , m_mode(FastTypedArray) > , m_butterfly(nullptr) > { >+ ASSERT(vector == removeArrayPtrTag(vector)); > RELEASE_ASSERT(length <= fastSizeLimit); > } > >@@ -74,11 +75,11 @@ JSArrayBufferView::ConstructionContext::ConstructionContext( > return; > > m_structure = structure; >- m_vector = temp; >+ m_vector = VectorType(temp, length); > m_mode = FastTypedArray; > > if (mode == ZeroFill) { >- uint64_t* asWords = static_cast<uint64_t*>(m_vector.getMayBeNull()); >+ uint64_t* asWords = static_cast<uint64_t*>(vector()); > for (unsigned i = size / sizeof(uint64_t); i--;) > asWords[i] = 0; > } >@@ -91,11 +92,11 @@ JSArrayBufferView::ConstructionContext::ConstructionContext( > return; > > size_t size = static_cast<size_t>(length) * static_cast<size_t>(elementSize); >- m_vector = Gigacage::tryMalloc(Gigacage::Primitive, size); >+ m_vector = VectorType(Gigacage::tryMalloc(Gigacage::Primitive, size), length); > if (!m_vector) > return; > if (mode == ZeroFill) >- memset(m_vector.get(), 0, size); >+ memset(vector(), 0, size); > > vm.heap.reportExtraMemoryAllocated(static_cast<size_t>(length) * elementSize); > >@@ -110,7 +111,8 @@ JSArrayBufferView::ConstructionContext::ConstructionContext( > , m_length(length) > , m_mode(WastefulTypedArray) > { >- m_vector = static_cast<uint8_t*>(arrayBuffer->data()) + byteOffset; >+ ASSERT(arrayBuffer->data() == removeArrayPtrTag(arrayBuffer->data())); >+ m_vector = VectorType(static_cast<uint8_t*>(arrayBuffer->data()) + byteOffset, length); > IndexingHeader indexingHeader; > indexingHeader.setArrayBuffer(arrayBuffer.get()); > m_butterfly = Butterfly::create(vm, 0, 0, 0, true, indexingHeader, 0); >@@ -124,7 +126,8 @@ JSArrayBufferView::ConstructionContext::ConstructionContext( > , m_mode(DataViewMode) > , m_butterfly(0) > { >- m_vector = static_cast<uint8_t*>(arrayBuffer->data()) + byteOffset; >+ ASSERT(arrayBuffer->data() == removeArrayPtrTag(arrayBuffer->data())); >+ m_vector = VectorType(static_cast<uint8_t*>(arrayBuffer->data()) + byteOffset, length); > } > > JSArrayBufferView::JSArrayBufferView(VM& vm, ConstructionContext& context) >@@ -133,7 +136,8 @@ JSArrayBufferView::JSArrayBufferView(VM& vm, ConstructionContext& context) > , m_mode(context.mode()) > { > setButterfly(vm, context.butterfly()); >- m_vector.setWithoutBarrier(context.vector()); >+ ASSERT(context.vector() == removeArrayPtrTag(context.vector())); >+ m_vector.setWithoutBarrier(context.vector(), m_length); > } > > void JSArrayBufferView::finishCreation(VM& vm) >@@ -194,7 +198,7 @@ void JSArrayBufferView::finalize(JSCell* cell) > JSArrayBufferView* thisObject = static_cast<JSArrayBufferView*>(cell); > ASSERT(thisObject->m_mode == OversizeTypedArray || thisObject->m_mode == WastefulTypedArray); > if (thisObject->m_mode == OversizeTypedArray) >- Gigacage::free(Gigacage::Primitive, thisObject->m_vector.get()); >+ Gigacage::free(Gigacage::Primitive, thisObject->vector()); > } > > JSArrayBuffer* JSArrayBufferView::unsharedJSBuffer(ExecState* exec) >@@ -283,7 +287,7 @@ ArrayBuffer* JSArrayBufferView::slowDownAndWasteMemory() > { > auto locker = holdLock(cellLock()); > butterfly()->indexingHeader()->setArrayBuffer(buffer.get()); >- m_vector.setWithoutBarrier(buffer->data()); >+ m_vector.setWithoutBarrier(buffer->data(), m_length); > WTF::storeStoreFence(); > m_mode = WastefulTypedArray; > } >diff --git a/Source/JavaScriptCore/runtime/JSArrayBufferView.h b/Source/JavaScriptCore/runtime/JSArrayBufferView.h >index ef7ebe1ad2a5d17613299295e478b4774bd66796..4dfd08f2593f9d54df011b3c81278c594b1e3d03 100644 >--- a/Source/JavaScriptCore/runtime/JSArrayBufferView.h >+++ b/Source/JavaScriptCore/runtime/JSArrayBufferView.h >@@ -1,5 +1,5 @@ > /* >- * Copyright (C) 2013, 2016 Apple Inc. All rights reserved. >+ * Copyright (C) 2013-2019 Apple Inc. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -27,6 +27,7 @@ > > #include "AuxiliaryBarrier.h" > #include "JSObject.h" >+#include <wtf/TaggedArrayStoragePtr.h> > > namespace JSC { > >@@ -96,6 +97,7 @@ class JSArrayBufferView : public JSNonFinalObject { > public: > typedef JSNonFinalObject Base; > static const unsigned fastSizeLimit = 1000; >+ using VectorPtr = CagedBarrierPtr<Gigacage::Primitive, void, tagCagedPtr>; > > static size_t sizeOf(uint32_t length, uint32_t elementSize) > { >@@ -133,14 +135,15 @@ protected: > bool operator!() const { return !m_structure; } > > Structure* structure() const { return m_structure; } >- void* vector() const { return m_vector.getMayBeNull(); } >+ void* vector() const { return m_vector.getMayBeNull(m_length); } > uint32_t length() const { return m_length; } > TypedArrayMode mode() const { return m_mode; } > Butterfly* butterfly() const { return m_butterfly; } > > private: > Structure* m_structure; >- CagedPtr<Gigacage::Primitive, void> m_vector; >+ using VectorType = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>; >+ VectorType m_vector; > uint32_t m_length; > TypedArrayMode m_mode; > Butterfly* m_butterfly; >@@ -164,10 +167,11 @@ public: > JSArrayBuffer* possiblySharedJSBuffer(ExecState* exec); > RefPtr<ArrayBufferView> unsharedImpl(); > JS_EXPORT_PRIVATE RefPtr<ArrayBufferView> possiblySharedImpl(); >- bool isNeutered() { return hasArrayBuffer() && !vector(); } >+ bool isNeutered() { return hasArrayBuffer() && !hasVector(); } > void neuter(); >- >- void* vector() const { return m_vector.getMayBeNull(); } >+ >+ bool hasVector() const { return !!m_vector; } >+ void* vector() const { return m_vector.getMayBeNull(length()); } > > unsigned byteOffset(); > unsigned length() const { return m_length; } >@@ -191,7 +195,7 @@ protected: > > static String toStringName(const JSObject*, ExecState*); > >- CagedBarrierPtr<Gigacage::Primitive, void> m_vector; >+ VectorPtr m_vector; > uint32_t m_length; > TypedArrayMode m_mode; > }; >diff --git a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h >index a27fe7826e945b38267294cf7113a679d2ba27fc..d42af64954f3f4afe200c0d48f27f6c69da2f863 100644 >--- a/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h >+++ b/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h >@@ -77,8 +77,7 @@ JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::createWithFa > } > > template<typename Adaptor> >-JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::createUninitialized( >- ExecState* exec, Structure* structure, unsigned length) >+JSGenericTypedArrayView<Adaptor>* JSGenericTypedArrayView<Adaptor>::createUninitialized(ExecState* exec, Structure* structure, unsigned length) > { > VM& vm = exec->vm(); > auto scope = DECLARE_THROW_SCOPE(vm); >@@ -507,7 +506,7 @@ size_t JSGenericTypedArrayView<Adaptor>::estimatedSize(JSCell* cell, VM& vm) > > if (thisObject->m_mode == OversizeTypedArray) > return Base::estimatedSize(thisObject, vm) + thisObject->byteSize(); >- if (thisObject->m_mode == FastTypedArray && thisObject->m_vector) >+ if (thisObject->m_mode == FastTypedArray && thisObject->hasVector()) > return Base::estimatedSize(thisObject, vm) + thisObject->byteSize(); > > return Base::estimatedSize(thisObject, vm); >@@ -526,7 +525,7 @@ void JSGenericTypedArrayView<Adaptor>::visitChildren(JSCell* cell, SlotVisitor& > { > auto locker = holdLock(thisObject->cellLock()); > mode = thisObject->m_mode; >- vector = thisObject->m_vector.getMayBeNull(); >+ vector = thisObject->vector(); > byteSize = thisObject->byteSize(); > } > >diff --git a/Source/JavaScriptCore/runtime/Options.h b/Source/JavaScriptCore/runtime/Options.h >index c2c59361ddc132d4120e7686a99b5d35d9a3ef64..c42a341fd8ddbb14fb3e6277562a45aa3d06da04 100644 >--- a/Source/JavaScriptCore/runtime/Options.h >+++ b/Source/JavaScriptCore/runtime/Options.h >@@ -492,8 +492,7 @@ constexpr bool enableWebAssemblyStreamingApi = false; > v(unsigned, webAssemblyLoopDecrement, 15, Normal, "The amount the tier up countdown is decremented on each loop backedge.") \ > v(unsigned, webAssemblyFunctionEntryDecrement, 1, Normal, "The amount the tier up countdown is decremented on each function entry.") \ > \ >- /* FIXME: enable fast memories on iOS and pre-allocate them. https://bugs.webkit.org/show_bug.cgi?id=170774 */ \ >- v(bool, useWebAssemblyFastMemory, !isIOS(), Normal, "If true, we will try to use a 32-bit address space with a signal handler to bounds check wasm memory.") \ >+ v(bool, useWebAssemblyFastMemory, true, Normal, "If true, we will try to use a 32-bit address space with a signal handler to bounds check wasm memory.") \ > v(bool, logWebAssemblyMemory, false, Normal, nullptr) \ > v(unsigned, webAssemblyFastMemoryRedzonePages, 128, Normal, "WebAssembly fast memories use 4GiB virtual allocations, plus a redzone (counted as multiple of 64KiB WebAssembly pages) at the end to catch reg+imm accesses which exceed 32-bit, anything beyond the redzone is explicitly bounds-checked") \ > v(bool, crashIfWebAssemblyCantFastMemory, false, Normal, "If true, we will crash if we can't obtain fast memory for wasm.") \ >diff --git a/Source/JavaScriptCore/runtime/ScopedArgumentsTable.cpp b/Source/JavaScriptCore/runtime/ScopedArgumentsTable.cpp >index 955a307d23e1669efba4c03229ee1e52c7604d15..5b0e9af06cfb04a0ed247ab7fb4e9481af69f9b4 100644 >--- a/Source/JavaScriptCore/runtime/ScopedArgumentsTable.cpp >+++ b/Source/JavaScriptCore/runtime/ScopedArgumentsTable.cpp >@@ -68,16 +68,16 @@ ScopedArgumentsTable* ScopedArgumentsTable::clone(VM& vm) > { > ScopedArgumentsTable* result = create(vm, m_length); > for (unsigned i = m_length; i--;) >- result->m_arguments[i] = m_arguments[i]; >+ result->at(i) = this->at(i); > return result; > } > > ScopedArgumentsTable* ScopedArgumentsTable::setLength(VM& vm, uint32_t newLength) > { > if (LIKELY(!m_locked)) { >- ArgumentsPtr newArguments = ArgumentsPtr::create(newLength); >+ ArgumentsPtr newArguments = ArgumentsPtr::create(newLength, newLength); > for (unsigned i = std::min(m_length, newLength); i--;) >- newArguments[i] = m_arguments[i]; >+ newArguments.at(i, newLength) = this->at(i); > m_length = newLength; > m_arguments = WTFMove(newArguments); > return this; >@@ -85,10 +85,12 @@ ScopedArgumentsTable* ScopedArgumentsTable::setLength(VM& vm, uint32_t newLength > > ScopedArgumentsTable* result = create(vm, newLength); > for (unsigned i = std::min(m_length, newLength); i--;) >- result->m_arguments[i] = m_arguments[i]; >+ result->at(i) = this->at(i); > return result; > } > >+static_assert(std::is_trivially_destructible<ScopeOffset>::value, ""); >+ > ScopedArgumentsTable* ScopedArgumentsTable::set(VM& vm, uint32_t i, ScopeOffset value) > { > ScopedArgumentsTable* result; >diff --git a/Source/JavaScriptCore/runtime/ScopedArgumentsTable.h b/Source/JavaScriptCore/runtime/ScopedArgumentsTable.h >index e81234297b0bb8a025802f37a89847088a5ae135..558a9eba39de500b86035446076328ca84499b35 100644 >--- a/Source/JavaScriptCore/runtime/ScopedArgumentsTable.h >+++ b/Source/JavaScriptCore/runtime/ScopedArgumentsTable.h >@@ -61,10 +61,7 @@ public: > uint32_t length() const { return m_length; } > ScopedArgumentsTable* setLength(VM&, uint32_t newLength); > >- ScopeOffset get(uint32_t i) const >- { >- return const_cast<ScopedArgumentsTable*>(this)->at(i); >- } >+ ScopeOffset get(uint32_t i) const { return at(i); } > > void lock() > { >@@ -80,13 +77,13 @@ public: > static ptrdiff_t offsetOfLength() { return OBJECT_OFFSETOF(ScopedArgumentsTable, m_length); } > static ptrdiff_t offsetOfArguments() { return OBJECT_OFFSETOF(ScopedArgumentsTable, m_arguments); } > >- typedef CagedUniquePtr<Gigacage::Primitive, ScopeOffset[]> ArgumentsPtr; >+ typedef CagedUniquePtr<Gigacage::Primitive, ScopeOffset> ArgumentsPtr; > > private: >- ScopeOffset& at(uint32_t i) >+ ScopeOffset& at(uint32_t i) const > { > ASSERT_WITH_SECURITY_IMPLICATION(i < m_length); >- return m_arguments[i]; >+ return m_arguments.get(length())[i]; > } > > uint32_t m_length; >diff --git a/Source/JavaScriptCore/runtime/SymbolTable.h b/Source/JavaScriptCore/runtime/SymbolTable.h >index 6fa3f580a288457c004e86a2be4d090d0ee01f98..8b74a20c8291091225130cf19a11ae309dd7c7bf 100644 >--- a/Source/JavaScriptCore/runtime/SymbolTable.h >+++ b/Source/JavaScriptCore/runtime/SymbolTable.h >@@ -636,8 +636,9 @@ public: > void setArgumentsLength(VM& vm, uint32_t length) > { > if (UNLIKELY(!m_arguments)) >- m_arguments.set(vm, this, ScopedArgumentsTable::create(vm)); >- m_arguments.set(vm, this, m_arguments->setLength(vm, length)); >+ m_arguments.set(vm, this, ScopedArgumentsTable::create(vm, length)); >+ else >+ m_arguments.set(vm, this, m_arguments->setLength(vm, length)); > } > > ScopeOffset argumentOffset(uint32_t i) const >diff --git a/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp b/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp >index 9944f7523f4702f59ff609a433bd8a46b1dfa516..57b3df810e4b12f9e73ac4b14780b1649d873cb2 100644 >--- a/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp >+++ b/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp >@@ -836,6 +836,8 @@ void AirIRGenerator::restoreWebAssemblyGlobalState(RestoreCachedStackLimit resto > RegisterSet clobbers; > clobbers.set(pinnedRegs->baseMemoryPointer); > clobbers.set(pinnedRegs->sizeRegister); >+ if (!isARM64()) >+ clobbers.set(RegisterSet::macroScratchRegisters()); > > auto* patchpoint = addPatchpoint(B3::Void); > B3::Effects effects = B3::Effects::none(); >@@ -843,10 +845,18 @@ void AirIRGenerator::restoreWebAssemblyGlobalState(RestoreCachedStackLimit resto > effects.reads = B3::HeapRange::top(); > patchpoint->effects = effects; > patchpoint->clobber(clobbers); >+ patchpoint->numGPScratchRegisters = Gigacage::isEnabled(Gigacage::Primitive) ? 1 : 0; > > patchpoint->setGenerator([pinnedRegs] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) { >+ RELEASE_ASSERT(!Gigacage::isEnabled(Gigacage::Primitive) || !isARM64()); >+ AllowMacroScratchRegisterUsageIf allowScratch(jit, !isARM64()); >+ GPRReg baseMemory = pinnedRegs->baseMemoryPointer; >+ GPRReg scratchOrSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs->sizeRegister; >+ > jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedMemorySize()), pinnedRegs->sizeRegister); >- jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedMemory()), pinnedRegs->baseMemoryPointer); >+ jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedMemory()), baseMemory); >+ >+ jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrSize); > }); > > emitPatchpoint(block, patchpoint, Tmp(), instance); >@@ -1958,6 +1968,8 @@ auto AirIRGenerator::addCallIndirect(const Signature& signature, Vector<Expressi > // FIXME: We shouldn't have to do this: https://bugs.webkit.org/show_bug.cgi?id=172181 > patchpoint->clobber(PinnedRegisterInfo::get().toSave(MemoryMode::BoundsChecking)); > patchpoint->clobber(RegisterSet::macroScratchRegisters()); >+ patchpoint->numGPScratchRegisters = Gigacage::isEnabled(Gigacage::Primitive) ? 1 : 0; >+ > patchpoint->setGenerator([=] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) { > AllowMacroScratchRegisterUsage allowScratch(jit); > GPRReg newContextInstance = params[0].gpr(); >@@ -1971,8 +1983,12 @@ auto AirIRGenerator::addCallIndirect(const Signature& signature, Vector<Expressi > // FIXME: We should support more than one memory size register > // see: https://bugs.webkit.org/show_bug.cgi?id=162952 > ASSERT(pinnedRegs.sizeRegister != newContextInstance); >+ GPRReg scratchOrSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs.sizeRegister; >+ > jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); // Memory size. > jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedMemory()), baseMemory); // Memory::void*. >+ >+ jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrSize); > }); > > emitPatchpoint(doContextSwitch, patchpoint, Tmp(), newContextInstance, instanceValue()); >diff --git a/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp b/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp >index 940c888229ad946ee6741016758b5dc5448aca89..2226ffc72c9382cc26fb3ebbe09429760ef44ab7 100644 >--- a/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp >+++ b/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp >@@ -47,6 +47,7 @@ > #include "B3VariableValue.h" > #include "B3WasmAddressValue.h" > #include "B3WasmBoundsCheckValue.h" >+#include "DisallowMacroScratchRegisterUsage.h" > #include "JSCInlines.h" > #include "JSWebAssemblyInstance.h" > #include "ScratchRegisterAllocator.h" >@@ -477,6 +478,8 @@ void B3IRGenerator::restoreWebAssemblyGlobalState(RestoreCachedStackLimit restor > RegisterSet clobbers; > clobbers.set(pinnedRegs->baseMemoryPointer); > clobbers.set(pinnedRegs->sizeRegister); >+ if (!isARM64()) >+ clobbers.set(RegisterSet::macroScratchRegisters()); > > B3::PatchpointValue* patchpoint = block->appendNew<B3::PatchpointValue>(proc, B3::Void, origin()); > Effects effects = Effects::none(); >@@ -484,13 +487,19 @@ void B3IRGenerator::restoreWebAssemblyGlobalState(RestoreCachedStackLimit restor > effects.reads = B3::HeapRange::top(); > patchpoint->effects = effects; > patchpoint->clobber(clobbers); >+ patchpoint->numGPScratchRegisters = Gigacage::isEnabled(Gigacage::Primitive) ? 1 : 0; > > patchpoint->append(instance, ValueRep::SomeRegister); >- > patchpoint->setGenerator([pinnedRegs] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) { >+ RELEASE_ASSERT(!Gigacage::isEnabled(Gigacage::Primitive) || !isARM64()); >+ AllowMacroScratchRegisterUsageIf allowScratch(jit, !isARM64()); > GPRReg baseMemory = pinnedRegs->baseMemoryPointer; >+ GPRReg scratchOrSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs->sizeRegister; >+ > jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedMemorySize()), pinnedRegs->sizeRegister); > jit.loadPtr(CCallHelpers::Address(params[0].gpr(), Instance::offsetOfCachedMemory()), baseMemory); >+ >+ jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrSize); > }); > } > } >@@ -1371,6 +1380,8 @@ auto B3IRGenerator::addCallIndirect(const Signature& signature, Vector<Expressio > patchpoint->clobber(RegisterSet::macroScratchRegisters()); > patchpoint->append(newContextInstance, ValueRep::SomeRegister); > patchpoint->append(instanceValue(), ValueRep::SomeRegister); >+ patchpoint->numGPScratchRegisters = Gigacage::isEnabled(Gigacage::Primitive) ? 1 : 0; >+ > patchpoint->setGenerator([=] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) { > AllowMacroScratchRegisterUsage allowScratch(jit); > GPRReg newContextInstance = params[0].gpr(); >@@ -1385,8 +1396,12 @@ auto B3IRGenerator::addCallIndirect(const Signature& signature, Vector<Expressio > // FIXME: We should support more than one memory size register > // see: https://bugs.webkit.org/show_bug.cgi?id=162952 > ASSERT(pinnedRegs.sizeRegister != newContextInstance); >+ GPRReg scratchOrSize = Gigacage::isEnabled(Gigacage::Primitive) ? params.gpScratch(0) : pinnedRegs.sizeRegister; >+ > jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); // Memory size. > jit.loadPtr(CCallHelpers::Address(newContextInstance, Instance::offsetOfCachedMemory()), baseMemory); // Memory::void*. >+ >+ jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrSize); > }); > doContextSwitch->appendNewControlValue(m_proc, Jump, origin(), continuation); > >diff --git a/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp b/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp >index e686fa7c5883d5248402ce1ecf35d0310025ba05..0b38f9d596bfc07bcb672bc2a17b71aadc1c49aa 100644 >--- a/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp >+++ b/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp >@@ -314,7 +314,7 @@ void BBQPlan::complete(const AbstractLocker& locker) > } > > m_wasmInternalFunctions[functionIndex]->entrypoint.compilation = std::make_unique<B3::Compilation>( >- FINALIZE_CODE(linkBuffer, B3CompilationPtrTag, "WebAssembly function[%i] %s", functionIndex, signature.toString().ascii().data()), >+ FINALIZE_CODE(linkBuffer, B3CompilationPtrTag, "WebAssembly BBQ function[%i] %s", functionIndex, signature.toString().ascii().data()), > WTFMove(context.wasmEntrypointByproducts)); > } > >diff --git a/Source/JavaScriptCore/wasm/WasmBinding.cpp b/Source/JavaScriptCore/wasm/WasmBinding.cpp >index 934971739126ef853d9e057e36bb2e612d47224f..fed45b1063c9a36bf651cf803ee10f1c5be7c654 100644 >--- a/Source/JavaScriptCore/wasm/WasmBinding.cpp >+++ b/Source/JavaScriptCore/wasm/WasmBinding.cpp >@@ -46,7 +46,7 @@ Expected<MacroAssemblerCodeRef<WasmEntryPtrTag>, BindingFailure> wasmToWasm(unsi > const PinnedRegisterInfo& pinnedRegs = PinnedRegisterInfo::get(); > JIT jit; > >- GPRReg scratch = GPRInfo::nonPreservedNonArgumentGPR0; >+ GPRReg scratch = wasmCallingConventionAir().prologueScratch(0); > GPRReg baseMemory = pinnedRegs.baseMemoryPointer; > ASSERT(baseMemory != scratch); > ASSERT(pinnedRegs.sizeRegister != baseMemory); >@@ -66,8 +66,13 @@ Expected<MacroAssemblerCodeRef<WasmEntryPtrTag>, BindingFailure> wasmToWasm(unsi > > // FIXME the following code assumes that all Wasm::Instance have the same pinned registers. https://bugs.webkit.org/show_bug.cgi?id=162952 > // Set up the callee's baseMemory register as well as the memory size registers. >- jit.loadPtr(JIT::Address(baseMemory, Wasm::Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); // Memory size. >- jit.loadPtr(JIT::Address(baseMemory, Wasm::Instance::offsetOfCachedMemory()), baseMemory); // Wasm::Memory::void*. >+ { >+ GPRReg scratchOrSize = isARM64E() ? pinnedRegs.sizeRegister : wasmCallingConventionAir().prologueScratch(1); >+ >+ jit.loadPtr(JIT::Address(baseMemory, Wasm::Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); // Memory size. >+ jit.loadPtr(JIT::Address(baseMemory, Wasm::Instance::offsetOfCachedMemory()), baseMemory); // Wasm::Memory::TaggedArrayStoragePtr<void> (void*). >+ jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrSize); >+ } > > // Tail call into the callee WebAssembly function. > jit.loadPtr(scratch, scratch); >diff --git a/Source/JavaScriptCore/wasm/WasmInstance.h b/Source/JavaScriptCore/wasm/WasmInstance.h >index bf11c1522b9a619f3c370466e4b78c32e850dcbd..5d1fcf3f9d3b82bd0981a20cccd544e7807ce4d7 100644 >--- a/Source/JavaScriptCore/wasm/WasmInstance.h >+++ b/Source/JavaScriptCore/wasm/WasmInstance.h >@@ -66,7 +66,7 @@ public: > Memory* memory() { return m_memory.get(); } > Table* table() { return m_table.get(); } > >- void* cachedMemory() const { return m_cachedMemory; } >+ void* cachedMemory() const { return m_cachedMemory.getMayBeNull(cachedMemorySize()); } > size_t cachedMemorySize() const { return m_cachedMemorySize; } > > void setMemory(Ref<Memory>&& memory) >@@ -78,7 +78,7 @@ public: > void updateCachedMemory() > { > if (m_memory != nullptr) { >- m_cachedMemory = memory()->memory(); >+ m_cachedMemory = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>(memory()->memory(), memory()->size()); > m_cachedMemorySize = memory()->size(); > } > } >@@ -147,7 +147,7 @@ private: > } > void* m_owner { nullptr }; // In a JS embedding, this is a JSWebAssemblyInstance*. > Context* m_context { nullptr }; >- void* m_cachedMemory { nullptr }; >+ CagedPtr<Gigacage::Primitive, void, tagCagedPtr> m_cachedMemory; > size_t m_cachedMemorySize { 0 }; > Ref<Module> m_module; > RefPtr<CodeBlock> m_codeBlock; >diff --git a/Source/JavaScriptCore/wasm/WasmMemory.cpp b/Source/JavaScriptCore/wasm/WasmMemory.cpp >index b2da87084c2ba1162cd31b6cb99ad8e0afec305b..5910382348e96d123aa1f539e39b09da031f064e 100644 >--- a/Source/JavaScriptCore/wasm/WasmMemory.cpp >+++ b/Source/JavaScriptCore/wasm/WasmMemory.cpp >@@ -253,10 +253,11 @@ Memory::Memory(PageCount initial, PageCount maximum, Function<void(NotifyPressur > ASSERT(!initial.bytes()); > ASSERT(m_mode == MemoryMode::BoundsChecking); > dataLogLnIf(verbose, "Memory::Memory allocating ", *this); >+ ASSERT(!memory()); > } > > Memory::Memory(void* memory, PageCount initial, PageCount maximum, size_t mappedCapacity, MemoryMode mode, Function<void(NotifyPressure)>&& notifyMemoryPressure, Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback) >- : m_memory(memory) >+ : m_memory(memory, initial.bytes()) > , m_size(initial.bytes()) > , m_initial(initial) > , m_maximum(maximum) >@@ -338,14 +339,14 @@ Memory::~Memory() > memoryManager().freePhysicalBytes(m_size); > switch (m_mode) { > case MemoryMode::Signaling: >- if (mprotect(m_memory, Memory::fastMappedBytes(), PROT_READ | PROT_WRITE)) { >+ if (mprotect(memory(), Memory::fastMappedBytes(), PROT_READ | PROT_WRITE)) { > dataLog("mprotect failed: ", strerror(errno), "\n"); > RELEASE_ASSERT_NOT_REACHED(); > } >- memoryManager().freeFastMemory(m_memory); >+ memoryManager().freeFastMemory(memory()); > break; > case MemoryMode::BoundsChecking: >- Gigacage::freeVirtualPages(Gigacage::Primitive, m_memory, m_size); >+ Gigacage::freeVirtualPages(Gigacage::Primitive, memory(), m_size); > break; > } > } >@@ -419,24 +420,26 @@ Expected<PageCount, Memory::GrowFailReason> Memory::grow(PageCount delta) > if (!newMemory) > return makeUnexpected(GrowFailReason::OutOfMemory); > >- memcpy(newMemory, m_memory, m_size); >+ memcpy(newMemory, memory(), m_size); > if (m_memory) >- Gigacage::freeVirtualPages(Gigacage::Primitive, m_memory, m_size); >- m_memory = newMemory; >+ Gigacage::freeVirtualPages(Gigacage::Primitive, memory(), m_size); >+ m_memory = CagedMemory(newMemory, desiredSize); > m_mappedCapacity = desiredSize; > m_size = desiredSize; >+ ASSERT(memory() == newMemory); > return success(); > } > case MemoryMode::Signaling: { >- RELEASE_ASSERT(m_memory); >+ RELEASE_ASSERT(memory()); > // Signaling memory must have been pre-allocated virtually. >- uint8_t* startAddress = static_cast<uint8_t*>(m_memory) + m_size; >+ uint8_t* startAddress = static_cast<uint8_t*>(memory()) + m_size; > >- dataLogLnIf(verbose, "Marking WebAssembly memory's ", RawPointer(m_memory), " as read+write in range [", RawPointer(startAddress), ", ", RawPointer(startAddress + extraBytes), ")"); >+ dataLogLnIf(verbose, "Marking WebAssembly memory's ", RawPointer(memory()), " as read+write in range [", RawPointer(startAddress), ", ", RawPointer(startAddress + extraBytes), ")"); > if (mprotect(startAddress, extraBytes, PROT_READ | PROT_WRITE)) { > dataLog("mprotect failed: ", strerror(errno), "\n"); > RELEASE_ASSERT_NOT_REACHED(); > } >+ m_memory.recage(m_size, desiredSize); > m_size = desiredSize; > return success(); > } >@@ -460,7 +463,7 @@ void Memory::registerInstance(Instance* instance) > > void Memory::dump(PrintStream& out) const > { >- out.print("Memory at ", RawPointer(m_memory), ", size ", m_size, "B capacity ", m_mappedCapacity, "B, initial ", m_initial, " maximum ", m_maximum, " mode ", makeString(m_mode)); >+ out.print("Memory at ", RawPointer(memory()), ", size ", m_size, "B capacity ", m_mappedCapacity, "B, initial ", m_initial, " maximum ", m_maximum, " mode ", makeString(m_mode)); > } > > } // namespace JSC >diff --git a/Source/JavaScriptCore/wasm/WasmMemory.h b/Source/JavaScriptCore/wasm/WasmMemory.h >index 00737fc1e65e2b28d0b008a9e3953dc772c99111..9670838f1711f82e7bb4e15bf8b5dd3b84826b51 100644 >--- a/Source/JavaScriptCore/wasm/WasmMemory.h >+++ b/Source/JavaScriptCore/wasm/WasmMemory.h >@@ -30,6 +30,7 @@ > #include "WasmMemoryMode.h" > #include "WasmPageCount.h" > >+#include <wtf/CagedPtr.h> > #include <wtf/Expected.h> > #include <wtf/Function.h> > #include <wtf/RefCounted.h> >@@ -68,7 +69,7 @@ public: > static size_t fastMappedBytes(); // Includes redzone. > static bool addressIsInActiveFastMemory(void*); > >- void* memory() const { return m_memory; } >+ void* memory() const { ASSERT(m_memory.getMayBeNull(size()) == m_memory.getUnsafe()); return m_memory.getMayBeNull(size()); } > size_t size() const { return m_size; } > PageCount sizeInPages() const { return PageCount::fromBytes(m_size); } > >@@ -96,7 +97,8 @@ private: > Memory(void* memory, PageCount initial, PageCount maximum, size_t mappedCapacity, MemoryMode, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback); > Memory(PageCount initial, PageCount maximum, WTF::Function<void(NotifyPressure)>&& notifyMemoryPressure, WTF::Function<void(SyncTryToReclaim)>&& syncTryToReclaimMemory, WTF::Function<void(GrowSuccess, PageCount, PageCount)>&& growSuccessCallback); > >- void* m_memory { nullptr }; >+ using CagedMemory = CagedPtr<Gigacage::Primitive, void, tagCagedPtr>; >+ CagedMemory m_memory; > size_t m_size { 0 }; > PageCount m_initial; > PageCount m_maximum; >diff --git a/Source/JavaScriptCore/wasm/js/JSToWasm.cpp b/Source/JavaScriptCore/wasm/js/JSToWasm.cpp >index 8903d1c6f2ba3ce27dd0d5f6d0b163ab9610af88..657da57aeb7ce3daeaf3c25747818b620dce1492 100644 >--- a/Source/JavaScriptCore/wasm/js/JSToWasm.cpp >+++ b/Source/JavaScriptCore/wasm/js/JSToWasm.cpp >@@ -29,6 +29,7 @@ > #if ENABLE(WEBASSEMBLY) > > #include "CCallHelpers.h" >+#include "DisallowMacroScratchRegisterUsage.h" > #include "JSCInlines.h" > #include "JSWebAssemblyInstance.h" > #include "JSWebAssemblyRuntimeError.h" >@@ -211,15 +212,23 @@ std::unique_ptr<InternalFunction> createJSToWasmWrapper(CompilationContext& comp > > if (!!info.memory) { > GPRReg baseMemory = pinnedRegs.baseMemoryPointer; >+ GPRReg scratchOrSize = wasmCallingConventionAir().prologueScratch(0); > > if (Context::useFastTLS()) > jit.loadWasmContextInstance(baseMemory); > > GPRReg currentInstanceGPR = Context::useFastTLS() ? baseMemory : wasmContextInstanceGPR; >- if (mode != MemoryMode::Signaling) >- jit.loadPtr(CCallHelpers::Address(currentInstanceGPR, Wasm::Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); >+ if (isARM64E()) { >+ if (mode != Wasm::MemoryMode::Signaling) >+ scratchOrSize = pinnedRegs.sizeRegister; >+ jit.loadPtr(CCallHelpers::Address(currentInstanceGPR, Wasm::Instance::offsetOfCachedMemorySize()), scratchOrSize); >+ } else { >+ if (mode != Wasm::MemoryMode::Signaling) >+ jit.loadPtr(CCallHelpers::Address(currentInstanceGPR, Wasm::Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); >+ } > > jit.loadPtr(CCallHelpers::Address(currentInstanceGPR, Wasm::Instance::offsetOfCachedMemory()), baseMemory); >+ jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrSize); > } > > CCallHelpers::Call call = jit.threadSafePatchableNearCall(); >diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp >index 4850a259168634b3e691309e951697ebb012ad1e..2ff0e78e582f6561a28f3c59537821c03980b890 100644 >--- a/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp >+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp >@@ -410,13 +410,20 @@ MacroAssemblerCodePtr<JSEntryPtrTag> WebAssemblyFunction::jsCallEntrypointSlow() > > if (!!moduleInformation.memory) { > GPRReg baseMemory = pinnedRegs.baseMemoryPointer; >- >- if (instance()->memoryMode() != Wasm::MemoryMode::Signaling) { >- ASSERT(pinnedRegs.sizeRegister != scratchGPR); >- jit.loadPtr(CCallHelpers::Address(scratchGPR, Wasm::Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); >+ GPRReg scratchOrSize = scratch2GPR; >+ auto mode = instance()->memoryMode(); >+ >+ if (isARM64E()) { >+ if (mode != Wasm::MemoryMode::Signaling) >+ scratchOrSize = pinnedRegs.sizeRegister; >+ jit.loadPtr(CCallHelpers::Address(scratchGPR, Wasm::Instance::offsetOfCachedMemorySize()), scratchOrSize); >+ } else { >+ if (mode != Wasm::MemoryMode::Signaling) >+ jit.loadPtr(CCallHelpers::Address(scratchGPR, Wasm::Instance::offsetOfCachedMemorySize()), pinnedRegs.sizeRegister); > } > > jit.loadPtr(CCallHelpers::Address(scratchGPR, Wasm::Instance::offsetOfCachedMemory()), baseMemory); >+ jit.cageConditionally(Gigacage::Primitive, baseMemory, scratchOrSize); > } > > // We use this callee to indicate how to unwind past these types of frames: >diff --git a/Source/WTF/WTF.xcodeproj/project.pbxproj b/Source/WTF/WTF.xcodeproj/project.pbxproj >index b04c4358b65625c500163174e5f1800613e061b1..26344ac725ac93d02eab93c44e5ecf3e3dafc8dd 100644 >--- a/Source/WTF/WTF.xcodeproj/project.pbxproj >+++ b/Source/WTF/WTF.xcodeproj/project.pbxproj >@@ -653,6 +653,7 @@ > DCEE21FC1CEA7551000C2396 /* BlockObjCExceptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockObjCExceptions.h; sourceTree = "<group>"; }; > DCEE21FD1CEA7551000C2396 /* BlockObjCExceptions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BlockObjCExceptions.mm; sourceTree = "<group>"; }; > DCEE22041CEB9869000C2396 /* BackwardsGraph.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackwardsGraph.h; sourceTree = "<group>"; }; >+ DEF7FE5F22581AC800C15129 /* TaggedArrayStoragePtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaggedArrayStoragePtr.h; sourceTree = "<group>"; }; > E15556F318A0CC18006F48FB /* CryptographicUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptographicUtilities.cpp; sourceTree = "<group>"; }; > E15556F418A0CC18006F48FB /* CryptographicUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptographicUtilities.h; sourceTree = "<group>"; }; > E300E521203D645F00DA79BE /* UniqueArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UniqueArray.h; sourceTree = "<group>"; }; >@@ -1160,6 +1161,7 @@ > 5597F82C1D94B9970066BC21 /* SynchronizedFixedQueue.h */, > E3E158251EADA53C004A079D /* SystemFree.h */, > 0FB317C31C488001007E395A /* SystemTracing.h */, >+ DEF7FE5F22581AC800C15129 /* TaggedArrayStoragePtr.h */, > E311FB151F0A568B003C08DE /* ThreadGroup.cpp */, > E311FB161F0A568B003C08DE /* ThreadGroup.h */, > A8A47332151A825B004123FF /* Threading.cpp */, >diff --git a/Source/WTF/wtf/CMakeLists.txt b/Source/WTF/wtf/CMakeLists.txt >index c8ccad4d91cbbcf056610e98497d4326e5534d5b..975d87132a53444567ffeb4cb98786ae03874bbc 100644 >--- a/Source/WTF/wtf/CMakeLists.txt >+++ b/Source/WTF/wtf/CMakeLists.txt >@@ -230,6 +230,7 @@ set(WTF_PUBLIC_HEADERS > SynchronizedFixedQueue.h > SystemFree.h > SystemTracing.h >+ TaggedArrayStoragePtr.h > ThreadGroup.h > ThreadMessage.h > ThreadSafeRefCounted.h >diff --git a/Source/WTF/wtf/CagedPtr.h b/Source/WTF/wtf/CagedPtr.h >index d4b4ba1bb3d07feede914d25197a05b5cdfdf2d0..71ec51e2947b5b2ca06ea2c4056dadceb938df6e 100644 >--- a/Source/WTF/wtf/CagedPtr.h >+++ b/Source/WTF/wtf/CagedPtr.h >@@ -27,107 +27,91 @@ > > #include <wtf/DumbPtrTraits.h> > #include <wtf/Gigacage.h> >+#include <wtf/PtrTag.h> > > namespace WTF { > >-template<Gigacage::Kind passedKind, typename T, typename PtrTraits = DumbPtrTraits<T>> >+constexpr bool tagCagedPtr = true; >+ >+template<Gigacage::Kind passedKind, typename T, bool shouldTag = false, typename PtrTraits = DumbPtrTraits<T>> > class CagedPtr { > public: > static constexpr Gigacage::Kind kind = passedKind; > > CagedPtr() : CagedPtr(nullptr) { } >- CagedPtr(std::nullptr_t) : m_ptr(nullptr) { } >+ CagedPtr(std::nullptr_t) >+ : m_ptr(shouldTag ? tagArrayPtr<T>(nullptr, 0) : nullptr) >+ { } > >- explicit CagedPtr(T* ptr) >- : m_ptr(ptr) >- { >- } >- >- T* get() const >+ CagedPtr(T* ptr, unsigned size) >+ : m_ptr(shouldTag ? tagArrayPtr(ptr, size) : ptr) >+ { } >+ >+ >+ T* get(unsigned size) const > { > ASSERT(m_ptr); >- return Gigacage::caged(kind, PtrTraits::unwrap(m_ptr)); >- } >- >- T* getMayBeNull() const >- { >- if (!m_ptr) >- return nullptr; >- return get(); >+ T* ptr = PtrTraits::unwrap(m_ptr); >+ if (shouldTag) >+ ptr = untagArrayPtr(ptr, size); >+ return Gigacage::caged(kind, ptr); > } > >- CagedPtr& operator=(T* ptr) >+ T* getMayBeNull(unsigned size) const > { >- m_ptr = ptr; >- return *this; >+ T* ptr = PtrTraits::unwrap(m_ptr); >+ if (shouldTag) >+ ptr = untagArrayPtr(ptr, size); >+ return Gigacage::cagedMayBeNull(kind, ptr); > } > >- CagedPtr& operator=(T*&& ptr) >+ T* getUnsafe() const > { >- m_ptr = WTFMove(ptr); >- return *this; >+ T* ptr = PtrTraits::unwrap(m_ptr); >+ if (shouldTag) >+ ptr = removeArrayPtrTag(ptr); >+ return Gigacage::cagedMayBeNull(kind, ptr); > } > >- bool operator==(const CagedPtr& other) const >- { >- return getMayBeNull() == other.getMayBeNull(); >- } >- >- bool operator!=(const CagedPtr& other) const >- { >- return !(*this == other); >- } >- >- explicit operator bool() const >+ // We need the template here so that the type of U is deduced at usage time rather than class time. U should always be T. >+ template<typename U = T> >+ typename std::enable_if<!std::is_same<void, U>::value, T>::type& >+ /* T& */ at(unsigned index, unsigned size) const { return get(size)[index]; } >+ >+ void recage(unsigned oldSize, unsigned newSize) > { >- return *this != CagedPtr(); >+ auto ptr = get(oldSize); >+ ASSERT(ptr == getUnsafe()); >+ *this = CagedPtr(ptr, newSize); > } >- >- T& operator*() const { return *get(); } >- T* operator->() const { return get(); } >- >- template<typename IndexType> >- T& operator[](IndexType index) const { return get()[index]; } >- >-protected: >- typename PtrTraits::StorageType m_ptr; >-}; > >-template<Gigacage::Kind passedKind, typename PtrTraits> >-class CagedPtr<passedKind, void, PtrTraits> { >-public: >- static constexpr Gigacage::Kind kind = passedKind; >- >- CagedPtr() : CagedPtr(nullptr) { } >- CagedPtr(std::nullptr_t) : m_ptr(nullptr) { } >- >- explicit CagedPtr(void* ptr) >- : m_ptr(ptr) >+ CagedPtr(CagedPtr& other) >+ : m_ptr(other.m_ptr) > { > } >- >- void* get() const >+ >+ CagedPtr& operator=(const CagedPtr& ptr) > { >- ASSERT(m_ptr); >- return Gigacage::caged(kind, PtrTraits::unwrap(m_ptr)); >+ m_ptr = ptr.m_ptr; >+ return *this; > } >- >- void* getMayBeNull() const >+ >+ CagedPtr(CagedPtr&& other) >+ : m_ptr(PtrTraits::exchange(other.m_ptr, nullptr)) > { >- if (!m_ptr) >- return nullptr; >- return get(); > } > >- CagedPtr& operator=(void* ptr) >+ CagedPtr& operator=(CagedPtr&& ptr) > { >- m_ptr = ptr; >+ m_ptr = PtrTraits::exchange(ptr.m_ptr, nullptr); > return *this; > } > > bool operator==(const CagedPtr& other) const > { >- return getMayBeNull() == other.getMayBeNull(); >+ bool result = m_ptr == other.m_ptr; >+ ASSERT(result == (getUnsafe() == other.getUnsafe())); >+ return result; > } > > bool operator!=(const CagedPtr& other) const >@@ -137,7 +121,7 @@ public: > > explicit operator bool() const > { >- return *this != CagedPtr(); >+ return getUnsafe() != nullptr; > } > > protected: >@@ -147,4 +131,5 @@ protected: > } // namespace WTF > > using WTF::CagedPtr; >+using WTF::tagCagedPtr; > >diff --git a/Source/WTF/wtf/CagedUniquePtr.h b/Source/WTF/wtf/CagedUniquePtr.h >index 4aae2878f617c72db317f2893ba612c8efc23a09..2ed083c165ce0d5f618db3d20197ef29889e81dc 100644 >--- a/Source/WTF/wtf/CagedUniquePtr.h >+++ b/Source/WTF/wtf/CagedUniquePtr.h >@@ -29,80 +29,30 @@ > > namespace WTF { > >-template<Gigacage::Kind kind, typename T, typename Enable = void> >-class CagedUniquePtr : public CagedPtr<kind, T> { >+template<Gigacage::Kind kind, typename T, bool shouldTag = false> >+class CagedUniquePtr : public CagedPtr<kind, T, shouldTag> { >+ static_assert(std::is_trivially_destructible<T>::value, "We expect the contents of a caged pointer to be trivially destructable."); > public: >- CagedUniquePtr(T* ptr = nullptr) >- : CagedPtr<kind, T>(ptr) >- { >- } >- >- CagedUniquePtr(CagedUniquePtr&& ptr) >- : CagedPtr<kind, T>(ptr.m_ptr) >- { >- ptr.m_ptr = nullptr; >- } >- >- CagedUniquePtr(const CagedUniquePtr&) = delete; >- >- template<typename... Arguments> >- static CagedUniquePtr create(Arguments&&... arguments) >- { >- T* result = static_cast<T*>(Gigacage::malloc(kind, sizeof(T))); >- new (result) T(std::forward<Arguments>(arguments)...); >- return CagedUniquePtr(result); >- } >- >- CagedUniquePtr& operator=(CagedUniquePtr&& ptr) >- { >- destroy(); >- this->m_ptr = ptr.m_ptr; >- ptr.m_ptr = nullptr; >- return *this; >- } >- >- CagedUniquePtr& operator=(const CagedUniquePtr&) = delete; >- >- ~CagedUniquePtr() >- { >- destroy(); >- } >- >-private: >- void destroy() >- { >- if (!this->m_ptr) >- return; >- this->m_ptr->~T(); >- Gigacage::free(kind, this->m_ptr); >- } >-}; >+ using Base = CagedPtr<kind, T, shouldTag>; >+ CagedUniquePtr() = default; >+ >+ CagedUniquePtr(T* ptr, unsigned size) >+ : Base(ptr, size) >+ { } > >-template<Gigacage::Kind kind, typename T> >-class CagedUniquePtr<kind, T[], typename std::enable_if<std::is_trivially_destructible<T>::value>::type> : public CagedPtr<kind, T> { >-public: >- CagedUniquePtr() : CagedPtr<kind, T>() { } >- >- CagedUniquePtr(T* ptr) >- : CagedPtr<kind, T>(ptr) >- { >- } >- > CagedUniquePtr(CagedUniquePtr&& ptr) >- : CagedPtr<kind, T>(ptr.m_ptr) >- { >- ptr.m_ptr = nullptr; >- } >+ : Base(std::forward<CagedUniquePtr&&>(ptr)) >+ { } > > CagedUniquePtr(const CagedUniquePtr&) = delete; > > template<typename... Arguments> >- static CagedUniquePtr create(size_t count, Arguments&&... arguments) >+ static CagedUniquePtr create(unsigned length, Arguments&&... arguments) > { >- T* result = static_cast<T*>(Gigacage::mallocArray(kind, count, sizeof(T))); >- while (count--) >- new (result + count) T(std::forward<Arguments>(arguments)...); >- return CagedUniquePtr(result); >+ T* result = static_cast<T*>(Gigacage::malloc(kind, sizeof(T) * length)); >+ while (length--) >+ new (result + length) T(arguments...); >+ return CagedUniquePtr(result, length); > } > > CagedUniquePtr& operator=(CagedUniquePtr&& ptr) >@@ -119,83 +69,16 @@ public: > { > destroy(); > } >- >-private: >- void destroy() >- { >- if (!this->m_ptr) >- return; >- Gigacage::free(kind, this->m_ptr); >- } >-}; > >-template<Gigacage::Kind kind, typename T> >-class CagedUniquePtr<kind, T[], typename std::enable_if<!std::is_trivially_destructible<T>::value>::type> : public CagedPtr<kind, T> { >-public: >- CagedUniquePtr() : CagedPtr<kind, T>() { } >- >- CagedUniquePtr(T* ptr, size_t count) >- : CagedPtr<kind, T>(ptr) >- , m_count(count) >- { >- } >- >- CagedUniquePtr(CagedUniquePtr&& ptr) >- : CagedPtr<kind, T>(ptr.m_ptr) >- , m_count(ptr.m_count) >- { >- ptr.clear(); >- } >- >- CagedUniquePtr(const CagedUniquePtr&) = delete; >- >- template<typename... Arguments> >- static CagedUniquePtr create(size_t count, Arguments&&... arguments) >- { >- T* result = static_cast<T*>(Gigacage::mallocArray(kind, count, sizeof(T))); >- while (count--) >- new (result + count) T(std::forward<Arguments>(arguments)...); >- return CagedUniquePtr(result, count); >- } >- >- CagedUniquePtr& operator=(CagedUniquePtr&& ptr) >- { >- destroy(); >- this->m_ptr = ptr.m_ptr; >- m_count = ptr.m_count; >- ptr.clear(); >- return *this; >- } >- >- CagedUniquePtr& operator=(const CagedUniquePtr&) = delete; >- >- ~CagedUniquePtr() >- { >- destroy(); >- } >- >- // FIXME: It's weird that we inherit CagedPtr::operator== and friends, which don't do anything >- // about m_count. It "works" because pointer equality is enough so long as everything is sane, but >- // it seems like a missed opportunity to assert things. >- // https://bugs.webkit.org/show_bug.cgi?id=175541 >- > private: > void destroy() > { >- if (!this->m_ptr) >+ T* ptr = Base::getUnsafe(); >+ if (!ptr) > return; >- while (m_count--) >- this->m_ptr[m_count].~T(); >- Gigacage::free(kind, this->m_ptr); >+ ptr->~T(); >+ Gigacage::free(kind, ptr); > } >- >- void clear() >- { >- this->m_ptr = nullptr; >- m_count = 0; >- } >- >- size_t m_count { 0 }; > }; > > } // namespace WTF >diff --git a/Source/WTF/wtf/Gigacage.h b/Source/WTF/wtf/Gigacage.h >index 233f56ec34c4e0d2c31fbcef605c831468ffb811..227f6471f2d05e99c8da385f9744f05ef6313c38 100644 >--- a/Source/WTF/wtf/Gigacage.h >+++ b/Source/WTF/wtf/Gigacage.h >@@ -114,6 +114,8 @@ ALWAYS_INLINE size_t mask(Kind) { return 0; } > > template<typename T> > inline T* caged(Kind, T* ptr) { return ptr; } >+template<typename T> >+inline T* cagedMayBeNull(Kind, T* ptr) { return ptr; } > > inline bool isCaged(Kind, const void*) { return false; } > >diff --git a/Source/WTF/wtf/PtrTag.h b/Source/WTF/wtf/PtrTag.h >index 60a0a8d4efe06ad5e61fa779291bdffa696194bd..14349bda47e0a6761270cfcc9978e38cf9edec78 100644 >--- a/Source/WTF/wtf/PtrTag.h >+++ b/Source/WTF/wtf/PtrTag.h >@@ -122,6 +122,38 @@ constexpr bool enablePtrTagDebugAssert = true; > } while (false) > > >+template<typename T> >+inline T* tagArrayPtr(std::nullptr_t ptr, size_t length) >+{ >+ ASSERT(!length); >+ return ptrauth_sign_unauthenticated(static_cast<T*>(ptr), ptrauth_key_process_dependent_data, length); >+} >+ >+ >+template<typename T> >+inline T* tagArrayPtr(T* ptr, size_t length) >+{ >+ return ptrauth_sign_unauthenticated(ptr, ptrauth_key_process_dependent_data, length); >+} >+ >+template<typename T> >+inline T* untagArrayPtr(T* ptr, size_t length) >+{ >+ return ptrauth_auth_data(ptr, ptrauth_key_process_dependent_data, length); >+} >+ >+template<typename T> >+inline T* removeArrayPtrTag(T* ptr) >+{ >+ return ptrauth_strip(ptr, ptrauth_key_process_dependent_data); >+} >+ >+template<typename T> >+inline T* retagArrayPtr(T* ptr, size_t oldLength, size_t newLength) >+{ >+ return ptrauth_auth_and_resign(ptr, ptrauth_key_process_dependent_data, oldLength, ptrauth_key_process_dependent_data, newLength); >+} >+ > template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>> > inline constexpr T removeCodePtrTag(PtrType ptr) > { >@@ -395,6 +427,38 @@ inline bool usesPointerTagging() { return true; } > inline void registerPtrTagLookup(PtrTagLookup*) { } > inline void reportBadTag(const void*, PtrTag) { } > >+template<typename T> >+inline T* tagArrayPtr(std::nullptr_t, size_t size) >+{ >+ ASSERT_UNUSED(size, !size); >+ return nullptr; >+} >+ >+template<typename T> >+inline T* tagArrayPtr(T* ptr, size_t) >+{ >+ return ptr; >+} >+ >+template<typename T> >+inline T* untagArrayPtr(T* ptr, size_t) >+{ >+ return ptr; >+} >+ >+template<typename T> >+inline T* removeArrayPtrTag(T* ptr) >+{ >+ return ptr; >+} >+ >+template<typename T> >+inline T* retagArrayPtr(T* ptr, size_t, size_t) >+{ >+ return ptr; >+} >+ >+ > template<typename T, typename PtrType, typename = std::enable_if_t<std::is_pointer<PtrType>::value && !std::is_same<T, PtrType>::value>> > constexpr T tagCodePtr(PtrType ptr, PtrTag) { return bitwise_cast<T>(ptr); } > >@@ -494,6 +558,11 @@ using WTF::PtrTag; > > using WTF::reportBadTag; > >+using WTF::tagArrayPtr; >+using WTF::untagArrayPtr; >+using WTF::retagArrayPtr; >+using WTF::removeArrayPtrTag; >+ > using WTF::tagCodePtr; > using WTF::untagCodePtr; > using WTF::retagCodePtr; >diff --git a/Source/WTF/wtf/TaggedArrayStoragePtr.h b/Source/WTF/wtf/TaggedArrayStoragePtr.h >new file mode 100644 >index 0000000000000000000000000000000000000000..553e86f77399847d0e07117f609eec517ca579d1 >--- /dev/null >+++ b/Source/WTF/wtf/TaggedArrayStoragePtr.h >@@ -0,0 +1,59 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. 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. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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. >+ */ >+ >+#pragma once >+ >+#include <wtf/PtrTag.h> >+ >+namespace WTF { >+ >+template<typename PtrType> >+class TaggedArrayStoragePtr { >+public: >+ TaggedArrayStoragePtr() >+ : m_ptr(tagArrayPtr<PtrType>(nullptr, 0)) >+ { } >+ >+ TaggedArrayStoragePtr(PtrType* ptr, unsigned length) >+ : m_ptr(tagArrayPtr(ptr, length)) >+ { } >+ >+ PtrType* get(unsigned length) const { return untagArrayPtr(m_ptr, length); } >+ PtrType* getUnsafe() const { return removeArrayPtrTag(m_ptr); } >+ >+ void resize(unsigned oldLength, unsigned newLength) >+ { >+ m_ptr = retagArrayPtr(m_ptr, oldLength, newLength); >+ } >+ >+ explicit operator bool() const { return !!getUnsafe(); } >+ >+private: >+ PtrType* m_ptr; >+}; >+ >+} >+ >+using WTF::TaggedArrayStoragePtr; >diff --git a/Source/bmalloc/bmalloc/Gigacage.h b/Source/bmalloc/bmalloc/Gigacage.h >index 70cce67a245b43395132bfddaa4166a3be833b42..76d72df74a136f0219155cf208f7c77958c4e996 100644 >--- a/Source/bmalloc/bmalloc/Gigacage.h >+++ b/Source/bmalloc/bmalloc/Gigacage.h >@@ -34,8 +34,7 @@ > #include <cstddef> > #include <inttypes.h> > >-#if ((BOS(DARWIN) || BOS(LINUX)) && \ >-(BCPU(X86_64) || (BCPU(ARM64) && !defined(__ILP32__) && (!BPLATFORM(IOS_FAMILY) || BPLATFORM(IOS))))) >+#if ((BOS(DARWIN) || BOS(LINUX)) && BCPU(X86_64)) > #define GIGACAGE_ENABLED 1 > #else > #define GIGACAGE_ENABLED 0 >@@ -200,6 +199,14 @@ BINLINE T* caged(Kind kind, T* ptr) > reinterpret_cast<uintptr_t>(ptr) & mask(kind))); > } > >+template<typename T> >+BINLINE T* cagedMayBeNull(Kind kind, T* ptr) >+{ >+ if (!ptr) >+ return ptr; >+ return caged(kind, ptr); >+} >+ > BINLINE bool isCaged(Kind kind, const void* ptr) > { > return caged(kind, ptr) == ptr; >@@ -219,8 +226,9 @@ BINLINE size_t size(Kind) { BCRASH(); return 0; } > BINLINE void ensureGigacage() { } > BINLINE bool wasEnabled() { return false; } > BINLINE bool isCaged(Kind, const void*) { return true; } >-BINLINE bool isEnabled() { return false; } >+BINLINE bool isEnabled(Kind) { return false; } > template<typename T> BINLINE T* caged(Kind, T* ptr) { return ptr; } >+template<typename T> BINLINE T* cagedMayBeNull(Kind, T* ptr) { return ptr; } > BINLINE void disableDisablingPrimitiveGigacageIfShouldBeEnabled() { } > BINLINE bool canPrimitiveGigacageBeDisabled() { return false; } > BINLINE void disablePrimitiveGigacage() { }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198796
: 371976