From 454110c781d8b1db62d3f57072ff79078b1a3266 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Sun, 23 Sep 2018 05:14:23 -0400 Subject: Remove code that prevents binary extensions --- xpcom/components/ManifestParser.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'xpcom') diff --git a/xpcom/components/ManifestParser.cpp b/xpcom/components/ManifestParser.cpp index 4dcfc8402..7188c0ec5 100644 --- a/xpcom/components/ManifestParser.cpp +++ b/xpcom/components/ManifestParser.cpp @@ -637,14 +637,6 @@ ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf, continue; } -#ifndef MOZ_BINARY_EXTENSIONS - if (directive->apponly && NS_APP_LOCATION != aType) { - LogMessageWithContext(aFile, line, - "Only application manifests may use the '%s' directive.", token); - continue; - } -#endif - if (directive->componentonly && NS_SKIN_LOCATION == aType) { LogMessageWithContext(aFile, line, "Skin manifest not allowed to use '%s' directive.", -- cgit v1.2.3 From 7b0f3f2f92a22df1b3d4a4a35bab2a5c637d3cb4 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Mon, 1 Oct 2018 11:00:05 +0200 Subject: Remove unused telemetry functions/variables. Tag #21. --- xpcom/base/CycleCollectedJSContext.cpp | 1 - xpcom/base/nsCycleCollector.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'xpcom') diff --git a/xpcom/base/CycleCollectedJSContext.cpp b/xpcom/base/CycleCollectedJSContext.cpp index 02fc1aa4c..206984656 100644 --- a/xpcom/base/CycleCollectedJSContext.cpp +++ b/xpcom/base/CycleCollectedJSContext.cpp @@ -1537,7 +1537,6 @@ IncrementalFinalizeRunnable::Run() return NS_OK; } - TimeStamp start = TimeStamp::Now(); ReleaseNow(true); if (mDeferredFinalizeFunctions.Length()) { diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index a349e086d..7109d85bd 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -3524,9 +3524,9 @@ nsCycleCollector::CleanupAfterCollection() mGraph.Clear(); timeLog.Checkpoint("CleanupAfterCollection::mGraph.Clear()"); +#ifdef COLLECT_TIME_DEBUG uint32_t interval = (uint32_t)((TimeStamp::Now() - mCollectionStart).ToMilliseconds()); -#ifdef COLLECT_TIME_DEBUG printf("cc: total cycle collector time was %ums in %u slices\n", interval, mResults.mNumSlices); printf("cc: visited %u ref counted and %u GCed objects, freed %d ref counted and %d GCed objects", -- cgit v1.2.3 From c2fa384d666aea1b119736f33116ac09e870fda0 Mon Sep 17 00:00:00 2001 From: trav90 Date: Sat, 6 Oct 2018 17:29:50 -0500 Subject: Add mozilla::Span --- xpcom/glue/nsTArray.h | 84 +++++++++++++++++++++++++++++++++++++++++++++ xpcom/string/nsTSubstring.h | 83 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) (limited to 'xpcom') diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index ca74a41f7..c86772a8e 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -19,6 +19,7 @@ #include "mozilla/Move.h" #include "mozilla/ReverseIterator.h" #include "mozilla/TypeTraits.h" +#include "mozilla/Span.h" #include @@ -1112,6 +1113,18 @@ public: const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } const_reverse_iterator crend() const { return rend(); } + // Span integration + + operator mozilla::Span() + { + return mozilla::Span(Elements(), Length()); + } + + operator mozilla::Span() const + { + return mozilla::Span(Elements(), Length()); + } + // // Search methods // @@ -1336,6 +1349,16 @@ protected: return ReplaceElementsAt( aStart, aCount, aArray.Elements(), aArray.Length()); } + + template + elem_type* ReplaceElementsAt(index_type aStart, + size_type aCount, + mozilla::Span aSpan) + { + return ReplaceElementsAt( + aStart, aCount, aSpan.Elements(), aSpan.Length()); + } + public: template @@ -1347,6 +1370,15 @@ public: return ReplaceElementsAt(aStart, aCount, aArray); } + template + MOZ_MUST_USE elem_type* ReplaceElementsAt(index_type aStart, + size_type aCount, + mozilla::Span aSpan, + const mozilla::fallible_t&) + { + return ReplaceElementsAt(aStart, aCount, aSpan); + } + // A variation on the ReplaceElementsAt method defined above. protected: template @@ -1399,6 +1431,15 @@ protected: return ReplaceElementsAt( aIndex, 0, aArray.Elements(), aArray.Length()); } + + template + elem_type* InsertElementsAt(index_type aIndex, + mozilla::Span aSpan) + { + return ReplaceElementsAt( + aIndex, 0, aSpan.Elements(), aSpan.Length()); + } + public: template @@ -1425,6 +1466,14 @@ public: return InsertElementAt(aIndex); } + template + MOZ_MUST_USE elem_type* InsertElementsAt(index_type aIndex, + mozilla::Span aSpan, + const mozilla::fallible_t&) + { + return InsertElementsAt(aIndex, aSpan); + } + // Insert a new element, move constructing if possible. protected: template @@ -1526,6 +1575,13 @@ protected: template elem_type* AppendElements(const Item* aArray, size_type aArrayLen); + template + elem_type* AppendElements(mozilla::Span aSpan) + { + return AppendElements(aSpan.Elements(), + aSpan.Length()); + } + public: template @@ -1536,6 +1592,15 @@ public: return AppendElements(aArray, aArrayLen); } + template + /* MOZ_MUST_USE */ + elem_type* AppendElements(mozilla::Span aSpan, + const mozilla::fallible_t&) + { + return AppendElements(aSpan.Elements(), + aSpan.Length()); + } + // A variation on the AppendElements method defined above. protected: template @@ -2347,6 +2412,25 @@ struct nsTArray_CopyChooser> typedef nsTArray_CopyWithConstructors> Type; }; +// Span integration +namespace mozilla { + +template +Span +MakeSpan(nsTArray_Impl& aTArray) +{ + return aTArray; +} + +template +Span +MakeSpan(const nsTArray_Impl& aTArray) +{ + return aTArray; +} + +} // namespace mozilla + // Assert that AutoTArray doesn't have any extra padding inside. // // It's important that the data stored in this auto array takes up a multiple of diff --git a/xpcom/string/nsTSubstring.h b/xpcom/string/nsTSubstring.h index a08036b1f..53b4fb9a8 100644 --- a/xpcom/string/nsTSubstring.h +++ b/xpcom/string/nsTSubstring.h @@ -7,6 +7,8 @@ #include "mozilla/Casting.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/IntegerTypeTraits.h" +#include "mozilla/Span.h" #ifndef MOZILLA_INTERNAL_API #error Cannot use internal string classes without MOZILLA_INTERNAL_API defined. Use the frozen header nsStringAPI.h instead. @@ -798,6 +800,68 @@ public: } #endif + /** + * Span integration + */ + + operator mozilla::Span() + { + return mozilla::MakeSpan(BeginWriting(), Length()); + } + + operator mozilla::Span() const + { + return mozilla::MakeSpan(BeginReading(), Length()); + } + + void Append(mozilla::Span aSpan) + { + auto len = aSpan.Length(); + MOZ_RELEASE_ASSERT(len <= mozilla::MaxValue::value); + Append(aSpan.Elements(), len); + } + + MOZ_MUST_USE bool Append(mozilla::Span aSpan, + const fallible_t& aFallible) + { + auto len = aSpan.Length(); + if (len > mozilla::MaxValue::value) { + return false; + } + return Append(aSpan.Elements(), len, aFallible); + } + +#if !defined(CharT_is_PRUnichar) + operator mozilla::Span() + { + return mozilla::MakeSpan(reinterpret_cast(BeginWriting()), + Length()); + } + + operator mozilla::Span() const + { + return mozilla::MakeSpan(reinterpret_cast(BeginReading()), + Length()); + } + + void Append(mozilla::Span aSpan) + { + auto len = aSpan.Length(); + MOZ_RELEASE_ASSERT(len <= mozilla::MaxValue::value); + Append(reinterpret_cast(aSpan.Elements()), len); + } + + MOZ_MUST_USE bool Append(mozilla::Span aSpan, + const fallible_t& aFallible) + { + auto len = aSpan.Length(); + if (len > mozilla::MaxValue::value) { + return false; + } + return Append( + reinterpret_cast(aSpan.Elements()), len, aFallible); + } +#endif /** * string data is never null, but can be marked void. if true, the @@ -1184,3 +1248,22 @@ operator>(const nsTSubstring_CharT::base_string_type& aLhs, { return Compare(aLhs, aRhs) > 0; } + +/** + * Span integration + */ +namespace mozilla { + +inline Span +MakeSpan(nsTSubstring_CharT& aString) +{ + return aString; +} + +inline Span +MakeSpan(const nsTSubstring_CharT& aString) +{ + return aString; +} + +} // namespace mozilla -- cgit v1.2.3 From cc234ff4304d3a60dc2163f77a4214ecdbd88d5c Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Fri, 2 Nov 2018 14:59:25 +0100 Subject: Add overflow checks for extending nsTArrays. Surprisingly, this was previously not done. Also, some of this code seems to be incorrect or, at the very least, wasn't clear what it was trying to do. --- xpcom/glue/nsTArray-inl.h | 32 ++++++++++++++++++++++---------- xpcom/glue/nsTArray.h | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 24 deletions(-) (limited to 'xpcom') diff --git a/xpcom/glue/nsTArray-inl.h b/xpcom/glue/nsTArray-inl.h index af57c9866..7e667a327 100644 --- a/xpcom/glue/nsTArray-inl.h +++ b/xpcom/glue/nsTArray-inl.h @@ -108,6 +108,23 @@ nsTArray_base::UsesAutoArrayBuffer() const bool IsTwiceTheRequiredBytesRepresentableAsUint32(size_t aCapacity, size_t aElemSize); +template +template +typename ActualAlloc::ResultTypeProxy +nsTArray_base::ExtendCapacity(size_type aLength, + size_type aCount, + size_type aElemSize) +{ + mozilla::CheckedInt newLength = aLength; + newLength += aCount; + + if (!newLength.isValid()) { + return ActualAlloc::FailureResult(); + } + + return this->EnsureCapacity(newLength.value(), aElemSize); +} + template template typename ActualAlloc::ResultTypeProxy @@ -275,26 +292,21 @@ nsTArray_base::ShiftData(index_type aStart, template template -bool +typename ActualAlloc::ResultTypeProxy nsTArray_base::InsertSlotsAt(index_type aIndex, size_type aCount, size_type aElemSize, size_t aElemAlign) { MOZ_ASSERT(aIndex <= Length(), "Bogus insertion index"); - size_type newLen = Length() + aCount; - - EnsureCapacity(newLen, aElemSize); - - // Check for out of memory conditions - if (Capacity() < newLen) { - return false; + if (!ActualAlloc::Successful(this->ExtendCapacity(Length(), aCount, aElemSize))) { + return ActualAlloc::FailureResult(); } - + // Move the existing elements as needed. Note that this will // change our mLength, so no need to call IncrementLength. ShiftData(aIndex, 0, aCount, aElemSize, aElemAlign); - return true; + return ActualAlloc::SuccessResult(); } // nsTArray_base::IsAutoArrayRestorer is an RAII class which takes diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index c86772a8e..82586a79a 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -12,6 +12,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/BinarySearch.h" +#include "mozilla/CheckedInt.h" #include "mozilla/fallible.h" #include "mozilla/Function.h" #include "mozilla/MathAlgorithms.h" @@ -421,6 +422,17 @@ protected: typename ActualAlloc::ResultTypeProxy EnsureCapacity(size_type aCapacity, size_type aElemSize); + // Extend the storage to accommodate aCount extra elements. + // @param aLength The current size of the array. + // @param aCount The number of elements to add. + // @param aElemSize The size of an array element. + // @return False if insufficient memory is available or the new length + // would overflow; true otherwise. + template + typename ActualAlloc::ResultTypeProxy ExtendCapacity(size_type aLength, + size_type aCount, + size_type aElemSize); + // Tries to resize the storage to the minimum required amount. If this fails, // the array is left as-is. // @param aElemSize The size of an array element. @@ -462,8 +474,9 @@ protected: // @param aElementSize the size of an array element. // @param aElemAlign the alignment in bytes of an array element. template - bool InsertSlotsAt(index_type aIndex, size_type aCount, - size_type aElementSize, size_t aElemAlign); + typename ActualAlloc::ResultTypeProxy + InsertSlotsAt(index_type aIndex, size_type aCount, + size_type aElementSize, size_t aElemAlign); template typename ActualAlloc::ResultTypeProxy @@ -1655,8 +1668,8 @@ public: protected: template elem_type* AppendElements(size_type aCount) { - if (!ActualAlloc::Successful(this->template EnsureCapacity( - Length() + aCount, sizeof(elem_type)))) { + if (!ActualAlloc::Successful(this->template ExtendCapacity( + Length(), aCount, sizeof(elem_type)))) { return nullptr; } elem_type* elems = Elements() + Length(); @@ -1872,9 +1885,8 @@ protected: template elem_type* InsertElementsAt(index_type aIndex, size_type aCount) { - if (!base_type::template InsertSlotsAt(aIndex, aCount, - sizeof(elem_type), - MOZ_ALIGNOF(elem_type))) { + if (!ActualAlloc::Successful(this->template InsertSlotsAt( + aIndex, aCount, sizeof(elem_type), MOZ_ALIGNOF(elem_type)))) { return nullptr; } @@ -2047,9 +2059,8 @@ auto nsTArray_Impl::InsertElementsAt(index_type aIndex, size_type aCount, const Item& aItem) -> elem_type* { - if (!base_type::template InsertSlotsAt(aIndex, aCount, - sizeof(elem_type), - MOZ_ALIGNOF(elem_type))) { + if (!ActualAlloc::Successful(this->template InsertSlotsAt( + aIndex, aCount, sizeof(elem_type), MOZ_ALIGNOF(elem_type)))) { return nullptr; } @@ -2068,6 +2079,7 @@ template auto nsTArray_Impl::InsertElementAt(index_type aIndex) -> elem_type* { + // Length() + 1 is guaranteed to not overflow, so EnsureCapacity is OK. if (!ActualAlloc::Successful(this->template EnsureCapacity( Length() + 1, sizeof(elem_type)))) { return nullptr; @@ -2084,6 +2096,7 @@ template auto nsTArray_Impl::InsertElementAt(index_type aIndex, Item&& aItem) -> elem_type* { + // Length() + 1 is guaranteed to not overflow, so EnsureCapacity is OK. if (!ActualAlloc::Successful(this->template EnsureCapacity( Length() + 1, sizeof(elem_type)))) { return nullptr; @@ -2100,8 +2113,8 @@ template auto nsTArray_Impl::AppendElements(const Item* aArray, size_type aArrayLen) -> elem_type* { - if (!ActualAlloc::Successful(this->template EnsureCapacity( - Length() + aArrayLen, sizeof(elem_type)))) { + if (!ActualAlloc::Successful(this->template ExtendCapacity( + Length(), aArrayLen, sizeof(elem_type)))) { return nullptr; } index_type len = Length(); @@ -2123,8 +2136,8 @@ nsTArray_Impl::AppendElements(nsTArray_Impl&& aArray) index_type len = Length(); index_type otherLen = aArray.Length(); - if (!Alloc::Successful(this->template EnsureCapacity( - len + otherLen, sizeof(elem_type)))) { + if (!Alloc::Successful(this->template ExtendCapacity( + len, otherLen, sizeof(elem_type)))) { return nullptr; } copy_type::MoveNonOverlappingRegion(Elements() + len, aArray.Elements(), otherLen, @@ -2140,6 +2153,7 @@ template auto nsTArray_Impl::AppendElement(Item&& aItem) -> elem_type* { + // Length() + 1 is guaranteed to not overflow, so EnsureCapacity is OK. if (!ActualAlloc::Successful(this->template EnsureCapacity( Length() + 1, sizeof(elem_type)))) { return nullptr; -- cgit v1.2.3