mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 09:54:42 +00:00
Bug 1454819 - Simplify SharedMemory classes r=ipc-reviewers,nika
Differential Revision: https://phabricator.services.mozilla.com/D217487
This commit is contained in:
parent
1f68e6ad0c
commit
ab8fa1ab81
@ -304,7 +304,7 @@ bool DrawTargetWebgl::Init(const IntSize& size, const SurfaceFormat format,
|
||||
return false;
|
||||
}
|
||||
|
||||
auto shmem = MakeRefPtr<mozilla::ipc::SharedMemoryBasic>();
|
||||
auto shmem = MakeRefPtr<mozilla::ipc::SharedMemory>();
|
||||
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<uint8_t*>(mShmem->memory()), size, stride,
|
||||
if (!mSkia->Init(reinterpret_cast<uint8_t*>(mShmem->Memory()), size, stride,
|
||||
SurfaceFormat::B8G8R8A8, true)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -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 <vector>
|
||||
@ -368,7 +368,7 @@ class DrawTargetWebgl : public DrawTarget, public SupportsWeakPtr {
|
||||
// Skia DT pointing to the same pixel data, but without any applied clips.
|
||||
RefPtr<DrawTargetSkia> mSkiaNoClip;
|
||||
// The Shmem backing the Skia DT, if applicable.
|
||||
RefPtr<mozilla::ipc::SharedMemoryBasic> mShmem;
|
||||
RefPtr<mozilla::ipc::SharedMemory> mShmem;
|
||||
// The currently cached snapshot of the WebGL context
|
||||
RefPtr<SourceSurfaceWebgl> 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; }
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -21,12 +21,12 @@ namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
struct ShmemAndHandle {
|
||||
RefPtr<ipc::SharedMemoryBasic> shmem;
|
||||
RefPtr<ipc::SharedMemory> shmem;
|
||||
Handle handle;
|
||||
};
|
||||
|
||||
static Maybe<ShmemAndHandle> CreateAndMapShmem(size_t aSize) {
|
||||
auto shmem = MakeRefPtr<ipc::SharedMemoryBasic>();
|
||||
auto shmem = MakeRefPtr<ipc::SharedMemory>();
|
||||
if (!shmem->Create(aSize) || !shmem->Map(aSize)) {
|
||||
return Nothing();
|
||||
}
|
||||
@ -66,7 +66,7 @@ bool CanvasDrawEventRecorder::Init(TextureType aTextureType,
|
||||
return false;
|
||||
}
|
||||
|
||||
mHeader = static_cast<Header*>(header->shmem->memory());
|
||||
mHeader = static_cast<Header*>(header->shmem->Memory());
|
||||
mHeader->eventCount = 0;
|
||||
mHeader->writerWaitCount = 0;
|
||||
mHeader->writerState = State::Processing;
|
||||
|
@ -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<Helpers> mHelpers;
|
||||
|
||||
TextureType mTextureType = TextureType::Unknown;
|
||||
RefPtr<ipc::SharedMemoryBasic> mHeaderShmem;
|
||||
RefPtr<ipc::SharedMemory> mHeaderShmem;
|
||||
Header* mHeader = nullptr;
|
||||
|
||||
struct CanvasBuffer : public gfx::ContiguousBuffer {
|
||||
RefPtr<ipc::SharedMemoryBasic> shmem;
|
||||
RefPtr<ipc::SharedMemory> shmem;
|
||||
|
||||
CanvasBuffer() : ContiguousBuffer(nullptr) {}
|
||||
|
||||
explicit CanvasBuffer(RefPtr<ipc::SharedMemoryBasic>&& aShmem)
|
||||
: ContiguousBuffer(static_cast<char*>(aShmem->memory()),
|
||||
explicit CanvasBuffer(RefPtr<ipc::SharedMemory>&& aShmem)
|
||||
: ContiguousBuffer(static_cast<char*>(aShmem->Memory()),
|
||||
aShmem->Size()),
|
||||
shmem(std::move(aShmem)) {}
|
||||
|
||||
@ -180,9 +180,9 @@ class CanvasDrawEventRecorder final : public gfx::DrawEventRecorderPrivate,
|
||||
};
|
||||
|
||||
struct RecycledBuffer {
|
||||
RefPtr<ipc::SharedMemoryBasic> shmem;
|
||||
RefPtr<ipc::SharedMemory> shmem;
|
||||
int64_t eventCount = 0;
|
||||
explicit RecycledBuffer(RefPtr<ipc::SharedMemoryBasic>&& aShmem,
|
||||
explicit RecycledBuffer(RefPtr<ipc::SharedMemory>&& aShmem,
|
||||
int64_t aEventCount)
|
||||
: shmem(std::move(aShmem)), eventCount(aEventCount) {}
|
||||
size_t Capacity() { return shmem->Size(); }
|
||||
|
@ -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);
|
||||
|
@ -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<SharedMemoryBasic>();
|
||||
mBuf = MakeAndAddRef<SharedMemory>();
|
||||
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<uint8_t*>(mOldBuf->memory());
|
||||
return static_cast<uint8_t*>(mOldBuf->Memory());
|
||||
}
|
||||
return static_cast<uint8_t*>(mBuf->memory());
|
||||
return static_cast<uint8_t*>(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<SharedMemoryBasic> buf = new SharedMemoryBasic();
|
||||
RefPtr<SharedMemory> 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<char*>(buf->memory()), len, RightsRead);
|
||||
buf->Protect(static_cast<char*>(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<char*>(mBuf->memory()), len, RightsRead);
|
||||
mBuf->Protect(static_cast<char*>(mBuf->Memory()), len, RightsRead);
|
||||
#endif
|
||||
|
||||
mFinalized = true;
|
||||
|
@ -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<uint8_t*>(mBuf->memory()); }
|
||||
uint8_t* GetData() override { return static_cast<uint8_t*>(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<SharedMemoryBasic> mBuf;
|
||||
RefPtr<SharedMemory> 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<IntRect> mDirtyRect;
|
||||
IntSize mSize;
|
||||
RefPtr<SharedMemoryBasic> mBuf;
|
||||
RefPtr<SharedMemoryBasic> mOldBuf;
|
||||
RefPtr<SharedMemory> mBuf;
|
||||
RefPtr<SharedMemory> mOldBuf;
|
||||
SurfaceFormat mFormat;
|
||||
bool mClosed : 1;
|
||||
bool mFinalized : 1;
|
||||
|
@ -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"
|
||||
|
@ -42,7 +42,7 @@ namespace mozilla {
|
||||
|
||||
namespace ipc {
|
||||
|
||||
class SharedMemoryBasic;
|
||||
class SharedMemory;
|
||||
|
||||
} // namespace ipc
|
||||
|
||||
|
@ -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<ipc::SharedMemoryBasic> mShmem;
|
||||
RefPtr<ipc::SharedMemory> mShmem;
|
||||
RefPtr<CanvasChild> mCanvasChild MOZ_GUARDED_BY(mMutex);
|
||||
RefPtr<dom::ThreadSafeWorkerRef> 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<ipc::SharedMemoryBasic>();
|
||||
auto dataSurfaceShmem = MakeRefPtr<ipc::SharedMemory>();
|
||||
if (!dataSurfaceShmem->Create(sizeRequired) ||
|
||||
!dataSurfaceShmem->Map(sizeRequired)) {
|
||||
return false;
|
||||
@ -529,7 +528,7 @@ already_AddRefed<gfx::DataSourceSurface> CanvasChild::GetDataSurface(
|
||||
auto it = mTextureInfo.find(aTextureId);
|
||||
if (it != mTextureInfo.end() && it->second.mSnapshotShmem) {
|
||||
const auto shmemPtr =
|
||||
reinterpret_cast<uint8_t*>(it->second.mSnapshotShmem->memory());
|
||||
reinterpret_cast<uint8_t*>(it->second.mSnapshotShmem->Memory());
|
||||
MOZ_ASSERT(shmemPtr);
|
||||
mRecorder->RecordEvent(RecordedPrepareShmem(aTextureId));
|
||||
auto checkpoint = CreateCheckpoint();
|
||||
@ -571,7 +570,7 @@ already_AddRefed<gfx::DataSourceSurface> CanvasChild::GetDataSurface(
|
||||
|
||||
mDataSurfaceShmemAvailable = false;
|
||||
|
||||
auto* data = static_cast<uint8_t*>(mDataSurfaceShmem->memory());
|
||||
auto* data = static_cast<uint8_t*>(mDataSurfaceShmem->Memory());
|
||||
|
||||
RefPtr<gfx::DataSourceSurface> dataSurface =
|
||||
gfx::Factory::CreateWrappingDataSourceSurface(
|
||||
@ -598,8 +597,8 @@ already_AddRefed<gfx::SourceSurface> CanvasChild::WrapSurface(
|
||||
}
|
||||
|
||||
void CanvasChild::ReturnDataSurfaceShmem(
|
||||
already_AddRefed<ipc::SharedMemoryBasic> aDataSurfaceShmem) {
|
||||
RefPtr<ipc::SharedMemoryBasic> data = aDataSurfaceShmem;
|
||||
already_AddRefed<ipc::SharedMemory> aDataSurfaceShmem) {
|
||||
RefPtr<ipc::SharedMemory> 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<ipc::SharedMemoryBasic>();
|
||||
auto shmem = MakeRefPtr<ipc::SharedMemory>();
|
||||
if (NS_WARN_IF(!shmem->SetHandle(std::move(aShmemHandle),
|
||||
ipc::SharedMemory::RightsReadOnly)) ||
|
||||
NS_WARN_IF(!shmem->Map(aShmemSize))) {
|
||||
|
@ -156,7 +156,7 @@ class CanvasChild final : public PCanvasChild, public SupportsWeakPtr {
|
||||
void CleanupTexture(int64_t aTextureId);
|
||||
|
||||
void ReturnDataSurfaceShmem(
|
||||
already_AddRefed<ipc::SharedMemoryBasic> aDataSurfaceShmem);
|
||||
already_AddRefed<ipc::SharedMemory> aDataSurfaceShmem);
|
||||
|
||||
protected:
|
||||
void ActorDestroy(ActorDestroyReason aWhy) final;
|
||||
@ -179,12 +179,12 @@ class CanvasChild final : public PCanvasChild, public SupportsWeakPtr {
|
||||
RefPtr<dom::ThreadSafeWorkerRef> mWorkerRef;
|
||||
RefPtr<CanvasDrawEventRecorder> mRecorder;
|
||||
|
||||
RefPtr<ipc::SharedMemoryBasic> mDataSurfaceShmem;
|
||||
RefPtr<ipc::SharedMemory> mDataSurfaceShmem;
|
||||
bool mDataSurfaceShmemAvailable = false;
|
||||
int64_t mLastWriteLockCheckpoint = 0;
|
||||
uint32_t mTransactionsSinceGetDataSurface = kCacheDataSurfaceThreshold;
|
||||
struct TextureInfo {
|
||||
RefPtr<mozilla::ipc::SharedMemoryBasic> mSnapshotShmem;
|
||||
RefPtr<mozilla::ipc::SharedMemory> mSnapshotShmem;
|
||||
bool mRequiresRefresh = false;
|
||||
};
|
||||
std::unordered_map<int64_t, TextureInfo> mTextureInfo;
|
||||
|
@ -101,11 +101,11 @@ bool CanvasTranslator::IsInTaskQueue() const {
|
||||
return gfx::CanvasRenderThread::IsInCanvasRenderThread();
|
||||
}
|
||||
|
||||
static bool CreateAndMapShmem(RefPtr<ipc::SharedMemoryBasic>& aShmem,
|
||||
static bool CreateAndMapShmem(RefPtr<ipc::SharedMemory>& aShmem,
|
||||
Handle&& aHandle,
|
||||
ipc::SharedMemory::OpenRights aOpenRights,
|
||||
size_t aSize) {
|
||||
auto shmem = MakeRefPtr<ipc::SharedMemoryBasic>();
|
||||
auto shmem = MakeRefPtr<ipc::SharedMemory>();
|
||||
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<ipc::SharedMemoryBasic>();
|
||||
mHeaderShmem = MakeAndAddRef<ipc::SharedMemory>();
|
||||
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<Header*>(mHeaderShmem->memory());
|
||||
mHeader = static_cast<Header*>(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<ipc::SharedMemoryBasic::Handle&&, size_t>(
|
||||
"CanvasTranslator::AddBuffer", this, &CanvasTranslator::AddBuffer,
|
||||
std::move(aBufferHandle), aBufferSize));
|
||||
DispatchToTaskQueue(NewRunnableMethod<ipc::SharedMemory::Handle&&, size_t>(
|
||||
"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<ipc::SharedMemoryBasic::Handle&&, size_t>(
|
||||
"CanvasTranslator::SetDataSurfaceBuffer", this,
|
||||
&CanvasTranslator::SetDataSurfaceBuffer, std::move(aBufferHandle),
|
||||
aBufferSize));
|
||||
DispatchToTaskQueue(NewRunnableMethod<ipc::SharedMemory::Handle&&, size_t>(
|
||||
"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<uint8_t*>(mDataSurfaceShmem->memory());
|
||||
uint8_t* dst = static_cast<uint8_t*>(mDataSurfaceShmem->Memory());
|
||||
const uint8_t* src = map->GetData();
|
||||
const uint8_t* endSrc = src + (srcSize.height * srcStride);
|
||||
while (src < endSrc) {
|
||||
|
@ -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<CanvasTranslatorEvent> AddBuffer(
|
||||
ipc::SharedMemoryBasic::Handle&& aBufferHandle, size_t aBufferSize) {
|
||||
ipc::SharedMemory::Handle&& aBufferHandle, size_t aBufferSize) {
|
||||
return MakeUnique<CanvasTranslatorEvent>(
|
||||
Tag::AddBuffer, std::move(aBufferHandle), aBufferSize);
|
||||
}
|
||||
|
||||
static UniquePtr<CanvasTranslatorEvent> SetDataSurfaceBuffer(
|
||||
ipc::SharedMemoryBasic::Handle&& aBufferHandle, size_t aBufferSize) {
|
||||
ipc::SharedMemory::Handle&& aBufferHandle, size_t aBufferSize) {
|
||||
return MakeUnique<CanvasTranslatorEvent>(
|
||||
Tag::SetDataSurfaceBuffer, std::move(aBufferHandle), aBufferSize);
|
||||
}
|
||||
@ -336,12 +336,12 @@ class CanvasTranslator final : public gfx::InlineTranslator,
|
||||
return MakeUnique<CanvasTranslatorEvent>(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<ipc::SharedMemoryBasic> mHeaderShmem;
|
||||
RefPtr<ipc::SharedMemory> mHeaderShmem;
|
||||
Header* mHeader = nullptr;
|
||||
|
||||
struct CanvasShmem {
|
||||
RefPtr<ipc::SharedMemoryBasic> shmem;
|
||||
RefPtr<ipc::SharedMemory> shmem;
|
||||
auto Size() { return shmem->Size(); }
|
||||
gfx::MemReader CreateMemReader() {
|
||||
return {static_cast<char*>(shmem->memory()), Size()};
|
||||
return {static_cast<char*>(shmem->Memory()), Size()};
|
||||
}
|
||||
};
|
||||
std::queue<CanvasShmem> mCanvasShmems;
|
||||
CanvasShmem mCurrentShmem;
|
||||
gfx::MemReader mCurrentMemReader{0, 0};
|
||||
RefPtr<ipc::SharedMemoryBasic> mDataSurfaceShmem;
|
||||
RefPtr<ipc::SharedMemory> mDataSurfaceShmem;
|
||||
UniquePtr<CrossProcessSemaphore> mWriterSemaphore;
|
||||
UniquePtr<CrossProcessSemaphore> mReaderSemaphore;
|
||||
TextureType mTextureType = TextureType::Unknown;
|
||||
|
@ -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";
|
||||
|
@ -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 {
|
||||
|
@ -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";
|
||||
|
@ -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
|
||||
|
@ -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 <windows.h> via SharedMemoryBasic.h. So this header, which defines the
|
||||
// actual shared-memory FontList class, is included only by the .cpp files that
|
||||
// of <windows.h> 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.
|
||||
|
||||
|
@ -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<char*>(shmem_->memory());
|
||||
buffer_ = reinterpret_cast<char*>(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<const char*>(shmem_->memory());
|
||||
buffer_ = reinterpret_cast<const char*>(shmem_->Memory());
|
||||
}
|
||||
}
|
||||
remaining_ = full_len;
|
||||
|
@ -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<uint8_t*>(mData.as<1>()->memory());
|
||||
: reinterpret_cast<uint8_t*>(mData.as<1>()->Memory());
|
||||
}
|
||||
const uint8_t* BigBuffer::Data() const {
|
||||
return mData.is<0>()
|
||||
? mData.as<0>().get()
|
||||
: reinterpret_cast<const uint8_t*>(mData.as<1>()->memory());
|
||||
: reinterpret_cast<const uint8_t*>(mData.as<1>()->Memory());
|
||||
}
|
||||
|
||||
auto BigBuffer::TryAllocBuffer(size_t aSize) -> Maybe<Storage> {
|
||||
@ -40,7 +40,7 @@ auto BigBuffer::TryAllocBuffer(size_t aSize) -> Maybe<Storage> {
|
||||
return Some(AsVariant(std::move(mem)));
|
||||
}
|
||||
|
||||
RefPtr<SharedMemory> shmem = new SharedMemoryBasic();
|
||||
RefPtr<SharedMemory> shmem = new SharedMemory();
|
||||
size_t capacity = SharedMemory::PageAlignedSize(aSize);
|
||||
if (!shmem->Create(capacity) || !shmem->Map(capacity)) {
|
||||
return {};
|
||||
@ -80,7 +80,7 @@ bool IPC::ParamTraits<mozilla::ipc::BigBuffer>::Read(MessageReader* aReader,
|
||||
}
|
||||
|
||||
if (isShmem) {
|
||||
RefPtr<SharedMemory> shmem = new SharedMemoryBasic();
|
||||
RefPtr<SharedMemory> shmem = new SharedMemory();
|
||||
size_t capacity = SharedMemory::PageAlignedSize(size);
|
||||
if (!shmem->ReadHandle(aReader) || !shmem->Map(capacity)) {
|
||||
aReader->FatalError("Failed to read data shmem");
|
||||
|
@ -15,7 +15,7 @@
|
||||
#endif
|
||||
#if !defined(XP_WIN) && !defined(XP_NETBSD) && !defined(XP_OPENBSD)
|
||||
# include <pthread.h>
|
||||
# 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<mozilla::ipc::SharedMemoryBasic> mSharedBuffer;
|
||||
RefPtr<mozilla::ipc::SharedMemory> mSharedBuffer;
|
||||
pthread_mutex_t* mMutex;
|
||||
mozilla::Atomic<int32_t>* mCount;
|
||||
#endif
|
||||
|
@ -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<MutexData*>(mSharedBuffer->memory());
|
||||
MutexData* data = static_cast<MutexData*>(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<MutexData*>(mSharedBuffer->memory());
|
||||
MutexData* data = static_cast<MutexData*>(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();
|
||||
|
@ -16,7 +16,7 @@
|
||||
#else
|
||||
# include <pthread.h>
|
||||
# include <semaphore.h>
|
||||
# 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<CrossProcessSemaphoreHandle>(
|
||||
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<mozilla::ipc::SharedMemoryBasic> mSharedBuffer;
|
||||
RefPtr<mozilla::ipc::SharedMemory> mSharedBuffer;
|
||||
sem_t* mSemaphore;
|
||||
mozilla::Atomic<int32_t>* mRefCount;
|
||||
#endif
|
||||
|
@ -28,7 +28,7 @@ namespace mozilla {
|
||||
/* static */
|
||||
CrossProcessSemaphore* CrossProcessSemaphore::Create(const char*,
|
||||
uint32_t aInitialValue) {
|
||||
RefPtr<ipc::SharedMemoryBasic> sharedBuffer = new ipc::SharedMemoryBasic;
|
||||
RefPtr<ipc::SharedMemory> 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<SemaphoreData*>(sharedBuffer->memory());
|
||||
SemaphoreData* data = static_cast<SemaphoreData*>(sharedBuffer->Memory());
|
||||
|
||||
if (!data) {
|
||||
return nullptr;
|
||||
@ -61,7 +61,7 @@ CrossProcessSemaphore* CrossProcessSemaphore::Create(const char*,
|
||||
/* static */
|
||||
CrossProcessSemaphore* CrossProcessSemaphore::Create(
|
||||
CrossProcessSemaphoreHandle aHandle) {
|
||||
RefPtr<ipc::SharedMemoryBasic> sharedBuffer = new ipc::SharedMemoryBasic;
|
||||
RefPtr<ipc::SharedMemory> sharedBuffer = new ipc::SharedMemory;
|
||||
|
||||
if (!sharedBuffer->IsHandleValid(aHandle)) {
|
||||
return nullptr;
|
||||
@ -78,7 +78,7 @@ CrossProcessSemaphore* CrossProcessSemaphore::Create(
|
||||
|
||||
sharedBuffer->CloseHandle();
|
||||
|
||||
SemaphoreData* data = static_cast<SemaphoreData*>(sharedBuffer->memory());
|
||||
SemaphoreData* data = static_cast<SemaphoreData*>(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();
|
||||
|
@ -71,7 +71,7 @@ static void DoNotifyOnUnlock(DataPipeAutoLock& aLock,
|
||||
class DataPipeLink : public NodeController::PortObserver {
|
||||
public:
|
||||
DataPipeLink(bool aReceiverSide, std::shared_ptr<Mutex> 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<Mutex> mMutex;
|
||||
|
||||
ScopedPort mPort MOZ_GUARDED_BY(*mMutex);
|
||||
SharedMemoryBasic::Handle mShmemHandle MOZ_GUARDED_BY(*mMutex);
|
||||
SharedMemory::Handle mShmemHandle MOZ_GUARDED_BY(*mMutex);
|
||||
const RefPtr<SharedMemory> 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<char*>(link->mShmem->memory()) + link->mOffset;
|
||||
char* start = static_cast<char*>(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<T>* 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<SharedMemoryBasic>();
|
||||
auto shmem = MakeRefPtr<SharedMemory>();
|
||||
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;
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "chrome/common/process_watcher.h"
|
||||
#ifdef XP_DARWIN
|
||||
# include <mach/mach_traps.h>
|
||||
# include "SharedMemoryBasic.h"
|
||||
# include "SharedMemory.h"
|
||||
# include "base/rand_util.h"
|
||||
# include "chrome/common/mach_ipc_mac.h"
|
||||
# include "mozilla/StaticPrefs_media.h"
|
||||
|
@ -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<ipc::SharedMemoryBasic> shm = MakeAndAddRef<ipc::SharedMemoryBasic>();
|
||||
RefPtr<ipc::SharedMemory> shm = MakeAndAddRef<ipc::SharedMemory>();
|
||||
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<ipc::SharedMemoryBasic>&& aRef)
|
||||
RefPtr<ipc::SharedMemory>&& aRef)
|
||||
: mRef(aRef) {}
|
||||
|
||||
Maybe<WritableSharedMemoryMapping> WritableSharedMemoryMapping::Open(
|
||||
@ -61,7 +61,7 @@ Maybe<WritableSharedMemoryMapping> WritableSharedMemoryMapping::Open(
|
||||
return Some(WritableSharedMemoryMapping(nullptr));
|
||||
}
|
||||
|
||||
RefPtr<ipc::SharedMemoryBasic> shm = MakeAndAddRef<ipc::SharedMemoryBasic>();
|
||||
RefPtr<ipc::SharedMemory> shm = MakeAndAddRef<ipc::SharedMemory>();
|
||||
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<uint8_t> WritableSharedMemoryMapping::Bytes() {
|
||||
return Span<uint8_t>();
|
||||
}
|
||||
|
||||
uint8_t* mem = static_cast<uint8_t*>(mRef->memory());
|
||||
uint8_t* mem = static_cast<uint8_t*>(mRef->Memory());
|
||||
return Span(mem, mRef->Size());
|
||||
}
|
||||
|
||||
|
@ -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 <utility>
|
||||
|
||||
@ -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<mozilla::ipc::SharedMemoryBasic>&& aRef);
|
||||
RefPtr<mozilla::ipc::SharedMemory>&& aRef);
|
||||
|
||||
RefPtr<mozilla::ipc::SharedMemoryBasic> mRef;
|
||||
RefPtr<mozilla::ipc::SharedMemory> mRef;
|
||||
};
|
||||
|
||||
} // namespace mozilla::ipc
|
||||
|
@ -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 <math.h>
|
||||
|
||||
#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<size_t> gShmemAllocated;
|
||||
static Atomic<size_t> 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<char*>(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
|
||||
|
@ -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 <cstddef>
|
||||
|
||||
#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<char*>(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 <typename HandleImpl>
|
||||
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
|
||||
|
@ -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
|
@ -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<base::SharedMemoryHandle> {
|
||||
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
|
@ -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 <mach/port.h>
|
||||
|
||||
#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<mozilla::UniqueMachSendRight> {
|
||||
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
|
47
ipc/glue/SharedMemoryImpl_chromium.cpp
Normal file
47
ipc/glue/SharedMemoryImpl_chromium.cpp
Normal file
@ -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
|
51
ipc/glue/SharedMemoryImpl_chromium.h
Normal file
51
ipc/glue/SharedMemoryImpl_chromium.h
Normal file
@ -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
|
@ -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 <map>
|
||||
|
||||
#include <mach/vm_map.h>
|
||||
@ -21,7 +22,6 @@
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#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<mach_vm_address_t>(reinterpret_cast<uintptr_t>(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
|
56
ipc/glue/SharedMemoryImpl_mach.h
Normal file
56
ipc/glue/SharedMemoryImpl_mach.h
Normal file
@ -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 <mach/port.h>
|
||||
|
||||
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
|
@ -13,8 +13,7 @@
|
||||
# include "prenv.h"
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
namespace mozilla::ipc {
|
||||
|
||||
#if defined(XP_MACOSX) && defined(__x86_64__)
|
||||
std::atomic<size_t> sPageSizeOverride = 0;
|
||||
@ -51,5 +50,4 @@ size_t SharedMemory::SystemPageSize() {
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace ipc
|
||||
} // namespace mozilla
|
||||
} // namespace mozilla::ipc
|
||||
|
@ -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 <windows.h>
|
||||
|
||||
#include "mozilla/ipc/SharedMemory.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
#include <windows.h>
|
||||
|
||||
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
|
||||
|
@ -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<SharedMemory> NewSegment() {
|
||||
return MakeAndAddRef<SharedMemoryBasic>();
|
||||
return MakeAndAddRef<SharedMemory>();
|
||||
}
|
||||
|
||||
static already_AddRefed<SharedMemory> CreateSegment(size_t aNBytes) {
|
||||
@ -116,13 +116,13 @@ static already_AddRefed<SharedMemory> ReadSegment(
|
||||
|
||||
static void Protect(SharedMemory* aSegment) {
|
||||
MOZ_ASSERT(aSegment, "null segment");
|
||||
aSegment->Protect(reinterpret_cast<char*>(aSegment->memory()),
|
||||
aSegment->Protect(reinterpret_cast<char*>(aSegment->Memory()),
|
||||
aSegment->Size(), RightsNone);
|
||||
}
|
||||
|
||||
static void Unprotect(SharedMemory* aSegment) {
|
||||
MOZ_ASSERT(aSegment, "null segment");
|
||||
aSegment->Protect(reinterpret_cast<char*>(aSegment->memory()),
|
||||
aSegment->Protect(reinterpret_cast<char*>(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);
|
||||
|
@ -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++
|
||||
|
@ -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 += [
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/ipc/SharedMemory.h"
|
||||
#include "mozilla/ipc/SharedMemoryBasic.h"
|
||||
|
||||
#ifdef XP_LINUX
|
||||
# include <errno.h>
|
||||
@ -285,13 +284,13 @@ TEST(IPCSharedMemory, IsZero)
|
||||
#ifndef FUZZING
|
||||
TEST(IPCSharedMemory, BasicIsZero)
|
||||
{
|
||||
auto shm = MakeRefPtr<ipc::SharedMemoryBasic>();
|
||||
auto shm = MakeRefPtr<ipc::SharedMemory>();
|
||||
|
||||
static constexpr size_t kSize = 65536;
|
||||
ASSERT_TRUE(shm->Create(kSize));
|
||||
ASSERT_TRUE(shm->Map(kSize));
|
||||
|
||||
auto* mem = reinterpret_cast<char*>(shm->memory());
|
||||
auto* mem = reinterpret_cast<char*>(shm->Memory());
|
||||
for (size_t i = 0; i < kSize; ++i) {
|
||||
ASSERT_EQ(mem[i], 0) << "offset " << i;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user