diff --git a/dom/canvas/QueueParamTraits.h b/dom/canvas/QueueParamTraits.h index 87fe910675ec..a67f5abf51ad 100644 --- a/dom/canvas/QueueParamTraits.h +++ b/dom/canvas/QueueParamTraits.h @@ -261,6 +261,15 @@ struct QueueParamTraits { // --------------------------------------------------------------- +template +Maybe AsValidEnum(const std::underlying_type_t raw_val) { + const auto raw_enum = T{raw_val}; // This is the risk we prevent! + if (!IsEnumCase(raw_enum)) return {}; + return Some(raw_enum); +} + +// - + template struct QueueParamTraits_IsEnumCase { template diff --git a/dom/canvas/TiedFields.h b/dom/canvas/TiedFields.h index a071da9dab6b..2df225aeee01 100644 --- a/dom/canvas/TiedFields.h +++ b/dom/canvas/TiedFields.h @@ -131,34 +131,42 @@ constexpr bool AssertTiedFieldsAreExhaustive() { // - /** - * PaddingField can be used to pad out a struct so that it's not - * implicitly padded by struct rules, but also can't be accidentally initialized - * via Aggregate Initialization. (TiedFields serialization checks rely on object - * fields leaving no implicit padding bytes, but explicit padding fields are - * fine) While you can use e.g. `uint8_t _padding[3];`, consider instead - * `PaddingField _padding;` for clarity and to move the `3` nearer - * to the `uint8_t`. + * Padding can be used to pad out a struct so that it's not implicitly + * padded by struct rules. + * You can also just add your padding to TiedFields, but by explicitly typing + * padding like this, serialization can make a choice whether to copy Padding, + * or instead to omit the copy. + * + * Omitting the copy isn't always faster. + * struct Entry { + * uint16_t key; + * Padding padding; + * uint32_t val; + * auto MutTiedFields() { return std::tie(key, padding, val); } + * }; + * If you serialize Padding, the serialized size is 8, and the compiler will + * optimize serialization to a single 8-byte memcpy. + * If your serialization omits Padding, the serialized size of Entry shrinks + * by 25%. If you have a big list of Entrys, maybe this is a big savings! + * However, by optimizing for size here you sacrifice speed, because this splits + * the single memcpy into two: a 2-byte memcpy and a 4-byte memcpy. + * + * Explicitly marking padding gives callers the option of choosing. */ -template -struct PaddingField { - static_assert(!std::is_array_v, "Use PaddingField not ."); +template +struct Padding { + T ignored; - std::array ignored = {}; - - PaddingField() {} - - friend constexpr bool operator==(const PaddingField&, const PaddingField&) { + friend constexpr bool operator==(const Padding&, const Padding&) { return true; } - friend constexpr bool operator<(const PaddingField&, const PaddingField&) { + friend constexpr bool operator<(const Padding&, const Padding&) { return false; } - - auto MutTiedFields() { return std::tie(ignored); } }; -static_assert(sizeof(PaddingField) == 1); -static_assert(sizeof(PaddingField) == 2); -static_assert(sizeof(PaddingField) == 4); +static_assert(sizeof(Padding) == 1); +static_assert(sizeof(Padding) == 2); +static_assert(sizeof(Padding) == 4); // - @@ -194,7 +202,7 @@ static_assert(AreAllBytesTiedFields()); struct Eel { // Like a Fish, but you can skip serializing the padding. bool b; - PaddingField padding; + Padding padding[3]; int i; constexpr auto MutTiedFields() { return std::tie(i, b, padding); } diff --git a/dom/canvas/WebGLIpdl.h b/dom/canvas/WebGLIpdl.h index 45a5c5ad648d..5a35c059099c 100644 --- a/dom/canvas/WebGLIpdl.h +++ b/dom/canvas/WebGLIpdl.h @@ -244,45 +244,6 @@ struct ParamTraits final : public mozilla::dom::WebIDLEnumSerializer< mozilla::dom::PredefinedColorSpace> {}; -// - -// ParamTraits_IsEnumCase - -/* -`IsEnumCase(T) -> bool` guarantees that we never have false negatives or false -positives due to adding or removing enum cases to enums, and forgetting to -update their serializations. Also, it allows enums to be non-continguous, unlike -ContiguousEnumSerializer. -*/ - -template -struct ParamTraits_IsEnumCase { - static bool Write(MessageWriter* const writer, const T& in) { - MOZ_ASSERT(IsEnumCase(in)); - const auto shadow = static_cast>(in); - WriteParam(writer, shadow); - return true; - } - - static bool Read(MessageReader* const reader, T* const out) { - auto shadow = std::underlying_type_t{}; - if (!ReadParam(reader, &shadow)) return false; - const auto e = mozilla::AsValidEnum(shadow); - if (!e) return false; - *out = *e; - return true; - } -}; - -// - - -#define USE_IS_ENUM_CASE(T) \ - template <> \ - struct ParamTraits : public ParamTraits_IsEnumCase {}; - -USE_IS_ENUM_CASE(mozilla::webgl::OptionalRenderableFormatBits) - -#undef USE_IS_ENUM_CASE - // - // ParamTraits_TiedFields @@ -311,10 +272,6 @@ struct ParamTraits_TiedFields { } }; -template -struct ParamTraits> final - : public ParamTraits_TiedFields> {}; - // - template <> @@ -652,6 +609,35 @@ struct ParamTraits> final { } }; +// - + +template +struct ParamTraits_IsEnumCase { + using T = TT; + + static void Write(IPC::MessageWriter* const writer, const T& in) { + MOZ_RELEASE_ASSERT(IsEnumCase(in)); + WriteParam(writer, mozilla::UnderlyingValue(in)); + } + + static bool Read(IPC::MessageReader* const reader, T* const out) { + std::underlying_type_t rawVal; + if (!ReadParam(reader, &rawVal)) return false; + *out = static_cast(rawVal); + return IsEnumCase(*out); + } +}; + +// - + +#define USE_IS_ENUM_CASE(T) \ + template <> \ + struct ParamTraits : public ParamTraits_IsEnumCase {}; + +USE_IS_ENUM_CASE(mozilla::webgl::OptionalRenderableFormatBits) + +#undef USE_IS_ENUM_CASE + } // namespace IPC #endif diff --git a/dom/canvas/WebGLTypes.h b/dom/canvas/WebGLTypes.h index 4e1fa1905ef9..f2413da61649 100644 --- a/dom/canvas/WebGLTypes.h +++ b/dom/canvas/WebGLTypes.h @@ -1224,15 +1224,6 @@ inline bool StartsWith(const std::string_view str, // - -template -Maybe AsValidEnum(const std::underlying_type_t raw_val) { - const auto raw_enum = T{raw_val}; // This is the risk we prevent! - if (!IsEnumCase(raw_enum)) return {}; - return Some(raw_enum); -} - -// - - namespace webgl { // In theory, this number can be unbounded based on the driver. However, no diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 2faee98046fb..60b295e71f7c 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -644,10 +644,6 @@ static const char* sObserverTopics[] = { DEFAULT_TIMEZONE_CHANGED_OBSERVER_TOPIC, }; -void ContentParent_NotifyUpdatedDictionaries() { - ContentParent::NotifyUpdatedDictionaries(); -} - // PreallocateProcess is called by the PreallocatedProcessManager. // ContentParent then takes this process back within GetNewOrUsedBrowserProcess. /*static*/ already_AddRefed diff --git a/dom/ipc/ContentParent_NotifyUpdatedDictionaries.h b/dom/ipc/ContentParent_NotifyUpdatedDictionaries.h deleted file mode 100644 index 0c78fb874d3a..000000000000 --- a/dom/ipc/ContentParent_NotifyUpdatedDictionaries.h +++ /dev/null @@ -1,17 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_dom_ContentParent_NotifyUpdatedDictionaries_h -#define mozilla_dom_ContentParent_NotifyUpdatedDictionaries_h - -// Avoid including ContentParent.h because it ends up including WebGLTypes.h, -// where we have our mozilla::malloc(ForbidNarrowing) overrides, which -// cause issues with the way hunspell overrides malloc for itself. -namespace mozilla::dom { -void ContentParent_NotifyUpdatedDictionaries(); -} // namespace mozilla::dom - -#endif // mozilla_dom_ContentParent_NotifyUpdatedDictionaries_h diff --git a/dom/ipc/moz.build b/dom/ipc/moz.build index 35b6039d894c..3f10b9fbab19 100644 --- a/dom/ipc/moz.build +++ b/dom/ipc/moz.build @@ -52,7 +52,6 @@ EXPORTS.mozilla.dom += [ "CoalescedWheelData.h", "ContentChild.h", "ContentParent.h", - "ContentParent_NotifyUpdatedDictionaries.h", "ContentProcess.h", "ContentProcessManager.h", "CSPMessageUtils.h", diff --git a/dom/media/MediaInfo.h b/dom/media/MediaInfo.h index e6e7e0fe7569..73704d1593e3 100644 --- a/dom/media/MediaInfo.h +++ b/dom/media/MediaInfo.h @@ -109,16 +109,12 @@ struct FlacCodecSpecificData { RefPtr mStreamInfoBinaryBlob{new MediaByteBuffer}; }; -struct Mp3CodecSpecificData final { +struct Mp3CodecSpecificData { bool operator==(const Mp3CodecSpecificData& rhs) const { return mEncoderDelayFrames == rhs.mEncoderDelayFrames && mEncoderPaddingFrames == rhs.mEncoderPaddingFrames; } - auto MutTiedFields() { - return std::tie(mEncoderDelayFrames, mEncoderPaddingFrames); - } - // The number of frames that should be skipped from the beginning of the // decoded stream. // See https://bugzilla.mozilla.org/show_bug.cgi?id=1566389 for more info. diff --git a/dom/media/ipc/MediaIPCUtils.h b/dom/media/ipc/MediaIPCUtils.h index 9598e1557f57..fecf41c32534 100644 --- a/dom/media/ipc/MediaIPCUtils.h +++ b/dom/media/ipc/MediaIPCUtils.h @@ -15,7 +15,6 @@ #include "ipc/EnumSerializer.h" #include "mozilla/EnumSet.h" #include "mozilla/GfxMessageUtils.h" -#include "mozilla/dom/WebGLIpdl.h" #include "mozilla/gfx/Rect.h" #include "mozilla/dom/MFCDMSerializers.h" @@ -140,7 +139,7 @@ struct ParamTraits { template <> struct ParamTraits - : public ParamTraits_TiedFields {}; + : public PlainOldDataSerializer {}; template <> struct ParamTraits { diff --git a/dom/network/TCPSocket.cpp b/dom/network/TCPSocket.cpp index 577e630952df..f7ac7d3f9b6b 100644 --- a/dom/network/TCPSocket.cpp +++ b/dom/network/TCPSocket.cpp @@ -49,6 +49,9 @@ #include "secerr.h" #include "sslerr.h" +#define BUFFER_SIZE 65536 +#define NETWORK_STATS_THRESHOLD 65536 + using namespace mozilla::dom; NS_IMPL_CYCLE_COLLECTION(LegacyMozTCPSocket, mGlobal) diff --git a/extensions/spellcheck/hunspell/glue/mozHunspell.cpp b/extensions/spellcheck/hunspell/glue/mozHunspell.cpp index 1c6a60ae8150..a69dcd6b050d 100644 --- a/extensions/spellcheck/hunspell/glue/mozHunspell.cpp +++ b/extensions/spellcheck/hunspell/glue/mozHunspell.cpp @@ -69,14 +69,14 @@ #include "nsIPrefBranch.h" #include "nsIPrefService.h" #include "nsNetUtil.h" -#include "prenv.h" +#include "mozilla/dom/ContentParent.h" #include "mozilla/Components.h" #include "mozilla/Services.h" -#include "mozilla/dom/ContentParent_NotifyUpdatedDictionaries.h" #include #include +using mozilla::dom::ContentParent; using namespace mozilla; NS_IMPL_CYCLE_COLLECTING_ADDREF(mozHunspell) @@ -294,7 +294,7 @@ void mozHunspell::DictionariesChanged(bool aNotifyChildProcesses) { mozInlineSpellChecker::UpdateCanEnableInlineSpellChecking(); if (aNotifyChildProcesses) { - mozilla::dom::ContentParent_NotifyUpdatedDictionaries(); + ContentParent::NotifyUpdatedDictionaries(); } // Check if the current dictionaries are still available. diff --git a/gfx/layers/FrameMetrics.h b/gfx/layers/FrameMetrics.h index c79a088e539a..5d13d36703cd 100644 --- a/gfx/layers/FrameMetrics.h +++ b/gfx/layers/FrameMetrics.h @@ -700,7 +700,7 @@ MOZ_DEFINE_ENUM_CLASS_WITH_BASE( std::ostream& operator<<(std::ostream& aStream, const OverscrollBehavior& aBehavior); -struct OverscrollBehaviorInfo final { +struct OverscrollBehaviorInfo { OverscrollBehaviorInfo(); // Construct from StyleOverscrollBehavior values. @@ -711,8 +711,6 @@ struct OverscrollBehaviorInfo final { friend std::ostream& operator<<(std::ostream& aStream, const OverscrollBehaviorInfo& aInfo); - auto MutTiedFields() { return std::tie(mBehaviorX, mBehaviorY); } - OverscrollBehavior mBehaviorX; OverscrollBehavior mBehaviorY; }; diff --git a/gfx/layers/LayersTypes.h b/gfx/layers/LayersTypes.h index c02851d81f8e..340ea76fa59b 100644 --- a/gfx/layers/LayersTypes.h +++ b/gfx/layers/LayersTypes.h @@ -46,11 +46,9 @@ class TextureHost; #undef NONE #undef OPAQUE -struct LayersId final { +struct LayersId { uint64_t mId = 0; - auto MutTiedFields() { return std::tie(mId); } - bool IsValid() const { return mId != 0; } // Allow explicit cast to a uint64_t for now @@ -77,11 +75,9 @@ struct LayersId final { }; template -struct BaseTransactionId final { +struct BaseTransactionId { uint64_t mId = 0; - auto MutTiedFields() { return std::tie(mId); } - bool IsValid() const { return mId != 0; } [[nodiscard]] BaseTransactionId Next() const { diff --git a/gfx/layers/ipc/LayersMessageUtils.h b/gfx/layers/ipc/LayersMessageUtils.h index a0da6154d538..a4e9557ac3a3 100644 --- a/gfx/layers/ipc/LayersMessageUtils.h +++ b/gfx/layers/ipc/LayersMessageUtils.h @@ -18,7 +18,6 @@ #include "ipc/IPCMessageUtils.h" #include "mozilla/ScrollSnapInfo.h" #include "mozilla/ServoBindings.h" -#include "mozilla/dom/WebGLIpdl.h" #include "mozilla/ipc/ByteBuf.h" #include "mozilla/ipc/ProtocolMessageUtils.h" #include "mozilla/layers/APZInputBridge.h" @@ -49,11 +48,15 @@ namespace IPC { template <> struct ParamTraits - : public ParamTraits_TiedFields {}; + : public PlainOldDataSerializer {}; template struct ParamTraits> - : public ParamTraits_TiedFields> {}; + : public PlainOldDataSerializer> {}; + +template <> +struct ParamTraits + : public PlainOldDataSerializer {}; template <> struct ParamTraits { @@ -416,7 +419,7 @@ struct ParamTraits template <> struct ParamTraits - : public ParamTraits_IsEnumCase {}; + : public PlainOldDataSerializer {}; template <> struct ParamTraits { @@ -492,12 +495,26 @@ struct ParamTraits { }; template <> -struct ParamTraits - : public ParamTraits_TiedFields {}; +struct ParamTraits { + // Not using PlainOldDataSerializer so we get enum validation + // for the members. + + typedef mozilla::layers::OverscrollBehaviorInfo paramType; + + static void Write(MessageWriter* aWriter, const paramType& aParam) { + WriteParam(aWriter, aParam.mBehaviorX); + WriteParam(aWriter, aParam.mBehaviorY); + } + + static bool Read(MessageReader* aReader, paramType* aResult) { + return (ReadParam(aReader, &aResult->mBehaviorX) && + ReadParam(aReader, &aResult->mBehaviorY)); + } +}; template struct ParamTraits> - : public ParamTraits_TiedFields> {}; + : PlainOldDataSerializer> {}; template <> struct ParamTraits diff --git a/gfx/layers/ipc/SharedSurfacesMemoryReport.h b/gfx/layers/ipc/SharedSurfacesMemoryReport.h index 31e27bccadf5..81baf1349f03 100644 --- a/gfx/layers/ipc/SharedSurfacesMemoryReport.h +++ b/gfx/layers/ipc/SharedSurfacesMemoryReport.h @@ -12,7 +12,6 @@ #include "base/process.h" #include "ipc/IPCMessageUtils.h" #include "ipc/IPCMessageUtilsSpecializations.h" -#include "mozilla/dom/WebGLIpdl.h" #include "mozilla/gfx/Point.h" // for IntSize namespace mozilla { @@ -27,16 +26,8 @@ class SharedSurfacesMemoryReport final { int32_t mStride; uint32_t mConsumers; bool mCreatorRef; - PaddingField _padding; - - auto MutTiedFields() { - return std::tie(mCreatorPid, mSize, mStride, mConsumers, mCreatorRef, - _padding); - } }; - auto MutTiedFields() { return std::tie(mSurfaces); } - std::unordered_map mSurfaces; }; @@ -46,13 +37,21 @@ class SharedSurfacesMemoryReport final { namespace IPC { template <> -struct ParamTraits - : public ParamTraits_TiedFields< - mozilla::layers::SharedSurfacesMemoryReport> {}; +struct ParamTraits { + typedef mozilla::layers::SharedSurfacesMemoryReport paramType; + + static void Write(MessageWriter* aWriter, const paramType& aParam) { + WriteParam(aWriter, aParam.mSurfaces); + } + + static bool Read(MessageReader* aReader, paramType* aResult) { + return ReadParam(aReader, &aResult->mSurfaces); + } +}; template <> struct ParamTraits - : public ParamTraits_TiedFields< + : public PlainOldDataSerializer< mozilla::layers::SharedSurfacesMemoryReport::SurfaceEntry> {}; } // namespace IPC diff --git a/layout/generic/ScrollGeneration.h b/layout/generic/ScrollGeneration.h index 5f14844e3397..90eb243e9e87 100644 --- a/layout/generic/ScrollGeneration.h +++ b/layout/generic/ScrollGeneration.h @@ -7,7 +7,6 @@ #include #include -#include namespace mozilla { @@ -24,7 +23,7 @@ std::ostream& operator<<(std::ostream& aStream, const ScrollGeneration& aGen); template -struct ScrollGeneration final { +struct ScrollGeneration { friend struct ScrollGenerationCounter; private: @@ -44,8 +43,6 @@ struct ScrollGeneration final { friend std::ostream& operator<< <>(std::ostream& aStream, const ScrollGeneration& aGen); - auto MutTiedFields() { return std::tie(mValue); } - private: uint64_t mValue; }; diff --git a/layout/generic/ScrollSnapTargetId.h b/layout/generic/ScrollSnapTargetId.h index a4a281f5e77f..f53e736fa1b9 100644 --- a/layout/generic/ScrollSnapTargetId.h +++ b/layout/generic/ScrollSnapTargetId.h @@ -17,7 +17,6 @@ namespace mozilla { enum class ScrollSnapTargetId : uintptr_t { None = 0, }; -inline constexpr bool IsEnumCase(ScrollSnapTargetId) { return true; } struct ScrollSnapTargetIds { CopyableTArray mIdsOnX; diff --git a/toolkit/components/telemetry/core/ipc/TelemetryComms.h b/toolkit/components/telemetry/core/ipc/TelemetryComms.h index 57c875dedb71..75f59209b0db 100644 --- a/toolkit/components/telemetry/core/ipc/TelemetryComms.h +++ b/toolkit/components/telemetry/core/ipc/TelemetryComms.h @@ -12,7 +12,6 @@ #include "mozilla/TelemetryProcessEnums.h" #include "mozilla/TimeStamp.h" #include "mozilla/Variant.h" -#include "mozilla/dom/WebGLIpdl.h" #include "nsITelemetry.h" namespace mozilla { @@ -97,13 +96,6 @@ struct DiscardedData { uint32_t mDiscardedScalarActions; uint32_t mDiscardedKeyedScalarActions; uint32_t mDiscardedChildEvents; - - auto MutTiedFields() { - return std::tie(mDiscardedHistogramAccumulations, - mDiscardedKeyedHistogramAccumulations, - mDiscardedScalarActions, mDiscardedKeyedScalarActions, - mDiscardedChildEvents); - } }; } // namespace Telemetry @@ -401,7 +393,7 @@ struct ParamTraits { template <> struct ParamTraits - : public ParamTraits_TiedFields {}; + : public PlainOldDataSerializer {}; } // namespace IPC