From ab8fa1ab81a9e788dc417355c98a6d895788eaef Mon Sep 17 00:00:00 2001 From: Alex Franchuk Date: Tue, 6 Aug 2024 18:16:08 +0000 Subject: [PATCH] Bug 1454819 - Simplify SharedMemory classes r=ipc-reviewers,nika Differential Revision: https://phabricator.services.mozilla.com/D217487 --- dom/canvas/DrawTargetWebgl.cpp | 4 +- dom/canvas/DrawTargetWebgl.h | 8 +- dom/canvas/QueueParamTraits.h | 2 +- dom/canvas/WebGLTypes.h | 2 +- gfx/layers/CanvasDrawEventRecorder.cpp | 6 +- gfx/layers/CanvasDrawEventRecorder.h | 16 +-- gfx/layers/RecordedCanvasEventImpl.h | 2 +- gfx/layers/SourceSurfaceSharedData.cpp | 21 ++- gfx/layers/SourceSurfaceSharedData.h | 21 +-- gfx/layers/apz/src/AsyncPanZoomController.cpp | 6 +- gfx/layers/apz/src/AsyncPanZoomController.h | 2 +- gfx/layers/ipc/CanvasChild.cpp | 17 ++- gfx/layers/ipc/CanvasChild.h | 6 +- gfx/layers/ipc/CanvasTranslator.cpp | 34 +++-- gfx/layers/ipc/CanvasTranslator.h | 20 +-- gfx/layers/ipc/LayersSurfaces.ipdlh | 2 +- gfx/layers/ipc/PCanvas.ipdl | 4 +- gfx/layers/ipc/PCompositorManager.ipdl | 4 +- gfx/layers/ipc/SharedSurfacesChild.cpp | 2 +- gfx/thebes/SharedFontList-impl.h | 4 +- .../src/chrome/common/ipc_message_utils.cc | 9 +- ipc/glue/BigBuffer.cpp | 12 +- ipc/glue/CrossProcessMutex.h | 6 +- ipc/glue/CrossProcessMutex_posix.cpp | 10 +- ipc/glue/CrossProcessSemaphore.h | 8 +- ipc/glue/CrossProcessSemaphore_posix.cpp | 10 +- ipc/glue/DataPipe.cpp | 26 ++-- ipc/glue/DataPipe.h | 8 +- ipc/glue/GeckoChildProcessHost.cpp | 2 +- ipc/glue/RawShmem.cpp | 14 +- ipc/glue/RawShmem.h | 10 +- ipc/glue/SharedMemory.cpp | 116 +++++++++++----- ipc/glue/SharedMemory.h | 126 ++++-------------- ipc/glue/SharedMemoryBasic.h | 16 --- ipc/glue/SharedMemoryBasic_chromium.h | 89 ------------- ipc/glue/SharedMemoryBasic_mach.h | 75 ----------- ipc/glue/SharedMemoryImpl_chromium.cpp | 47 +++++++ ipc/glue/SharedMemoryImpl_chromium.h | 51 +++++++ ...asic_mach.mm => SharedMemoryImpl_mach.cpp} | 65 +++++---- ipc/glue/SharedMemoryImpl_mach.h | 56 ++++++++ ipc/glue/SharedMemory_posix.cpp | 6 +- ipc/glue/SharedMemory_windows.cpp | 10 +- ipc/glue/Shmem.cpp | 10 +- ipc/glue/Shmem.h | 5 +- ipc/glue/moz.build | 10 +- ipc/gtest/TestBigBuffer.cpp | 4 +- ipc/gtest/TestSharedMemory.cpp | 5 +- 47 files changed, 460 insertions(+), 529 deletions(-) delete mode 100644 ipc/glue/SharedMemoryBasic.h delete mode 100644 ipc/glue/SharedMemoryBasic_chromium.h delete mode 100644 ipc/glue/SharedMemoryBasic_mach.h create mode 100644 ipc/glue/SharedMemoryImpl_chromium.cpp create mode 100644 ipc/glue/SharedMemoryImpl_chromium.h rename ipc/glue/{SharedMemoryBasic_mach.mm => SharedMemoryImpl_mach.cpp} (74%) create mode 100644 ipc/glue/SharedMemoryImpl_mach.h diff --git a/dom/canvas/DrawTargetWebgl.cpp b/dom/canvas/DrawTargetWebgl.cpp index 95a9216f0610..f01c56e398d0 100644 --- a/dom/canvas/DrawTargetWebgl.cpp +++ b/dom/canvas/DrawTargetWebgl.cpp @@ -304,7 +304,7 @@ bool DrawTargetWebgl::Init(const IntSize& size, const SurfaceFormat format, return false; } - auto shmem = MakeRefPtr(); + auto shmem = MakeRefPtr(); if (NS_WARN_IF(!shmem->Create(shmemSize)) || NS_WARN_IF(!shmem->Map(shmemSize))) { return false; @@ -316,7 +316,7 @@ bool DrawTargetWebgl::Init(const IntSize& size, const SurfaceFormat format, mSkia = new DrawTargetSkia; auto stride = layers::ImageDataSerializer::ComputeRGBStride( SurfaceFormat::B8G8R8A8, size.width); - if (!mSkia->Init(reinterpret_cast(mShmem->memory()), size, stride, + if (!mSkia->Init(reinterpret_cast(mShmem->Memory()), size, stride, SurfaceFormat::B8G8R8A8, true)) { return false; } diff --git a/dom/canvas/DrawTargetWebgl.h b/dom/canvas/DrawTargetWebgl.h index 77ced97843d3..6c0e1d4543d1 100644 --- a/dom/canvas/DrawTargetWebgl.h +++ b/dom/canvas/DrawTargetWebgl.h @@ -14,7 +14,7 @@ #include "mozilla/LinkedList.h" #include "mozilla/WeakPtr.h" #include "mozilla/ThreadLocal.h" -#include "mozilla/ipc/SharedMemoryBasic.h" +#include "mozilla/ipc/SharedMemory.h" #include "mozilla/layers/LayersTypes.h" #include @@ -368,7 +368,7 @@ class DrawTargetWebgl : public DrawTarget, public SupportsWeakPtr { // Skia DT pointing to the same pixel data, but without any applied clips. RefPtr mSkiaNoClip; // The Shmem backing the Skia DT, if applicable. - RefPtr mShmem; + RefPtr mShmem; // The currently cached snapshot of the WebGL context RefPtr mSnapshot; // The mappable size of mShmem. @@ -591,9 +591,9 @@ class DrawTargetWebgl : public DrawTarget, public SupportsWeakPtr { return stream.str(); } - mozilla::ipc::SharedMemoryBasic::Handle TakeShmemHandle() const { + mozilla::ipc::SharedMemory::Handle TakeShmemHandle() const { return mShmem ? mShmem->TakeHandle() - : mozilla::ipc::SharedMemoryBasic::NULLHandle(); + : mozilla::ipc::SharedMemory::NULLHandle(); } uint32_t GetShmemSize() const { return mShmemSize; } diff --git a/dom/canvas/QueueParamTraits.h b/dom/canvas/QueueParamTraits.h index fd1883f62bae..d83f6ac456d0 100644 --- a/dom/canvas/QueueParamTraits.h +++ b/dom/canvas/QueueParamTraits.h @@ -13,7 +13,7 @@ #include "mozilla/Assertions.h" #include "mozilla/IntegerRange.h" #include "mozilla/ipc/ProtocolUtils.h" -#include "mozilla/ipc/SharedMemoryBasic.h" +#include "mozilla/ipc/SharedMemory.h" #include "mozilla/Logging.h" #include "mozilla/TimeStamp.h" #include "nsExceptionHandler.h" diff --git a/dom/canvas/WebGLTypes.h b/dom/canvas/WebGLTypes.h index d75af79e9bab..eea2500181f2 100644 --- a/dom/canvas/WebGLTypes.h +++ b/dom/canvas/WebGLTypes.h @@ -39,7 +39,7 @@ #include "nsTArray.h" #include "nsString.h" #include "mozilla/dom/WebGLRenderingContextBinding.h" -#include "mozilla/ipc/SharedMemoryBasic.h" +#include "mozilla/ipc/SharedMemory.h" #include "TiedFields.h" // Manual reflection of WebIDL typedefs that are different from their diff --git a/gfx/layers/CanvasDrawEventRecorder.cpp b/gfx/layers/CanvasDrawEventRecorder.cpp index 8f3cd4be5c7e..7ffde793ffc4 100644 --- a/gfx/layers/CanvasDrawEventRecorder.cpp +++ b/gfx/layers/CanvasDrawEventRecorder.cpp @@ -21,12 +21,12 @@ namespace mozilla { namespace layers { struct ShmemAndHandle { - RefPtr shmem; + RefPtr shmem; Handle handle; }; static Maybe CreateAndMapShmem(size_t aSize) { - auto shmem = MakeRefPtr(); + auto shmem = MakeRefPtr(); if (!shmem->Create(aSize) || !shmem->Map(aSize)) { return Nothing(); } @@ -66,7 +66,7 @@ bool CanvasDrawEventRecorder::Init(TextureType aTextureType, return false; } - mHeader = static_cast(header->shmem->memory()); + mHeader = static_cast(header->shmem->Memory()); mHeader->eventCount = 0; mHeader->writerWaitCount = 0; mHeader->writerState = State::Processing; diff --git a/gfx/layers/CanvasDrawEventRecorder.h b/gfx/layers/CanvasDrawEventRecorder.h index aa95eec3e6b9..b0d5b0ef32e7 100644 --- a/gfx/layers/CanvasDrawEventRecorder.h +++ b/gfx/layers/CanvasDrawEventRecorder.h @@ -12,7 +12,7 @@ #include "mozilla/Atomics.h" #include "mozilla/gfx/DrawEventRecorder.h" #include "mozilla/ipc/CrossProcessSemaphore.h" -#include "mozilla/ipc/SharedMemoryBasic.h" +#include "mozilla/ipc/SharedMemory.h" #include "mozilla/layers/LayersTypes.h" #include "mozilla/RefPtr.h" #include "mozilla/UniquePtr.h" @@ -27,7 +27,7 @@ class ThreadSafeWorkerRef; namespace layers { -typedef mozilla::ipc::SharedMemoryBasic::Handle Handle; +typedef mozilla::ipc::SharedMemory::Handle Handle; typedef mozilla::CrossProcessSemaphoreHandle CrossProcessSemaphoreHandle; class CanvasDrawEventRecorder final : public gfx::DrawEventRecorderPrivate, @@ -163,16 +163,16 @@ class CanvasDrawEventRecorder final : public gfx::DrawEventRecorderPrivate, UniquePtr mHelpers; TextureType mTextureType = TextureType::Unknown; - RefPtr mHeaderShmem; + RefPtr mHeaderShmem; Header* mHeader = nullptr; struct CanvasBuffer : public gfx::ContiguousBuffer { - RefPtr shmem; + RefPtr shmem; CanvasBuffer() : ContiguousBuffer(nullptr) {} - explicit CanvasBuffer(RefPtr&& aShmem) - : ContiguousBuffer(static_cast(aShmem->memory()), + explicit CanvasBuffer(RefPtr&& aShmem) + : ContiguousBuffer(static_cast(aShmem->Memory()), aShmem->Size()), shmem(std::move(aShmem)) {} @@ -180,9 +180,9 @@ class CanvasDrawEventRecorder final : public gfx::DrawEventRecorderPrivate, }; struct RecycledBuffer { - RefPtr shmem; + RefPtr shmem; int64_t eventCount = 0; - explicit RecycledBuffer(RefPtr&& aShmem, + explicit RecycledBuffer(RefPtr&& aShmem, int64_t aEventCount) : shmem(std::move(aShmem)), eventCount(aEventCount) {} size_t Capacity() { return shmem->Size(); } diff --git a/gfx/layers/RecordedCanvasEventImpl.h b/gfx/layers/RecordedCanvasEventImpl.h index f931691e3785..d036fc7f4927 100644 --- a/gfx/layers/RecordedCanvasEventImpl.h +++ b/gfx/layers/RecordedCanvasEventImpl.h @@ -26,7 +26,7 @@ using gfx::ReadElement; using gfx::ReferencePtr; using gfx::SurfaceFormat; using gfx::WriteElement; -using ipc::SharedMemoryBasic; +using ipc::SharedMemory; const EventType CANVAS_BEGIN_TRANSACTION = EventType::LAST; const EventType CANVAS_END_TRANSACTION = EventType(EventType::LAST + 1); diff --git a/gfx/layers/SourceSurfaceSharedData.cpp b/gfx/layers/SourceSurfaceSharedData.cpp index 622f68855d00..b8d1456fba0a 100644 --- a/gfx/layers/SourceSurfaceSharedData.cpp +++ b/gfx/layers/SourceSurfaceSharedData.cpp @@ -32,7 +32,7 @@ namespace gfx { void SourceSurfaceSharedDataWrapper::Init(const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat, - SharedMemoryBasic::Handle aHandle, + SharedMemory::Handle aHandle, base::ProcessId aCreatorPid) { MOZ_ASSERT(!mBuf); mSize = aSize; @@ -41,7 +41,7 @@ void SourceSurfaceSharedDataWrapper::Init(const IntSize& aSize, int32_t aStride, mCreatorPid = aCreatorPid; size_t len = GetAlignedDataLength(); - mBuf = MakeAndAddRef(); + mBuf = MakeAndAddRef(); if (!mBuf->SetHandle(std::move(aHandle), ipc::SharedMemory::RightsReadOnly)) { MOZ_CRASH("Invalid shared memory handle!"); } @@ -153,7 +153,7 @@ bool SourceSurfaceSharedData::Init(const IntSize& aSize, int32_t aStride, mFormat = aFormat; size_t len = GetAlignedDataLength(); - mBuf = new SharedMemoryBasic(); + mBuf = new SharedMemory(); if (NS_WARN_IF(!mBuf->Create(len)) || NS_WARN_IF(!mBuf->Map(len))) { mBuf = nullptr; return false; @@ -190,13 +190,12 @@ uint8_t* SourceSurfaceSharedData::GetDataInternal() const { if (MOZ_UNLIKELY(mOldBuf)) { MOZ_ASSERT(mMapCount > 0); MOZ_ASSERT(mFinalized); - return static_cast(mOldBuf->memory()); + return static_cast(mOldBuf->Memory()); } - return static_cast(mBuf->memory()); + return static_cast(mBuf->Memory()); } -nsresult SourceSurfaceSharedData::CloneHandle( - SharedMemoryBasic::Handle& aHandle) { +nsresult SourceSurfaceSharedData::CloneHandle(SharedMemory::Handle& aHandle) { MutexAutoLock lock(mMutex); MOZ_ASSERT(mHandleCount > 0); @@ -241,15 +240,15 @@ bool SourceSurfaceSharedData::ReallocHandle() { } size_t len = GetAlignedDataLength(); - RefPtr buf = new SharedMemoryBasic(); + RefPtr buf = new SharedMemory(); if (NS_WARN_IF(!buf->Create(len)) || NS_WARN_IF(!buf->Map(len))) { return false; } size_t copyLen = GetDataLength(); - memcpy(buf->memory(), mBuf->memory(), copyLen); + memcpy(buf->Memory(), mBuf->Memory(), copyLen); #ifdef SHARED_SURFACE_PROTECT_FINALIZED - buf->Protect(static_cast(buf->memory()), len, RightsRead); + buf->Protect(static_cast(buf->Memory()), len, RightsRead); #endif if (mMapCount > 0 && !mOldBuf) { @@ -267,7 +266,7 @@ void SourceSurfaceSharedData::Finalize() { #ifdef SHARED_SURFACE_PROTECT_FINALIZED size_t len = GetAlignedDataLength(); - mBuf->Protect(static_cast(mBuf->memory()), len, RightsRead); + mBuf->Protect(static_cast(mBuf->Memory()), len, RightsRead); #endif mFinalized = true; diff --git a/gfx/layers/SourceSurfaceSharedData.h b/gfx/layers/SourceSurfaceSharedData.h index 73743a839dbf..ddd87dcf9dce 100644 --- a/gfx/layers/SourceSurfaceSharedData.h +++ b/gfx/layers/SourceSurfaceSharedData.h @@ -7,9 +7,10 @@ #ifndef MOZILLA_GFX_SOURCESURFACESHAREDDATA_H_ #define MOZILLA_GFX_SOURCESURFACESHAREDDATA_H_ +#include "base/process.h" #include "mozilla/gfx/2D.h" #include "mozilla/Mutex.h" -#include "mozilla/ipc/SharedMemoryBasic.h" +#include "mozilla/ipc/SharedMemory.h" #include "nsExpirationTracker.h" namespace mozilla { @@ -29,11 +30,11 @@ class SourceSurfaceSharedData; * original surface is a signal which feeds into SharedSurfacesParent to decide * to release the SourceSurfaceSharedDataWrapper. * - * If it is in a different process, mBuf is a new SharedMemoryBasic object which + * If it is in a different process, mBuf is a new SharedMemory object which * mapped in the given shared memory handle as read only memory. */ class SourceSurfaceSharedDataWrapper final : public DataSourceSurface { - typedef mozilla::ipc::SharedMemoryBasic SharedMemoryBasic; + typedef mozilla::ipc::SharedMemory SharedMemory; public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceSharedDataWrapper, @@ -47,7 +48,7 @@ class SourceSurfaceSharedDataWrapper final : public DataSourceSurface { mCreatorRef(true) {} void Init(const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat, - SharedMemoryBasic::Handle aHandle, base::ProcessId aCreatorPid); + SharedMemory::Handle aHandle, base::ProcessId aCreatorPid); void Init(SourceSurfaceSharedData* aSurface); @@ -61,7 +62,7 @@ class SourceSurfaceSharedDataWrapper final : public DataSourceSurface { IntSize GetSize() const override { return mSize; } SurfaceFormat GetFormat() const override { return mFormat; } - uint8_t* GetData() override { return static_cast(mBuf->memory()); } + uint8_t* GetData() override { return static_cast(mBuf->Memory()); } bool OnHeap() const override { return false; } @@ -111,7 +112,7 @@ class SourceSurfaceSharedDataWrapper final : public DataSourceSurface { int32_t mStride; uint32_t mConsumers; IntSize mSize; - RefPtr mBuf; + RefPtr mBuf; SurfaceFormat mFormat; base::ProcessId mCreatorPid; bool mCreatorRef; @@ -122,7 +123,7 @@ class SourceSurfaceSharedDataWrapper final : public DataSourceSurface { * source surface. */ class SourceSurfaceSharedData : public DataSourceSurface { - typedef mozilla::ipc::SharedMemoryBasic SharedMemoryBasic; + typedef mozilla::ipc::SharedMemory SharedMemory; public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceSharedData, override) @@ -200,7 +201,7 @@ class SourceSurfaceSharedData : public DataSourceSurface { * NS_ERROR_NOT_AVAILABLE -- handle was closed, need to reallocate. * NS_ERROR_FAILURE -- failed to create a handle to share. */ - nsresult CloneHandle(SharedMemoryBasic::Handle& aHandle); + nsresult CloneHandle(SharedMemory::Handle& aHandle); /** * Indicates the buffer is not expected to be shared with any more processes. @@ -331,8 +332,8 @@ class SourceSurfaceSharedData : public DataSourceSurface { int32_t mHandleCount; Maybe mDirtyRect; IntSize mSize; - RefPtr mBuf; - RefPtr mOldBuf; + RefPtr mBuf; + RefPtr mOldBuf; SurfaceFormat mFormat; bool mClosed : 1; bool mFinalized : 1; diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 1e317ea90fa2..4a95774f00ac 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -87,9 +87,9 @@ #include "nsThreadUtils.h" // for NS_IsMainThread #include "nsViewportInfo.h" // for ViewportMinScale(), ViewportMaxScale() #include "prsystem.h" // for PR_GetPhysicalMemorySize -#include "mozilla/ipc/SharedMemoryBasic.h" // for SharedMemoryBasic -#include "ScrollSnap.h" // for ScrollSnapUtils -#include "ScrollAnimationPhysics.h" // for ComputeAcceleratedWheelDelta +#include "mozilla/ipc/SharedMemory.h" // for SharedMemory +#include "ScrollSnap.h" // for ScrollSnapUtils +#include "ScrollAnimationPhysics.h" // for ComputeAcceleratedWheelDelta #include "SmoothMsdScrollAnimation.h" #include "SmoothScrollAnimation.h" #include "WheelScrollAnimation.h" diff --git a/gfx/layers/apz/src/AsyncPanZoomController.h b/gfx/layers/apz/src/AsyncPanZoomController.h index 694770c6ac7d..10f19453b6ba 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.h +++ b/gfx/layers/apz/src/AsyncPanZoomController.h @@ -42,7 +42,7 @@ namespace mozilla { namespace ipc { -class SharedMemoryBasic; +class SharedMemory; } // namespace ipc diff --git a/gfx/layers/ipc/CanvasChild.cpp b/gfx/layers/ipc/CanvasChild.cpp index 60f1abfac651..79a91e138aa2 100644 --- a/gfx/layers/ipc/CanvasChild.cpp +++ b/gfx/layers/ipc/CanvasChild.cpp @@ -182,8 +182,7 @@ class SourceSurfaceCanvasRecording final : public gfx::SourceSurface { class CanvasDataShmemHolder { public: - CanvasDataShmemHolder(ipc::SharedMemoryBasic* aShmem, - CanvasChild* aCanvasChild) + CanvasDataShmemHolder(ipc::SharedMemory* aShmem, CanvasChild* aCanvasChild) : mMutex("CanvasChild::DataShmemHolder::mMutex"), mShmem(aShmem), mCanvasChild(aCanvasChild) {} @@ -268,7 +267,7 @@ class CanvasDataShmemHolder { private: Mutex mMutex; - RefPtr mShmem; + RefPtr mShmem; RefPtr mCanvasChild MOZ_GUARDED_BY(mMutex); RefPtr mWorkerRef MOZ_GUARDED_BY(mMutex); }; @@ -461,7 +460,7 @@ bool CanvasChild::EnsureDataSurfaceShmem(gfx::IntSize aSize, if (!mDataSurfaceShmemAvailable || mDataSurfaceShmem->Size() < sizeRequired) { RecordEvent(RecordedPauseTranslation()); - auto dataSurfaceShmem = MakeRefPtr(); + auto dataSurfaceShmem = MakeRefPtr(); if (!dataSurfaceShmem->Create(sizeRequired) || !dataSurfaceShmem->Map(sizeRequired)) { return false; @@ -529,7 +528,7 @@ already_AddRefed CanvasChild::GetDataSurface( auto it = mTextureInfo.find(aTextureId); if (it != mTextureInfo.end() && it->second.mSnapshotShmem) { const auto shmemPtr = - reinterpret_cast(it->second.mSnapshotShmem->memory()); + reinterpret_cast(it->second.mSnapshotShmem->Memory()); MOZ_ASSERT(shmemPtr); mRecorder->RecordEvent(RecordedPrepareShmem(aTextureId)); auto checkpoint = CreateCheckpoint(); @@ -571,7 +570,7 @@ already_AddRefed CanvasChild::GetDataSurface( mDataSurfaceShmemAvailable = false; - auto* data = static_cast(mDataSurfaceShmem->memory()); + auto* data = static_cast(mDataSurfaceShmem->Memory()); RefPtr dataSurface = gfx::Factory::CreateWrappingDataSourceSurface( @@ -598,8 +597,8 @@ already_AddRefed CanvasChild::WrapSurface( } void CanvasChild::ReturnDataSurfaceShmem( - already_AddRefed aDataSurfaceShmem) { - RefPtr data = aDataSurfaceShmem; + already_AddRefed aDataSurfaceShmem) { + RefPtr data = aDataSurfaceShmem; // We can only reuse the latest data surface shmem. if (data == mDataSurfaceShmem) { MOZ_ASSERT(!mDataSurfaceShmemAvailable); @@ -649,7 +648,7 @@ ipc::IPCResult CanvasChild::RecvSnapshotShmem( SnapshotShmemResolver&& aResolve) { auto it = mTextureInfo.find(aTextureId); if (it != mTextureInfo.end()) { - auto shmem = MakeRefPtr(); + auto shmem = MakeRefPtr(); if (NS_WARN_IF(!shmem->SetHandle(std::move(aShmemHandle), ipc::SharedMemory::RightsReadOnly)) || NS_WARN_IF(!shmem->Map(aShmemSize))) { diff --git a/gfx/layers/ipc/CanvasChild.h b/gfx/layers/ipc/CanvasChild.h index d51f714b2ec2..d9197fe51706 100644 --- a/gfx/layers/ipc/CanvasChild.h +++ b/gfx/layers/ipc/CanvasChild.h @@ -156,7 +156,7 @@ class CanvasChild final : public PCanvasChild, public SupportsWeakPtr { void CleanupTexture(int64_t aTextureId); void ReturnDataSurfaceShmem( - already_AddRefed aDataSurfaceShmem); + already_AddRefed aDataSurfaceShmem); protected: void ActorDestroy(ActorDestroyReason aWhy) final; @@ -179,12 +179,12 @@ class CanvasChild final : public PCanvasChild, public SupportsWeakPtr { RefPtr mWorkerRef; RefPtr mRecorder; - RefPtr mDataSurfaceShmem; + RefPtr mDataSurfaceShmem; bool mDataSurfaceShmemAvailable = false; int64_t mLastWriteLockCheckpoint = 0; uint32_t mTransactionsSinceGetDataSurface = kCacheDataSurfaceThreshold; struct TextureInfo { - RefPtr mSnapshotShmem; + RefPtr mSnapshotShmem; bool mRequiresRefresh = false; }; std::unordered_map mTextureInfo; diff --git a/gfx/layers/ipc/CanvasTranslator.cpp b/gfx/layers/ipc/CanvasTranslator.cpp index d0a43388c762..dc8fefcb87da 100644 --- a/gfx/layers/ipc/CanvasTranslator.cpp +++ b/gfx/layers/ipc/CanvasTranslator.cpp @@ -101,11 +101,11 @@ bool CanvasTranslator::IsInTaskQueue() const { return gfx::CanvasRenderThread::IsInCanvasRenderThread(); } -static bool CreateAndMapShmem(RefPtr& aShmem, +static bool CreateAndMapShmem(RefPtr& aShmem, Handle&& aHandle, ipc::SharedMemory::OpenRights aOpenRights, size_t aSize) { - auto shmem = MakeRefPtr(); + auto shmem = MakeRefPtr(); if (!shmem->SetHandle(std::move(aHandle), aOpenRights) || !shmem->Map(aSize)) { return false; @@ -166,14 +166,14 @@ mozilla::ipc::IPCResult CanvasTranslator::RecvInitTranslator( mBackendType = aBackendType; mOtherPid = OtherPid(); - mHeaderShmem = MakeAndAddRef(); + mHeaderShmem = MakeAndAddRef(); if (!CreateAndMapShmem(mHeaderShmem, std::move(aReadHandle), ipc::SharedMemory::RightsReadWrite, sizeof(Header))) { Deactivate(); return IPC_FAIL(this, "Failed to map canvas header shared memory."); } - mHeader = static_cast(mHeaderShmem->memory()); + mHeader = static_cast(mHeaderShmem->Memory()); mWriterSemaphore.reset(CrossProcessSemaphore::Create(std::move(aWriterSem))); mWriterSemaphore->CloseHandle(); @@ -246,7 +246,7 @@ ipc::IPCResult CanvasTranslator::RecvRestartTranslation() { } ipc::IPCResult CanvasTranslator::RecvAddBuffer( - ipc::SharedMemoryBasic::Handle&& aBufferHandle, uint64_t aBufferSize) { + ipc::SharedMemory::Handle&& aBufferHandle, uint64_t aBufferSize) { if (mDeactivated) { // The other side might have sent a resume message before we deactivated. return IPC_OK(); @@ -258,16 +258,15 @@ ipc::IPCResult CanvasTranslator::RecvAddBuffer( std::move(aBufferHandle), aBufferSize)); PostCanvasTranslatorEvents(lock); } else { - DispatchToTaskQueue( - NewRunnableMethod( - "CanvasTranslator::AddBuffer", this, &CanvasTranslator::AddBuffer, - std::move(aBufferHandle), aBufferSize)); + DispatchToTaskQueue(NewRunnableMethod( + "CanvasTranslator::AddBuffer", this, &CanvasTranslator::AddBuffer, + std::move(aBufferHandle), aBufferSize)); } return IPC_OK(); } -bool CanvasTranslator::AddBuffer(ipc::SharedMemoryBasic::Handle&& aBufferHandle, +bool CanvasTranslator::AddBuffer(ipc::SharedMemory::Handle&& aBufferHandle, size_t aBufferSize) { MOZ_ASSERT(IsInTaskQueue()); if (mHeader->readerState == State::Failed) { @@ -309,7 +308,7 @@ bool CanvasTranslator::AddBuffer(ipc::SharedMemoryBasic::Handle&& aBufferHandle, } ipc::IPCResult CanvasTranslator::RecvSetDataSurfaceBuffer( - ipc::SharedMemoryBasic::Handle&& aBufferHandle, uint64_t aBufferSize) { + ipc::SharedMemory::Handle&& aBufferHandle, uint64_t aBufferSize) { if (mDeactivated) { // The other side might have sent a resume message before we deactivated. return IPC_OK(); @@ -322,18 +321,17 @@ ipc::IPCResult CanvasTranslator::RecvSetDataSurfaceBuffer( aBufferSize)); PostCanvasTranslatorEvents(lock); } else { - DispatchToTaskQueue( - NewRunnableMethod( - "CanvasTranslator::SetDataSurfaceBuffer", this, - &CanvasTranslator::SetDataSurfaceBuffer, std::move(aBufferHandle), - aBufferSize)); + DispatchToTaskQueue(NewRunnableMethod( + "CanvasTranslator::SetDataSurfaceBuffer", this, + &CanvasTranslator::SetDataSurfaceBuffer, std::move(aBufferHandle), + aBufferSize)); } return IPC_OK(); } bool CanvasTranslator::SetDataSurfaceBuffer( - ipc::SharedMemoryBasic::Handle&& aBufferHandle, size_t aBufferSize) { + ipc::SharedMemory::Handle&& aBufferHandle, size_t aBufferSize) { MOZ_ASSERT(IsInTaskQueue()); if (mHeader->readerState == State::Failed) { // We failed before we got to the pause event. @@ -390,7 +388,7 @@ void CanvasTranslator::GetDataSurface(uint64_t aSurfaceRef) { return; } - uint8_t* dst = static_cast(mDataSurfaceShmem->memory()); + uint8_t* dst = static_cast(mDataSurfaceShmem->Memory()); const uint8_t* src = map->GetData(); const uint8_t* endSrc = src + (srcSize.height * srcStride); while (src < endSrc) { diff --git a/gfx/layers/ipc/CanvasTranslator.h b/gfx/layers/ipc/CanvasTranslator.h index dbaf5998e857..3908441b65c0 100644 --- a/gfx/layers/ipc/CanvasTranslator.h +++ b/gfx/layers/ipc/CanvasTranslator.h @@ -298,7 +298,7 @@ class CanvasTranslator final : public gfx::InlineTranslator, const Tag mTag; private: - ipc::SharedMemoryBasic::Handle mBufferHandle; + ipc::SharedMemory::Handle mBufferHandle; const size_t mBufferSize; public: @@ -308,7 +308,7 @@ class CanvasTranslator final : public gfx::InlineTranslator, mTag == Tag::ClearCachedResources); } CanvasTranslatorEvent(const Tag aTag, - ipc::SharedMemoryBasic::Handle&& aBufferHandle, + ipc::SharedMemory::Handle&& aBufferHandle, size_t aBufferSize) : mTag(aTag), mBufferHandle(std::move(aBufferHandle)), @@ -321,13 +321,13 @@ class CanvasTranslator final : public gfx::InlineTranslator, } static UniquePtr AddBuffer( - ipc::SharedMemoryBasic::Handle&& aBufferHandle, size_t aBufferSize) { + ipc::SharedMemory::Handle&& aBufferHandle, size_t aBufferSize) { return MakeUnique( Tag::AddBuffer, std::move(aBufferHandle), aBufferSize); } static UniquePtr SetDataSurfaceBuffer( - ipc::SharedMemoryBasic::Handle&& aBufferHandle, size_t aBufferSize) { + ipc::SharedMemory::Handle&& aBufferHandle, size_t aBufferSize) { return MakeUnique( Tag::SetDataSurfaceBuffer, std::move(aBufferHandle), aBufferSize); } @@ -336,12 +336,12 @@ class CanvasTranslator final : public gfx::InlineTranslator, return MakeUnique(Tag::ClearCachedResources); } - ipc::SharedMemoryBasic::Handle TakeBufferHandle() { + ipc::SharedMemory::Handle TakeBufferHandle() { if (mTag == Tag::AddBuffer || mTag == Tag::SetDataSurfaceBuffer) { return std::move(mBufferHandle); } MOZ_ASSERT_UNREACHABLE("unexpected to be called"); - return mozilla::ipc::SharedMemoryBasic::NULLHandle(); + return mozilla::ipc::SharedMemory::NULLHandle(); } size_t BufferSize() { @@ -437,20 +437,20 @@ class CanvasTranslator final : public gfx::InlineTranslator, using State = CanvasDrawEventRecorder::State; using Header = CanvasDrawEventRecorder::Header; - RefPtr mHeaderShmem; + RefPtr mHeaderShmem; Header* mHeader = nullptr; struct CanvasShmem { - RefPtr shmem; + RefPtr shmem; auto Size() { return shmem->Size(); } gfx::MemReader CreateMemReader() { - return {static_cast(shmem->memory()), Size()}; + return {static_cast(shmem->Memory()), Size()}; } }; std::queue mCanvasShmems; CanvasShmem mCurrentShmem; gfx::MemReader mCurrentMemReader{0, 0}; - RefPtr mDataSurfaceShmem; + RefPtr mDataSurfaceShmem; UniquePtr mWriterSemaphore; UniquePtr mReaderSemaphore; TextureType mTextureType = TextureType::Unknown; diff --git a/gfx/layers/ipc/LayersSurfaces.ipdlh b/gfx/layers/ipc/LayersSurfaces.ipdlh index f7433ff7d1fe..6a1947f58b54 100644 --- a/gfx/layers/ipc/LayersSurfaces.ipdlh +++ b/gfx/layers/ipc/LayersSurfaces.ipdlh @@ -23,7 +23,7 @@ using mozilla::gfx::IntSize from "mozilla/gfx/Point.h"; using mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h"; using mozilla::gfx::FenceInfo from "mozilla/gfx/FileHandleWrapper.h"; [RefCounted] using mozilla::gfx::FileHandleWrapper from "mozilla/gfx/FileHandleWrapper.h"; -[MoveOnly] using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasic.h"; +[MoveOnly] using mozilla::ipc::SharedMemory::Handle from "mozilla/ipc/SharedMemory.h"; using gfxImageFormat from "gfxTypes.h"; using mozilla::layers::MaybeVideoBridgeSource from "mozilla/layers/VideoBridgeUtils.h"; using mozilla::layers::RemoteTextureId from "mozilla/layers/LayersTypes.h"; diff --git a/gfx/layers/ipc/PCanvas.ipdl b/gfx/layers/ipc/PCanvas.ipdl index 59896b72cfa0..962e6b6f96ce 100644 --- a/gfx/layers/ipc/PCanvas.ipdl +++ b/gfx/layers/ipc/PCanvas.ipdl @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- * vim: sw=2 ts=8 et : */ /* 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 @@ -10,7 +10,7 @@ include "mozilla/layers/CanvasTranslator.h"; [MoveOnly] using mozilla::CrossProcessSemaphoreHandle from "mozilla/ipc/CrossProcessSemaphore.h"; using mozilla::layers::TextureType from "mozilla/layers/LayersTypes.h"; -[MoveOnly] using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasic.h"; +[MoveOnly] using mozilla::ipc::SharedMemory::Handle from "mozilla/ipc/SharedMemory.h"; using mozilla::gfx::BackendType from "mozilla/gfx/Types.h"; namespace mozilla { diff --git a/gfx/layers/ipc/PCompositorManager.ipdl b/gfx/layers/ipc/PCompositorManager.ipdl index 02045511a7e2..b60b9994182b 100644 --- a/gfx/layers/ipc/PCompositorManager.ipdl +++ b/gfx/layers/ipc/PCompositorManager.ipdl @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- * vim: sw=2 ts=8 et : */ /* This Source Code Form is subject to the terms of the Mozilla Public @@ -14,7 +14,7 @@ include "mozilla/layers/WebRenderMessageUtils.h"; using mozilla::TimeDuration from "mozilla/TimeStamp.h"; using mozilla::CSSToLayoutDeviceScale from "Units.h"; using mozilla::gfx::IntSize from "mozilla/gfx/2D.h"; -[MoveOnly] using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasic.h"; +[MoveOnly] using mozilla::ipc::SharedMemory::Handle from "mozilla/ipc/SharedMemory.h"; using mozilla::layers::CompositorOptions from "mozilla/layers/LayersMessageUtils.h"; using mozilla::wr::ExternalImageId from "mozilla/webrender/WebRenderTypes.h"; using mozilla::wr::MemoryReport from "mozilla/webrender/WebRenderTypes.h"; diff --git a/gfx/layers/ipc/SharedSurfacesChild.cpp b/gfx/layers/ipc/SharedSurfacesChild.cpp index 0f8b2a974328..feb7ef2ecb67 100644 --- a/gfx/layers/ipc/SharedSurfacesChild.cpp +++ b/gfx/layers/ipc/SharedSurfacesChild.cpp @@ -220,7 +220,7 @@ nsresult SharedSurfacesChild::ShareInternal(SourceSurfaceSharedData* aSurface, // Attempt to share a handle with the GPU process. The handle may or may not // be available -- it will only be available if it is either not yet finalized // and/or if it has been finalized but never used for drawing in process. - ipc::SharedMemoryBasic::Handle handle = ipc::SharedMemoryBasic::NULLHandle(); + ipc::SharedMemory::Handle handle = ipc::SharedMemory::NULLHandle(); nsresult rv = aSurface->CloneHandle(handle); if (rv == NS_ERROR_NOT_AVAILABLE) { // It is at least as expensive to copy the image to the GPU process if we diff --git a/gfx/thebes/SharedFontList-impl.h b/gfx/thebes/SharedFontList-impl.h index d78fdcd87346..0603edac162b 100644 --- a/gfx/thebes/SharedFontList-impl.h +++ b/gfx/thebes/SharedFontList-impl.h @@ -18,8 +18,8 @@ // This is split out from SharedFontList.h because that header is included // quite widely (via gfxPlatformFontList.h, gfxTextRun.h, etc), and other code // such as the generated DOM bindings code gets upset at (indirect) inclusion -// of via SharedMemoryBasic.h. So this header, which defines the -// actual shared-memory FontList class, is included only by the .cpp files that +// of via SharedMemory.h. So this header, which defines the actual +// shared-memory FontList class, is included only by the .cpp files that // implement or directly interface with the font list, to avoid polluting other // headers. diff --git a/ipc/chromium/src/chrome/common/ipc_message_utils.cc b/ipc/chromium/src/chrome/common/ipc_message_utils.cc index 8981410bfa87..3cdb625e43f5 100644 --- a/ipc/chromium/src/chrome/common/ipc_message_utils.cc +++ b/ipc/chromium/src/chrome/common/ipc_message_utils.cc @@ -6,7 +6,6 @@ #include "chrome/common/ipc_message_utils.h" #include "mozilla/ipc/SharedMemory.h" -#include "mozilla/ipc/SharedMemoryBasic.h" namespace IPC { @@ -18,7 +17,7 @@ MessageBufferWriter::MessageBufferWriter(MessageWriter* writer, // NOTE: We only write out the `shmem_ok` bool if we're over kShmemThreshold // to avoid bloating the size of messages with small buffers. if (full_len > kShmemThreshold) { - shmem_ = new mozilla::ipc::SharedMemoryBasic(); + shmem_ = new mozilla::ipc::SharedMemory(); bool shmem_ok = shmem_->Create(full_len) && shmem_->Map(full_len); writer->WriteBool(shmem_ok); if (shmem_ok) { @@ -26,7 +25,7 @@ MessageBufferWriter::MessageBufferWriter(MessageWriter* writer, writer->FatalError("SharedMemory::WriteHandle failed"); return; } - buffer_ = reinterpret_cast(shmem_->memory()); + buffer_ = reinterpret_cast(shmem_->Memory()); } else { // Creating or mapping the shared memory region failed, perhaps due to FD // exhaustion or address space fragmentation. Fall back to trying to send @@ -75,7 +74,7 @@ MessageBufferReader::MessageBufferReader(MessageReader* reader, return; } if (shmem_ok) { - shmem_ = new mozilla::ipc::SharedMemoryBasic(); + shmem_ = new mozilla::ipc::SharedMemory(); if (!shmem_->ReadHandle(reader)) { reader->FatalError("SharedMemory::ReadHandle failed!"); return; @@ -84,7 +83,7 @@ MessageBufferReader::MessageBufferReader(MessageReader* reader, reader->FatalError("SharedMemory::Map failed"); return; } - buffer_ = reinterpret_cast(shmem_->memory()); + buffer_ = reinterpret_cast(shmem_->Memory()); } } remaining_ = full_len; diff --git a/ipc/glue/BigBuffer.cpp b/ipc/glue/BigBuffer.cpp index 822ffe20fe70..2045c84539b0 100644 --- a/ipc/glue/BigBuffer.cpp +++ b/ipc/glue/BigBuffer.cpp @@ -6,14 +6,14 @@ #include "mozilla/ipc/BigBuffer.h" -#include "mozilla/ipc/SharedMemoryBasic.h" +#include "mozilla/ipc/SharedMemory.h" #include "nsDebug.h" namespace mozilla::ipc { BigBuffer::BigBuffer(Adopt, SharedMemory* aSharedMemory, size_t aSize) : mSize(aSize), mData(AsVariant(RefPtr{aSharedMemory})) { - MOZ_RELEASE_ASSERT(aSharedMemory && aSharedMemory->memory(), + MOZ_RELEASE_ASSERT(aSharedMemory && aSharedMemory->Memory(), "shared memory must be non-null and mapped"); MOZ_RELEASE_ASSERT(mSize <= aSharedMemory->Size(), "shared memory region isn't large enough"); @@ -24,12 +24,12 @@ BigBuffer::BigBuffer(Adopt, uint8_t* aData, size_t aSize) uint8_t* BigBuffer::Data() { return mData.is<0>() ? mData.as<0>().get() - : reinterpret_cast(mData.as<1>()->memory()); + : reinterpret_cast(mData.as<1>()->Memory()); } const uint8_t* BigBuffer::Data() const { return mData.is<0>() ? mData.as<0>().get() - : reinterpret_cast(mData.as<1>()->memory()); + : reinterpret_cast(mData.as<1>()->Memory()); } auto BigBuffer::TryAllocBuffer(size_t aSize) -> Maybe { @@ -40,7 +40,7 @@ auto BigBuffer::TryAllocBuffer(size_t aSize) -> Maybe { return Some(AsVariant(std::move(mem))); } - RefPtr shmem = new SharedMemoryBasic(); + RefPtr shmem = new SharedMemory(); size_t capacity = SharedMemory::PageAlignedSize(aSize); if (!shmem->Create(capacity) || !shmem->Map(capacity)) { return {}; @@ -80,7 +80,7 @@ bool IPC::ParamTraits::Read(MessageReader* aReader, } if (isShmem) { - RefPtr shmem = new SharedMemoryBasic(); + RefPtr shmem = new SharedMemory(); size_t capacity = SharedMemory::PageAlignedSize(size); if (!shmem->ReadHandle(aReader) || !shmem->Map(capacity)) { aReader->FatalError("Failed to read data shmem"); diff --git a/ipc/glue/CrossProcessMutex.h b/ipc/glue/CrossProcessMutex.h index 3e16166c4bf6..c49ae22d60a6 100644 --- a/ipc/glue/CrossProcessMutex.h +++ b/ipc/glue/CrossProcessMutex.h @@ -15,7 +15,7 @@ #endif #if !defined(XP_WIN) && !defined(XP_NETBSD) && !defined(XP_OPENBSD) # include -# include "mozilla/ipc/SharedMemoryBasic.h" +# include "mozilla/ipc/SharedMemory.h" # include "mozilla/Atomics.h" #endif @@ -39,7 +39,7 @@ namespace mozilla { #if defined(XP_WIN) typedef mozilla::UniqueFileHandle CrossProcessMutexHandle; #elif !defined(XP_NETBSD) && !defined(XP_OPENBSD) -typedef mozilla::ipc::SharedMemoryBasic::Handle CrossProcessMutexHandle; +typedef mozilla::ipc::SharedMemory::Handle CrossProcessMutexHandle; #else // Stub for other platforms. We can't use uintptr_t here since different // processes could disagree on its size. @@ -104,7 +104,7 @@ class CrossProcessMutex { #if defined(XP_WIN) HANDLE mMutex; #elif !defined(XP_NETBSD) && !defined(XP_OPENBSD) - RefPtr mSharedBuffer; + RefPtr mSharedBuffer; pthread_mutex_t* mMutex; mozilla::Atomic* mCount; #endif diff --git a/ipc/glue/CrossProcessMutex_posix.cpp b/ipc/glue/CrossProcessMutex_posix.cpp index c37fcb797dbb..b94c317a18ba 100644 --- a/ipc/glue/CrossProcessMutex_posix.cpp +++ b/ipc/glue/CrossProcessMutex_posix.cpp @@ -43,7 +43,7 @@ CrossProcessMutex::CrossProcessMutex(const char*) // they specifically are not on Linux. MOZ_RELEASE_ASSERT(false); #endif - mSharedBuffer = new ipc::SharedMemoryBasic; + mSharedBuffer = new ipc::SharedMemory; if (!mSharedBuffer->Create(sizeof(MutexData))) { MOZ_CRASH(); } @@ -52,7 +52,7 @@ CrossProcessMutex::CrossProcessMutex(const char*) MOZ_CRASH(); } - MutexData* data = static_cast(mSharedBuffer->memory()); + MutexData* data = static_cast(mSharedBuffer->Memory()); if (!data) { MOZ_CRASH(); @@ -69,7 +69,7 @@ CrossProcessMutex::CrossProcessMutex(const char*) CrossProcessMutex::CrossProcessMutex(CrossProcessMutexHandle aHandle) : mMutex(nullptr), mCount(nullptr) { - mSharedBuffer = new ipc::SharedMemoryBasic; + mSharedBuffer = new ipc::SharedMemory; if (!mSharedBuffer->IsHandleValid(aHandle)) { MOZ_CRASH(); @@ -84,7 +84,7 @@ CrossProcessMutex::CrossProcessMutex(CrossProcessMutexHandle aHandle) MOZ_CRASH(); } - MutexData* data = static_cast(mSharedBuffer->memory()); + MutexData* data = static_cast(mSharedBuffer->Memory()); if (!data) { MOZ_CRASH(); @@ -125,7 +125,7 @@ void CrossProcessMutex::Unlock() { } CrossProcessMutexHandle CrossProcessMutex::CloneHandle() { - CrossProcessMutexHandle result = ipc::SharedMemoryBasic::NULLHandle(); + CrossProcessMutexHandle result = ipc::SharedMemory::NULLHandle(); if (mSharedBuffer) { result = mSharedBuffer->CloneHandle(); diff --git a/ipc/glue/CrossProcessSemaphore.h b/ipc/glue/CrossProcessSemaphore.h index 466f88f8c39c..ca45b3226abb 100644 --- a/ipc/glue/CrossProcessSemaphore.h +++ b/ipc/glue/CrossProcessSemaphore.h @@ -16,7 +16,7 @@ #else # include # include -# include "mozilla/ipc/SharedMemoryBasic.h" +# include "mozilla/ipc/SharedMemory.h" # include "mozilla/Atomics.h" #endif @@ -41,12 +41,12 @@ typedef mozilla::UniqueFileHandle CrossProcessSemaphoreHandle; #elif defined(XP_DARWIN) typedef mozilla::UniqueMachSendRight CrossProcessSemaphoreHandle; #else -typedef mozilla::ipc::SharedMemoryBasic::Handle CrossProcessSemaphoreHandle; +typedef mozilla::ipc::SharedMemory::Handle CrossProcessSemaphoreHandle; template <> inline bool IsHandleValid( const CrossProcessSemaphoreHandle& handle) { - return !(handle == mozilla::ipc::SharedMemoryBasic::NULLHandle()); + return !(handle == mozilla::ipc::SharedMemory::NULLHandle()); } #endif @@ -108,7 +108,7 @@ class CrossProcessSemaphore { CrossProcessSemaphoreHandle mSemaphore; #else - RefPtr mSharedBuffer; + RefPtr mSharedBuffer; sem_t* mSemaphore; mozilla::Atomic* mRefCount; #endif diff --git a/ipc/glue/CrossProcessSemaphore_posix.cpp b/ipc/glue/CrossProcessSemaphore_posix.cpp index 3b32a897ee7d..e03768d4d2db 100644 --- a/ipc/glue/CrossProcessSemaphore_posix.cpp +++ b/ipc/glue/CrossProcessSemaphore_posix.cpp @@ -28,7 +28,7 @@ namespace mozilla { /* static */ CrossProcessSemaphore* CrossProcessSemaphore::Create(const char*, uint32_t aInitialValue) { - RefPtr sharedBuffer = new ipc::SharedMemoryBasic; + RefPtr sharedBuffer = new ipc::SharedMemory; if (!sharedBuffer->Create(sizeof(SemaphoreData))) { return nullptr; } @@ -37,7 +37,7 @@ CrossProcessSemaphore* CrossProcessSemaphore::Create(const char*, return nullptr; } - SemaphoreData* data = static_cast(sharedBuffer->memory()); + SemaphoreData* data = static_cast(sharedBuffer->Memory()); if (!data) { return nullptr; @@ -61,7 +61,7 @@ CrossProcessSemaphore* CrossProcessSemaphore::Create(const char*, /* static */ CrossProcessSemaphore* CrossProcessSemaphore::Create( CrossProcessSemaphoreHandle aHandle) { - RefPtr sharedBuffer = new ipc::SharedMemoryBasic; + RefPtr sharedBuffer = new ipc::SharedMemory; if (!sharedBuffer->IsHandleValid(aHandle)) { return nullptr; @@ -78,7 +78,7 @@ CrossProcessSemaphore* CrossProcessSemaphore::Create( sharedBuffer->CloseHandle(); - SemaphoreData* data = static_cast(sharedBuffer->memory()); + SemaphoreData* data = static_cast(sharedBuffer->Memory()); if (!data) { return nullptr; @@ -147,7 +147,7 @@ void CrossProcessSemaphore::Signal() { } CrossProcessSemaphoreHandle CrossProcessSemaphore::CloneHandle() { - CrossProcessSemaphoreHandle result = ipc::SharedMemoryBasic::NULLHandle(); + CrossProcessSemaphoreHandle result = ipc::SharedMemory::NULLHandle(); if (mSharedBuffer) { result = mSharedBuffer->CloneHandle(); diff --git a/ipc/glue/DataPipe.cpp b/ipc/glue/DataPipe.cpp index bc1af11515fd..c12d17d0c2ae 100644 --- a/ipc/glue/DataPipe.cpp +++ b/ipc/glue/DataPipe.cpp @@ -71,7 +71,7 @@ static void DoNotifyOnUnlock(DataPipeAutoLock& aLock, class DataPipeLink : public NodeController::PortObserver { public: DataPipeLink(bool aReceiverSide, std::shared_ptr aMutex, - ScopedPort aPort, SharedMemoryBasic::Handle aShmemHandle, + ScopedPort aPort, SharedMemory::Handle aShmemHandle, SharedMemory* aShmem, uint32_t aCapacity, nsresult aPeerStatus, uint32_t aOffset, uint32_t aAvailable) : mMutex(std::move(aMutex)), @@ -165,7 +165,7 @@ class DataPipeLink : public NodeController::PortObserver { std::shared_ptr mMutex; ScopedPort mPort MOZ_GUARDED_BY(*mMutex); - SharedMemoryBasic::Handle mShmemHandle MOZ_GUARDED_BY(*mMutex); + SharedMemory::Handle mShmemHandle MOZ_GUARDED_BY(*mMutex); const RefPtr mShmem; const uint32_t mCapacity; const bool mReceiverSide; @@ -245,7 +245,7 @@ DataPipeBase::DataPipeBase(bool aReceiverSide, nsresult aError) mStatus(NS_SUCCEEDED(aError) ? NS_BASE_STREAM_CLOSED : aError) {} DataPipeBase::DataPipeBase(bool aReceiverSide, ScopedPort aPort, - SharedMemoryBasic::Handle aShmemHandle, + SharedMemory::Handle aShmemHandle, SharedMemory* aShmem, uint32_t aCapacity, nsresult aPeerStatus, uint32_t aOffset, uint32_t aAvailable) @@ -318,7 +318,7 @@ nsresult DataPipeBase::ProcessSegmentsInternal( // Extract an iterator over the next contiguous region of the shared memory // buffer which will be used . - char* start = static_cast(link->mShmem->memory()) + link->mOffset; + char* start = static_cast(link->mShmem->Memory()) + link->mOffset; char* iter = start; char* end = start + std::min({aCount - *aProcessedCount, link->mAvailable, link->mCapacity - link->mOffset}); @@ -480,16 +480,16 @@ bool DataPipeRead(IPC::MessageReader* aReader, RefPtr* aResult) { aReader->FatalError("failed to read DataPipe port"); return false; } - SharedMemoryBasic::Handle shmemHandle; + SharedMemory::Handle shmemHandle; if (!ReadParam(aReader, &shmemHandle)) { aReader->FatalError("failed to read DataPipe shmem"); return false; } - // Due to the awkward shared memory API provided by SharedMemoryBasic, we need - // to transfer ownership into the `shmem` here, then steal it back later in - // the function. Bug 1797039 tracks potential changes to the RawShmem API - // which could improve this situation. - RefPtr shmem = new SharedMemoryBasic(); + // Due to the awkward shared memory API provided by SharedMemory, we need to + // transfer ownership into the `shmem` here, then steal it back later in the + // function. Bug 1797039 tracks potential changes to the RawShmem API which + // could improve this situation. + RefPtr shmem = new SharedMemory(); if (!shmem->SetHandle(std::move(shmemHandle), SharedMemory::RightsReadWrite)) { aReader->FatalError("failed to create DataPipe shmem from handle"); @@ -717,7 +717,7 @@ nsresult NewDataPipe(uint32_t aCapacity, DataPipeSender** aSender, auto [senderPort, receiverPort] = controller->CreatePortPair(); // Create and allocate the shared memory region. - auto shmem = MakeRefPtr(); + auto shmem = MakeRefPtr(); size_t alignedCapacity = SharedMemory::PageAlignedSize(aCapacity); if (!shmem->Create(alignedCapacity) || !shmem->Map(alignedCapacity)) { return NS_ERROR_OUT_OF_MEMORY; @@ -726,8 +726,8 @@ nsresult NewDataPipe(uint32_t aCapacity, DataPipeSender** aSender, // We'll first clone then take the handle from the region so that the sender & // receiver each have a handle. This avoids the need to duplicate the handle // when serializing, when errors are non-recoverable. - SharedMemoryBasic::Handle senderShmemHandle = shmem->CloneHandle(); - SharedMemoryBasic::Handle receiverShmemHandle = shmem->TakeHandle(); + SharedMemory::Handle senderShmemHandle = shmem->CloneHandle(); + SharedMemory::Handle receiverShmemHandle = shmem->TakeHandle(); if (!senderShmemHandle || !receiverShmemHandle) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/ipc/glue/DataPipe.h b/ipc/glue/DataPipe.h index f339b1c72d22..18760d10932d 100644 --- a/ipc/glue/DataPipe.h +++ b/ipc/glue/DataPipe.h @@ -7,7 +7,7 @@ #ifndef mozilla_ipc_DataPipe_h #define mozilla_ipc_DataPipe_h -#include "mozilla/ipc/SharedMemoryBasic.h" +#include "mozilla/ipc/SharedMemory.h" #include "mozilla/ipc/NodeController.h" #include "nsIAsyncInputStream.h" #include "nsIAsyncOutputStream.h" @@ -30,7 +30,7 @@ class DataPipeBase { protected: explicit DataPipeBase(bool aReceiverSide, nsresult aError); DataPipeBase(bool aReceiverSide, ScopedPort aPort, - SharedMemoryBasic::Handle aShmemHandle, SharedMemory* aShmem, + SharedMemory::Handle aShmemHandle, SharedMemory* aShmem, uint32_t aCapacity, nsresult aPeerStatus, uint32_t aOffset, uint32_t aAvailable); @@ -103,7 +103,7 @@ class DataPipeSender final : public nsIAsyncOutputStream, explicit DataPipeSender(nsresult aError) : data_pipe_detail::DataPipeBase(/* aReceiverSide */ false, aError) {} - DataPipeSender(ScopedPort aPort, SharedMemoryBasic::Handle aShmemHandle, + DataPipeSender(ScopedPort aPort, SharedMemory::Handle aShmemHandle, SharedMemory* aShmem, uint32_t aCapacity, nsresult aPeerStatus, uint32_t aOffset, uint32_t aAvailable) : data_pipe_detail::DataPipeBase( @@ -143,7 +143,7 @@ class DataPipeReceiver final : public nsIAsyncInputStream, explicit DataPipeReceiver(nsresult aError) : data_pipe_detail::DataPipeBase(/* aReceiverSide */ true, aError) {} - DataPipeReceiver(ScopedPort aPort, SharedMemoryBasic::Handle aShmemHandle, + DataPipeReceiver(ScopedPort aPort, SharedMemory::Handle aShmemHandle, SharedMemory* aShmem, uint32_t aCapacity, nsresult aPeerStatus, uint32_t aOffset, uint32_t aAvailable) : data_pipe_detail::DataPipeBase( diff --git a/ipc/glue/GeckoChildProcessHost.cpp b/ipc/glue/GeckoChildProcessHost.cpp index 920045f8bfa2..2261104b1b9d 100644 --- a/ipc/glue/GeckoChildProcessHost.cpp +++ b/ipc/glue/GeckoChildProcessHost.cpp @@ -15,7 +15,7 @@ #include "chrome/common/process_watcher.h" #ifdef XP_DARWIN # include -# include "SharedMemoryBasic.h" +# include "SharedMemory.h" # include "base/rand_util.h" # include "chrome/common/mach_ipc_mac.h" # include "mozilla/StaticPrefs_media.h" diff --git a/ipc/glue/RawShmem.cpp b/ipc/glue/RawShmem.cpp index f700804301b3..e4f7135ef706 100644 --- a/ipc/glue/RawShmem.cpp +++ b/ipc/glue/RawShmem.cpp @@ -9,12 +9,12 @@ namespace mozilla::ipc { UnsafeSharedMemoryHandle::UnsafeSharedMemoryHandle() - : mHandle(ipc::SharedMemoryBasic::NULLHandle()), mSize(0) {} + : mHandle(ipc::SharedMemory::NULLHandle()), mSize(0) {} UnsafeSharedMemoryHandle::UnsafeSharedMemoryHandle( UnsafeSharedMemoryHandle&& aOther) noexcept : mHandle(std::move(aOther.mHandle)), mSize(aOther.mSize) { - aOther.mHandle = ipc::SharedMemoryBasic::NULLHandle(); + aOther.mHandle = ipc::SharedMemory::NULLHandle(); aOther.mSize = 0; } @@ -26,7 +26,7 @@ UnsafeSharedMemoryHandle& UnsafeSharedMemoryHandle::operator=( mHandle = std::move(aOther.mHandle); mSize = aOther.mSize; - aOther.mHandle = ipc::SharedMemoryBasic::NULLHandle(); + aOther.mHandle = ipc::SharedMemory::NULLHandle(); aOther.mSize = 0; return *this; } @@ -38,7 +38,7 @@ UnsafeSharedMemoryHandle::CreateAndMap(size_t aSize) { WritableSharedMemoryMapping())); } - RefPtr shm = MakeAndAddRef(); + RefPtr shm = MakeAndAddRef(); if (NS_WARN_IF(!shm->Create(aSize)) || NS_WARN_IF(!shm->Map(aSize))) { return Nothing(); } @@ -52,7 +52,7 @@ UnsafeSharedMemoryHandle::CreateAndMap(size_t aSize) { } WritableSharedMemoryMapping::WritableSharedMemoryMapping( - RefPtr&& aRef) + RefPtr&& aRef) : mRef(aRef) {} Maybe WritableSharedMemoryMapping::Open( @@ -61,7 +61,7 @@ Maybe WritableSharedMemoryMapping::Open( return Some(WritableSharedMemoryMapping(nullptr)); } - RefPtr shm = MakeAndAddRef(); + RefPtr shm = MakeAndAddRef(); if (NS_WARN_IF(!shm->SetHandle(std::move(aHandle.mHandle), ipc::SharedMemory::RightsReadWrite)) || NS_WARN_IF(!shm->Map(aHandle.mSize))) { @@ -86,7 +86,7 @@ Span WritableSharedMemoryMapping::Bytes() { return Span(); } - uint8_t* mem = static_cast(mRef->memory()); + uint8_t* mem = static_cast(mRef->Memory()); return Span(mem, mRef->Size()); } diff --git a/ipc/glue/RawShmem.h b/ipc/glue/RawShmem.h index cebc59e9247c..e23a109e554c 100644 --- a/ipc/glue/RawShmem.h +++ b/ipc/glue/RawShmem.h @@ -6,7 +6,7 @@ #ifndef MOZILLA_IPC_RAWSHMEM_H_ #define MOZILLA_IPC_RAWSHMEM_H_ -#include "mozilla/ipc/SharedMemoryBasic.h" +#include "mozilla/ipc/SharedMemory.h" #include "mozilla/Span.h" #include @@ -35,10 +35,10 @@ class UnsafeSharedMemoryHandle { CreateAndMap(size_t aSize); private: - UnsafeSharedMemoryHandle(SharedMemoryBasic::Handle&& aHandle, uint64_t aSize) + UnsafeSharedMemoryHandle(SharedMemory::Handle&& aHandle, uint64_t aSize) : mHandle(std::move(aHandle)), mSize(aSize) {} - SharedMemoryBasic::Handle mHandle; + SharedMemory::Handle mHandle; uint64_t mSize; }; @@ -93,9 +93,9 @@ class WritableSharedMemoryMapping { private: explicit WritableSharedMemoryMapping( - RefPtr&& aRef); + RefPtr&& aRef); - RefPtr mRef; + RefPtr mRef; }; } // namespace mozilla::ipc diff --git a/ipc/glue/SharedMemory.cpp b/ipc/glue/SharedMemory.cpp index 47617466580b..94a81aea0d38 100644 --- a/ipc/glue/SharedMemory.cpp +++ b/ipc/glue/SharedMemory.cpp @@ -4,15 +4,16 @@ * 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/. */ -#include - -#include "nsString.h" -#include "nsIMemoryReporter.h" #include "mozilla/ipc/SharedMemory.h" -#include "mozilla/Atomics.h" -namespace mozilla { -namespace ipc { +#include "mozilla/Atomics.h" +#include "nsIMemoryReporter.h" + +#ifdef FUZZING +# include "mozilla/ipc/SharedMemoryFuzzer.h" +#endif + +namespace mozilla::ipc { static Atomic gShmemAllocated; static Atomic gShmemMapped; @@ -49,36 +50,85 @@ SharedMemory::SharedMemory() : mAllocSize(0), mMappedSize(0) { } } -/*static*/ -size_t SharedMemory::PageAlignedSize(size_t aSize) { - size_t pageSize = SystemPageSize(); - size_t nPagesNeeded = size_t(ceil(double(aSize) / double(pageSize))); - return pageSize * nPagesNeeded; -} +SharedMemory::~SharedMemory() { + Unmap(); + CloseHandle(); -void SharedMemory::Created(size_t aNBytes) { - mAllocSize = aNBytes; - gShmemAllocated += mAllocSize; -} - -void SharedMemory::Mapped(size_t aNBytes) { - mMappedSize = aNBytes; - gShmemMapped += mMappedSize; -} - -void SharedMemory::Unmapped() { - MOZ_ASSERT(gShmemMapped >= mMappedSize, "Can't unmap more than mapped"); - gShmemMapped -= mMappedSize; - mMappedSize = 0; -} - -/*static*/ -void SharedMemory::Destroyed() { MOZ_ASSERT(gShmemAllocated >= mAllocSize, "Can't destroy more than allocated"); gShmemAllocated -= mAllocSize; mAllocSize = 0; } -} // namespace ipc -} // namespace mozilla +bool SharedMemory::WriteHandle(IPC::MessageWriter* aWriter) { + Handle handle = CloneHandle(); + if (!handle) { + return false; + } + IPC::WriteParam(aWriter, std::move(handle)); + return true; +} + +bool SharedMemory::ReadHandle(IPC::MessageReader* aReader) { + Handle handle; + return IPC::ReadParam(aReader, &handle) && IsHandleValid(handle) && + SetHandle(std::move(handle), RightsReadWrite); +} + +void SharedMemory::Protect(char* aAddr, size_t aSize, int aRights) { + char* memStart = reinterpret_cast(Memory()); + if (!memStart) MOZ_CRASH("SharedMemory region points at NULL!"); + char* memEnd = memStart + Size(); + + char* protStart = aAddr; + if (!protStart) MOZ_CRASH("trying to Protect() a NULL region!"); + char* protEnd = protStart + aSize; + + if (!(memStart <= protStart && protEnd <= memEnd)) { + MOZ_CRASH("attempt to Protect() a region outside this SharedMemory"); + } + + // checks alignment etc. + SystemProtect(aAddr, aSize, aRights); +} + +size_t SharedMemory::PageAlignedSize(size_t aSize) { + size_t pageSize = SystemPageSize(); + size_t nPagesNeeded = size_t(ceil(double(aSize) / double(pageSize))); + return pageSize * nPagesNeeded; +} + +bool SharedMemory::Create(size_t aNBytes) { + bool ok = CreateImpl(aNBytes); + if (ok) { + mAllocSize = aNBytes; + gShmemAllocated += mAllocSize; + } + return ok; +} + +bool SharedMemory::Map(size_t aNBytes, void* fixedAddress) { + bool ok = MapImpl(aNBytes, fixedAddress); + if (ok) { + mMappedSize = aNBytes; + gShmemMapped += mMappedSize; + } + return ok; +} + +void SharedMemory::Unmap() { + MOZ_ASSERT(gShmemMapped >= mMappedSize, "Can't unmap more than mapped"); + UnmapImpl(mMappedSize); + gShmemMapped -= mMappedSize; + mMappedSize = 0; +} + +void* SharedMemory::Memory() const { +#ifdef FUZZING + return SharedMemoryFuzzer::MutateSharedMemory(MemoryImpl(), mAllocSize); +#else + return MemoryImpl(); +#endif +} + +} // namespace mozilla::ipc diff --git a/ipc/glue/SharedMemory.h b/ipc/glue/SharedMemory.h index 818fad5e69ad..f6fc0d8bebed 100644 --- a/ipc/glue/SharedMemory.h +++ b/ipc/glue/SharedMemory.h @@ -7,97 +7,50 @@ #ifndef mozilla_ipc_SharedMemory_h #define mozilla_ipc_SharedMemory_h -#include "nsDebug.h" -#include "nsISupportsImpl.h" // NS_INLINE_DECL_REFCOUNTING -#include "mozilla/Attributes.h" +#include -#include "base/process.h" #include "chrome/common/ipc_message_utils.h" +#include "mozilla/Assertions.h" +#include "nsISupportsImpl.h" // NS_INLINE_DECL_REFCOUNTING -// -// This is a low-level wrapper around platform shared memory. Don't -// use it directly; use Shmem allocated through IPDL interfaces. -// -namespace { -enum Rights { RightsNone = 0, RightsRead = 1 << 0, RightsWrite = 1 << 1 }; -} // namespace +#ifdef XP_DARWIN +# include "mozilla/ipc/SharedMemoryImpl_mach.h" +#else +# include "mozilla/ipc/SharedMemoryImpl_chromium.h" +#endif -namespace mozilla { +namespace mozilla::ipc { -namespace ipc { -class SharedMemory; -} // namespace ipc - -namespace ipc { - -class SharedMemory { - protected: - virtual ~SharedMemory() { - Unmapped(); - Destroyed(); - } +class SharedMemory : public SharedMemoryImpl { + ~SharedMemory(); public: - enum OpenRights { - RightsReadOnly = RightsRead, - RightsReadWrite = RightsRead | RightsWrite, - }; - - size_t Size() const { return mMappedSize; } - - virtual void* memory() const = 0; - - virtual bool Create(size_t size) = 0; - virtual bool Map(size_t nBytes, void* fixed_address = nullptr) = 0; - virtual void Unmap() = 0; - - virtual void CloseHandle() = 0; - - virtual bool WriteHandle(IPC::MessageWriter* aWriter) = 0; - virtual bool ReadHandle(IPC::MessageReader* aReader) = 0; - - void Protect(char* aAddr, size_t aSize, int aRights) { - char* memStart = reinterpret_cast(memory()); - if (!memStart) MOZ_CRASH("SharedMemory region points at NULL!"); - char* memEnd = memStart + Size(); - - char* protStart = aAddr; - if (!protStart) MOZ_CRASH("trying to Protect() a NULL region!"); - char* protEnd = protStart + aSize; - - if (!(memStart <= protStart && protEnd <= memEnd)) - MOZ_CRASH("attempt to Protect() a region outside this SharedMemory"); - - // checks alignment etc. - SystemProtect(aAddr, aSize, aRights); - } + SharedMemory(); // bug 1168843, compositor thread may create shared memory instances that are // destroyed by main thread on shutdown, so this must use thread-safe RC to // avoid hitting assertion NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedMemory) + size_t Size() const { return mMappedSize; } + void CloseHandle() { TakeHandle(); } + + bool WriteHandle(IPC::MessageWriter* aWriter); + bool ReadHandle(IPC::MessageReader* aReader); + void Protect(char* aAddr, size_t aSize, int aRights); + static void SystemProtect(char* aAddr, size_t aSize, int aRights); [[nodiscard]] static bool SystemProtectFallible(char* aAddr, size_t aSize, int aRights); static size_t SystemPageSize(); static size_t PageAlignedSize(size_t aSize); - protected: - SharedMemory(); - - // Implementations should call these methods on shmem usage changes, - // but *only if* the OS-specific calls are known to have succeeded. - // The methods are expected to be called in the pattern - // - // Created (Mapped Unmapped)* Destroy - // - // but this isn't checked. - void Created(size_t aNBytes); - void Mapped(size_t aNBytes); - void Unmapped(); - void Destroyed(); + bool Create(size_t nBytes); + bool Map(size_t nBytes, void* fixedAddress = nullptr); + void Unmap(); + void* Memory() const; + private: // The size of the shmem region requested in Create(), if // successful. SharedMemory instances that are opened from a // foreign handle have an alloc size of 0, even though they have @@ -108,35 +61,6 @@ class SharedMemory { size_t mMappedSize; }; -template -class SharedMemoryCommon : public SharedMemory { - public: - typedef HandleImpl Handle; - - virtual Handle CloneHandle() = 0; - virtual Handle TakeHandle() = 0; - virtual bool IsHandleValid(const Handle& aHandle) const = 0; - virtual bool SetHandle(Handle aHandle, OpenRights aRights) = 0; - - virtual void CloseHandle() override { TakeHandle(); } - - virtual bool WriteHandle(IPC::MessageWriter* aWriter) override { - Handle handle = CloneHandle(); - if (!handle) { - return false; - } - IPC::WriteParam(aWriter, std::move(handle)); - return true; - } - - virtual bool ReadHandle(IPC::MessageReader* aReader) override { - Handle handle; - return IPC::ReadParam(aReader, &handle) && IsHandleValid(handle) && - SetHandle(std::move(handle), RightsReadWrite); - } -}; - -} // namespace ipc -} // namespace mozilla +} // namespace mozilla::ipc #endif // ifndef mozilla_ipc_SharedMemory_h diff --git a/ipc/glue/SharedMemoryBasic.h b/ipc/glue/SharedMemoryBasic.h deleted file mode 100644 index 2f07ae4402c9..000000000000 --- a/ipc/glue/SharedMemoryBasic.h +++ /dev/null @@ -1,16 +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_ipc_SharedMemoryBasic_h -#define mozilla_ipc_SharedMemoryBasic_h - -#ifdef XP_DARWIN -# include "mozilla/ipc/SharedMemoryBasic_mach.h" -#else -# include "mozilla/ipc/SharedMemoryBasic_chromium.h" -#endif - -#endif // ifndef mozilla_ipc_SharedMemoryBasic_h diff --git a/ipc/glue/SharedMemoryBasic_chromium.h b/ipc/glue/SharedMemoryBasic_chromium.h deleted file mode 100644 index 8d65e7f1895e..000000000000 --- a/ipc/glue/SharedMemoryBasic_chromium.h +++ /dev/null @@ -1,89 +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_ipc_SharedMemoryBasic_chromium_h -#define mozilla_ipc_SharedMemoryBasic_chromium_h - -#include "base/shared_memory.h" -#include "mozilla/ipc/SharedMemory.h" - -#ifdef FUZZING -# include "mozilla/ipc/SharedMemoryFuzzer.h" -#endif - -#include "nsDebug.h" - -// -// This is a low-level wrapper around platform shared memory. Don't -// use it directly; use Shmem allocated through IPDL interfaces. -// - -namespace mozilla { -namespace ipc { - -class SharedMemoryBasic final - : public SharedMemoryCommon { - public: - SharedMemoryBasic() = default; - - virtual bool SetHandle(Handle aHandle, OpenRights aRights) override { - return mSharedMemory.SetHandle(std::move(aHandle), - aRights == RightsReadOnly); - } - - virtual bool Create(size_t aNbytes) override { - bool ok = mSharedMemory.Create(aNbytes); - if (ok) { - Created(aNbytes); - } - return ok; - } - - virtual bool Map(size_t nBytes, void* fixed_address = nullptr) override { - bool ok = mSharedMemory.Map(nBytes, fixed_address); - if (ok) { - Mapped(nBytes); - } - return ok; - } - - virtual void Unmap() override { mSharedMemory.Unmap(); } - - virtual void* memory() const override { -#ifdef FUZZING - return SharedMemoryFuzzer::MutateSharedMemory(mSharedMemory.memory(), - mAllocSize); -#else - return mSharedMemory.memory(); -#endif - } - - static Handle NULLHandle() { return base::SharedMemory::NULLHandle(); } - - virtual bool IsHandleValid(const Handle& aHandle) const override { - return base::SharedMemory::IsHandleValid(aHandle); - } - - virtual Handle CloneHandle() override { return mSharedMemory.CloneHandle(); } - - virtual Handle TakeHandle() override { - return mSharedMemory.TakeHandle(false); - } - - static void* FindFreeAddressSpace(size_t size) { - return base::SharedMemory::FindFreeAddressSpace(size); - } - - private: - ~SharedMemoryBasic() = default; - - base::SharedMemory mSharedMemory; -}; - -} // namespace ipc -} // namespace mozilla - -#endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h diff --git a/ipc/glue/SharedMemoryBasic_mach.h b/ipc/glue/SharedMemoryBasic_mach.h deleted file mode 100644 index d7ea9b2c3952..000000000000 --- a/ipc/glue/SharedMemoryBasic_mach.h +++ /dev/null @@ -1,75 +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_ipc_SharedMemoryBasic_mach_h -#define mozilla_ipc_SharedMemoryBasic_mach_h - -#include "base/process.h" - -#include "mozilla/UniquePtrExtensions.h" -#include "mozilla/ipc/SharedMemory.h" -#include - -#ifdef FUZZING -# include "mozilla/ipc/SharedMemoryFuzzer.h" -#endif - -// -// This is a low-level wrapper around platform shared memory. Don't -// use it directly; use Shmem allocated through IPDL interfaces. -// - -class MachPortSender; -class ReceivePort; - -namespace mozilla { -namespace ipc { - -class SharedMemoryBasic final - : public SharedMemoryCommon { - public: - SharedMemoryBasic(); - - virtual bool SetHandle(Handle aHandle, OpenRights aRights) override; - - virtual bool Create(size_t aNbytes) override; - - virtual bool Map(size_t nBytes, void* fixed_address = nullptr) override; - - virtual void Unmap() override; - - virtual void* memory() const override { -#ifdef FUZZING - return SharedMemoryFuzzer::MutateSharedMemory(mMemory, mAllocSize); -#else - return mMemory; -#endif - } - - static Handle NULLHandle() { return Handle(); } - - static void* FindFreeAddressSpace(size_t aSize); - - virtual bool IsHandleValid(const Handle& aHandle) const override; - - virtual Handle CloneHandle() override; - - virtual Handle TakeHandle() override; - - private: - ~SharedMemoryBasic(); - - mozilla::UniqueMachSendRight mPort; - // Pointer to mapped region, null if unmapped. - void* mMemory; - // Access rights to map an existing region with. - OpenRights mOpenRights; -}; - -} // namespace ipc -} // namespace mozilla - -#endif // ifndef mozilla_ipc_SharedMemoryBasic_mach_h diff --git a/ipc/glue/SharedMemoryImpl_chromium.cpp b/ipc/glue/SharedMemoryImpl_chromium.cpp new file mode 100644 index 000000000000..77270d103f22 --- /dev/null +++ b/ipc/glue/SharedMemoryImpl_chromium.cpp @@ -0,0 +1,47 @@ +/* -*- 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/. */ + +#include "mozilla/ipc/SharedMemoryImpl_chromium.h" + +namespace mozilla::ipc { + +SharedMemoryImpl::Handle SharedMemoryImpl::CloneHandle() { + return mSharedMemory.CloneHandle(); +} + +SharedMemoryImpl::Handle SharedMemoryImpl::TakeHandle() { + return mSharedMemory.TakeHandle(false); +} + +bool SharedMemoryImpl::IsHandleValid(const Handle& aHandle) const { + return base::SharedMemory::IsHandleValid(aHandle); +} + +bool SharedMemoryImpl::SetHandle(Handle aHandle, OpenRights aRights) { + return mSharedMemory.SetHandle(std::move(aHandle), aRights == RightsReadOnly); +} + +SharedMemoryImpl::Handle SharedMemoryImpl::NULLHandle() { + return base::SharedMemory::NULLHandle(); +} + +void* SharedMemoryImpl::FindFreeAddressSpace(size_t size) { + return base::SharedMemory::FindFreeAddressSpace(size); +} + +bool SharedMemoryImpl::CreateImpl(size_t size) { + return mSharedMemory.Create(size); +} + +bool SharedMemoryImpl::MapImpl(size_t nBytes, void* fixedAddress) { + return mSharedMemory.Map(nBytes, fixedAddress); +} + +void SharedMemoryImpl::UnmapImpl(size_t mappedSize) { mSharedMemory.Unmap(); } + +void* SharedMemoryImpl::MemoryImpl() const { return mSharedMemory.memory(); } + +} // namespace mozilla::ipc diff --git a/ipc/glue/SharedMemoryImpl_chromium.h b/ipc/glue/SharedMemoryImpl_chromium.h new file mode 100644 index 000000000000..c5027c98042e --- /dev/null +++ b/ipc/glue/SharedMemoryImpl_chromium.h @@ -0,0 +1,51 @@ +/* -*- 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_ipc_SharedMemoryImpl_posix_h +#define mozilla_ipc_SharedMemoryImpl_posix_h + +#include "base/shared_memory.h" + +namespace { +enum Rights { RightsNone = 0, RightsRead = 1 << 0, RightsWrite = 1 << 1 }; +} // namespace + +namespace mozilla::ipc { + +class SharedMemoryImpl { + public: + using Handle = base::SharedMemoryHandle; + + enum OpenRights { + RightsReadOnly = RightsRead, + RightsReadWrite = RightsRead | RightsWrite, + }; + + Handle CloneHandle(); + Handle TakeHandle(); + + bool IsHandleValid(const Handle& aHandle) const; + bool SetHandle(Handle aHandle, OpenRights aRights); + + static Handle NULLHandle(); + static void* FindFreeAddressSpace(size_t size); + + protected: + SharedMemoryImpl() = default; + ~SharedMemoryImpl() {} + + bool CreateImpl(size_t size); + bool MapImpl(size_t nBytes, void* fixedAddress); + void UnmapImpl(size_t mappedSize); + void* MemoryImpl() const; + + private: + base::SharedMemory mSharedMemory; +}; + +} // namespace mozilla::ipc + +#endif diff --git a/ipc/glue/SharedMemoryBasic_mach.mm b/ipc/glue/SharedMemoryImpl_mach.cpp similarity index 74% rename from ipc/glue/SharedMemoryBasic_mach.mm rename to ipc/glue/SharedMemoryImpl_mach.cpp index d9992792e9bb..20f0de9b9b2f 100644 --- a/ipc/glue/SharedMemoryBasic_mach.mm +++ b/ipc/glue/SharedMemoryImpl_mach.cpp @@ -1,10 +1,11 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=8 et : - */ +/* -*- 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/. */ +#include "mozilla/ipc/SharedMemoryImpl_mach.h" + #include #include @@ -21,7 +22,6 @@ #endif #include #include -#include "SharedMemoryBasic.h" #include "mozilla/IntegerPrintfMacros.h" #include "mozilla/Printf.h" @@ -39,18 +39,12 @@ } while (0) #endif -namespace mozilla { -namespace ipc { +namespace mozilla::ipc { -SharedMemoryBasic::SharedMemoryBasic() +SharedMemoryImpl::SharedMemoryImpl() : mPort(MACH_PORT_NULL), mMemory(nullptr), mOpenRights(RightsReadWrite) {} -SharedMemoryBasic::~SharedMemoryBasic() { - Unmap(); - CloseHandle(); -} - -bool SharedMemoryBasic::SetHandle(Handle aHandle, OpenRights aRights) { +bool SharedMemoryImpl::SetHandle(Handle aHandle, OpenRights aRights) { MOZ_ASSERT(mPort == MACH_PORT_NULL, "already initialized"); mPort = std::move(aHandle); @@ -66,7 +60,7 @@ static inline mach_vm_address_t toVMAddress(void* pointer) { return static_cast(reinterpret_cast(pointer)); } -bool SharedMemoryBasic::Create(size_t size) { +bool SharedMemoryImpl::CreateImpl(size_t size) { MOZ_ASSERT(mPort == MACH_PORT_NULL, "already initialized"); memory_object_size_t memoryObjectSize = round_page(size); @@ -78,15 +72,13 @@ bool SharedMemoryBasic::Create(size_t size) { if (kr != KERN_SUCCESS || memoryObjectSize < round_page(size)) { LOG_ERROR("Failed to make memory entry (%zu bytes). %s (%x)\n", size, mach_error_string(kr), kr); - CloseHandle(); + TakeHandle(); return false; } - - Created(size); return true; } -bool SharedMemoryBasic::Map(size_t size, void* fixed_address) { +bool SharedMemoryImpl::MapImpl(size_t size, void* fixedAddress) { MOZ_ASSERT(mMemory == nullptr); if (MACH_PORT_NULL == mPort) { @@ -94,7 +86,7 @@ bool SharedMemoryBasic::Map(size_t size, void* fixed_address) { } kern_return_t kr; - mach_vm_address_t address = toVMAddress(fixed_address); + mach_vm_address_t address = toVMAddress(fixedAddress); vm_prot_t vmProtection = VM_PROT_READ; if (mOpenRights == RightsReadWrite) { @@ -102,11 +94,11 @@ bool SharedMemoryBasic::Map(size_t size, void* fixed_address) { } kr = mach_vm_map(mach_task_self(), &address, round_page(size), 0, - fixed_address ? VM_FLAGS_FIXED : VM_FLAGS_ANYWHERE, + fixedAddress ? VM_FLAGS_FIXED : VM_FLAGS_ANYWHERE, mPort.get(), 0, false, vmProtection, vmProtection, VM_INHERIT_NONE); if (kr != KERN_SUCCESS) { - if (!fixed_address) { + if (!fixedAddress) { LOG_ERROR( "Failed to map shared memory (%zu bytes) into %x, port %x. %s (%x)\n", size, mach_task_self(), mach_port_t(mPort.get()), @@ -115,23 +107,23 @@ bool SharedMemoryBasic::Map(size_t size, void* fixed_address) { return false; } - if (fixed_address && fixed_address != toPointer(address)) { + if (fixedAddress && fixedAddress != toPointer(address)) { kr = vm_deallocate(mach_task_self(), address, size); if (kr != KERN_SUCCESS) { - LOG_ERROR("Failed to unmap shared memory at unsuitable address " - "(%zu bytes) from %x, port %x. %s (%x)\n", - size, mach_task_self(), mach_port_t(mPort.get()), - mach_error_string(kr), kr); + LOG_ERROR( + "Failed to unmap shared memory at unsuitable address " + "(%zu bytes) from %x, port %x. %s (%x)\n", + size, mach_task_self(), mach_port_t(mPort.get()), + mach_error_string(kr), kr); } return false; } mMemory = toPointer(address); - Mapped(size); return true; } -void* SharedMemoryBasic::FindFreeAddressSpace(size_t size) { +void* SharedMemoryImpl::FindFreeAddressSpace(size_t size) { mach_vm_address_t address = 0; size = round_page(size); if (mach_vm_map(mach_task_self(), &address, size, 0, VM_FLAGS_ANYWHERE, @@ -143,22 +135,22 @@ void* SharedMemoryBasic::FindFreeAddressSpace(size_t size) { return toPointer(address); } -auto SharedMemoryBasic::CloneHandle() -> Handle { +auto SharedMemoryImpl::CloneHandle() -> Handle { return mozilla::RetainMachSendRight(mPort.get()); } -auto SharedMemoryBasic::TakeHandle() -> Handle { +auto SharedMemoryImpl::TakeHandle() -> Handle { mOpenRights = RightsReadWrite; return std::move(mPort); } -void SharedMemoryBasic::Unmap() { +void SharedMemoryImpl::UnmapImpl(size_t mappedSize) { if (!mMemory) { return; } vm_address_t address = toVMAddress(mMemory); kern_return_t kr = - vm_deallocate(mach_task_self(), address, round_page(mMappedSize)); + vm_deallocate(mach_task_self(), address, round_page(mappedSize)); if (kr != KERN_SUCCESS) { LOG_ERROR("Failed to deallocate shared memory. %s (%x)\n", mach_error_string(kr), kr); @@ -167,9 +159,12 @@ void SharedMemoryBasic::Unmap() { mMemory = nullptr; } -bool SharedMemoryBasic::IsHandleValid(const Handle& aHandle) const { +void* SharedMemoryImpl::MemoryImpl() const { return mMemory; } + +bool SharedMemoryImpl::IsHandleValid(const Handle& aHandle) const { return aHandle != nullptr; } -} // namespace ipc -} // namespace mozilla +auto SharedMemoryImpl::NULLHandle() -> Handle { return Handle(); } + +} // namespace mozilla::ipc diff --git a/ipc/glue/SharedMemoryImpl_mach.h b/ipc/glue/SharedMemoryImpl_mach.h new file mode 100644 index 000000000000..c45c39a3a298 --- /dev/null +++ b/ipc/glue/SharedMemoryImpl_mach.h @@ -0,0 +1,56 @@ +/* -*- 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_ipc_SharedMemoryImpl_mach_h +#define mozilla_ipc_SharedMemoryImpl_mach_h + +#include "mozilla/UniquePtrExtensions.h" +#include + +namespace { +enum Rights { RightsNone = 0, RightsRead = 1 << 0, RightsWrite = 1 << 1 }; +} // namespace + +namespace mozilla::ipc { + +class SharedMemoryImpl { + public: + using Handle = mozilla::UniqueMachSendRight; + + enum OpenRights { + RightsReadOnly = RightsRead, + RightsReadWrite = RightsRead | RightsWrite, + }; + + Handle CloneHandle(); + Handle TakeHandle(); + + bool IsHandleValid(const Handle& aHandle) const; + bool SetHandle(Handle aHandle, OpenRights aRights); + + static Handle NULLHandle(); + static void* FindFreeAddressSpace(size_t size); + + protected: + SharedMemoryImpl(); + ~SharedMemoryImpl() {} + + bool CreateImpl(size_t size); + bool MapImpl(size_t nBytes, void* fixedAddress); + void UnmapImpl(size_t mappedSize); + void* MemoryImpl() const; + + private: + mozilla::UniqueMachSendRight mPort; + // Pointer to mapped region, null if unmapped. + void* mMemory; + // Access rights to map an existing region with. + OpenRights mOpenRights; +}; + +} // namespace mozilla::ipc + +#endif diff --git a/ipc/glue/SharedMemory_posix.cpp b/ipc/glue/SharedMemory_posix.cpp index b634058945a7..798cdf312df0 100644 --- a/ipc/glue/SharedMemory_posix.cpp +++ b/ipc/glue/SharedMemory_posix.cpp @@ -13,8 +13,7 @@ # include "prenv.h" #endif -namespace mozilla { -namespace ipc { +namespace mozilla::ipc { #if defined(XP_MACOSX) && defined(__x86_64__) std::atomic sPageSizeOverride = 0; @@ -51,5 +50,4 @@ size_t SharedMemory::SystemPageSize() { #endif } -} // namespace ipc -} // namespace mozilla +} // namespace mozilla::ipc diff --git a/ipc/glue/SharedMemory_windows.cpp b/ipc/glue/SharedMemory_windows.cpp index 1cc93687af38..7aa812e16dad 100644 --- a/ipc/glue/SharedMemory_windows.cpp +++ b/ipc/glue/SharedMemory_windows.cpp @@ -4,12 +4,11 @@ * 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/. */ -#include - #include "mozilla/ipc/SharedMemory.h" -namespace mozilla { -namespace ipc { +#include + +namespace mozilla::ipc { void SharedMemory::SystemProtect(char* aAddr, size_t aSize, int aRights) { if (!SystemProtectFallible(aAddr, aSize, aRights)) { @@ -37,5 +36,4 @@ size_t SharedMemory::SystemPageSize() { return si.dwPageSize; } -} // namespace ipc -} // namespace mozilla +} // namespace mozilla::ipc diff --git a/ipc/glue/Shmem.cpp b/ipc/glue/Shmem.cpp index 442c6fb73c02..c96e496b08de 100644 --- a/ipc/glue/Shmem.cpp +++ b/ipc/glue/Shmem.cpp @@ -7,7 +7,7 @@ #include "Shmem.h" #include "ProtocolUtils.h" -#include "SharedMemoryBasic.h" +#include "SharedMemory.h" #include "ShmemMessageUtils.h" #include "chrome/common/ipc_message_utils.h" #include "mozilla/Unused.h" @@ -63,7 +63,7 @@ class ShmemDestroyed : public IPC::Message { }; static already_AddRefed NewSegment() { - return MakeAndAddRef(); + return MakeAndAddRef(); } static already_AddRefed CreateSegment(size_t aNBytes) { @@ -116,13 +116,13 @@ static already_AddRefed ReadSegment( static void Protect(SharedMemory* aSegment) { MOZ_ASSERT(aSegment, "null segment"); - aSegment->Protect(reinterpret_cast(aSegment->memory()), + aSegment->Protect(reinterpret_cast(aSegment->Memory()), aSegment->Size(), RightsNone); } static void Unprotect(SharedMemory* aSegment) { MOZ_ASSERT(aSegment, "null segment"); - aSegment->Protect(reinterpret_cast(aSegment->memory()), + aSegment->Protect(reinterpret_cast(aSegment->Memory()), aSegment->Size(), RightsRead | RightsWrite); } @@ -153,7 +153,7 @@ void Shmem::RevokeRights() { #endif // if defined(DEBUG) Shmem::Shmem(SharedMemory* aSegment, id_t aId, size_t aSize, bool aUnsafe) - : mSegment(aSegment), mData(aSegment->memory()), mSize(aSize), mId(aId) { + : mSegment(aSegment), mData(aSegment->Memory()), mSize(aSize), mId(aId) { #ifdef DEBUG mUnsafe = aUnsafe; Unprotect(mSegment); diff --git a/ipc/glue/Shmem.h b/ipc/glue/Shmem.h index 657d5efbdd8a..f9b3e340111d 100644 --- a/ipc/glue/Shmem.h +++ b/ipc/glue/Shmem.h @@ -35,9 +35,8 @@ * means is OS specific.) * * (4a) The child receives the special IPC message, and using the - * |SharedMemory{Basic}::Handle| it was passed, creates a - * |mozilla::ipc::SharedMemory| in the child - * process. + * |SharedMemory::Handle| it was passed, creates a |mozilla::ipc::SharedMemory| + * in the child process. * * (4b) After sending the "shmem-created" IPC message, IPDL-generated * code in the parent returns a |mozilla::ipc::Shmem| back to the C++ diff --git a/ipc/glue/moz.build b/ipc/glue/moz.build index b944e2f8156b..cc699a8ffa5c 100644 --- a/ipc/glue/moz.build +++ b/ipc/glue/moz.build @@ -57,7 +57,6 @@ EXPORTS.mozilla.ipc += [ "ScopedPort.h", "SerializedStructuredCloneBuffer.h", "SharedMemory.h", - "SharedMemoryBasic.h", "Shmem.h", "ShmemMessageUtils.h", "SideVariant.h", @@ -115,12 +114,11 @@ else: ] if CONFIG["OS_ARCH"] == "Darwin": - EXPORTS.mozilla.ipc += ["SharedMemoryBasic_mach.h"] - SOURCES += [ - "SharedMemoryBasic_mach.mm", - ] + EXPORTS.mozilla.ipc += ["SharedMemoryImpl_mach.h"] + SOURCES += ["SharedMemoryImpl_mach.cpp"] else: - EXPORTS.mozilla.ipc += ["SharedMemoryBasic_chromium.h"] + EXPORTS.mozilla.ipc += ["SharedMemoryImpl_chromium.h"] + SOURCES += ["SharedMemoryImpl_chromium.cpp"] if CONFIG["OS_ARCH"] == "Linux": UNIFIED_SOURCES += [ diff --git a/ipc/gtest/TestBigBuffer.cpp b/ipc/gtest/TestBigBuffer.cpp index 88c353d53d06..65e79d4df6a4 100644 --- a/ipc/gtest/TestBigBuffer.cpp +++ b/ipc/gtest/TestBigBuffer.cpp @@ -69,7 +69,7 @@ TEST(BigBuffer, BigSize) BigBuffer in{Span(data)}; EXPECT_NE(in.GetSharedMemory(), nullptr); EXPECT_EQ(in.Size(), size); - EXPECT_EQ(in.GetSharedMemory()->memory(), in.Data()); + EXPECT_EQ(in.GetSharedMemory()->Memory(), in.Data()); BigBuffer out; ASSERT_TRUE(SerializeAndDeserialize(std::move(in), &out)); @@ -78,7 +78,7 @@ TEST(BigBuffer, BigSize) EXPECT_EQ(in.Size(), 0u); EXPECT_NE(out.GetSharedMemory(), nullptr); EXPECT_EQ(out.Size(), size); - EXPECT_EQ(out.GetSharedMemory()->memory(), out.Data()); + EXPECT_EQ(out.GetSharedMemory()->Memory(), out.Data()); EXPECT_TRUE(out.AsSpan() == Span(data)); } diff --git a/ipc/gtest/TestSharedMemory.cpp b/ipc/gtest/TestSharedMemory.cpp index 5d27bd81d052..8e8380afc656 100644 --- a/ipc/gtest/TestSharedMemory.cpp +++ b/ipc/gtest/TestSharedMemory.cpp @@ -10,7 +10,6 @@ #include "mozilla/RefPtr.h" #include "mozilla/ipc/SharedMemory.h" -#include "mozilla/ipc/SharedMemoryBasic.h" #ifdef XP_LINUX # include @@ -285,13 +284,13 @@ TEST(IPCSharedMemory, IsZero) #ifndef FUZZING TEST(IPCSharedMemory, BasicIsZero) { - auto shm = MakeRefPtr(); + auto shm = MakeRefPtr(); static constexpr size_t kSize = 65536; ASSERT_TRUE(shm->Create(kSize)); ASSERT_TRUE(shm->Map(kSize)); - auto* mem = reinterpret_cast(shm->memory()); + auto* mem = reinterpret_cast(shm->Memory()); for (size_t i = 0; i < kSize; ++i) { ASSERT_EQ(mem[i], 0) << "offset " << i; }