Bug 1777656: Delete mozilla::ipc::SharedMemory::SharedMemorytype. r=nika,media-playback-reviewers,padenot

Differential Revision: https://phabricator.services.mozilla.com/D150852
This commit is contained in:
Jim Blandy 2022-07-05 20:08:31 +00:00
parent 8e4c10f871
commit 2f5eb12516
55 changed files with 165 additions and 319 deletions

View File

@ -7875,7 +7875,7 @@ static bool AllocateShmem(mozilla::dom::ContentChild* aChild,
IShmemAllocator* allocator = aChild ? static_cast<IShmemAllocator*>(aChild)
: static_cast<IShmemAllocator*>(aParent);
return allocator->AllocShmem(aSize, SharedMemory::TYPE_BASIC, aShmem);
return allocator->AllocShmem(aSize, aShmem);
}
static Shmem ConvertToShmem(mozilla::dom::ContentChild* aChild,
@ -8166,7 +8166,7 @@ struct GetSurfaceDataShmem {
ReturnType Allocate(size_t aSize) {
Shmem shmem;
if (!mAllocator->AllocShmem(aSize, SharedMemory::TYPE_BASIC, &shmem)) {
if (!mAllocator->AllocShmem(aSize, &shmem)) {
return Nothing();
}

View File

@ -4310,10 +4310,8 @@ void ClientWebGLContext::TexImage(uint8_t funcDims, GLenum imageTarget,
MOZ_ASSERT(desc->sd);
const auto byteCount = pShmem->Size<uint8_t>();
const auto* const src = pShmem->get<uint8_t>();
const auto shmemType =
mozilla::ipc::SharedMemory::SharedMemoryType::TYPE_BASIC;
mozilla::ipc::Shmem shmemForResend;
if (!child->AllocShmem(byteCount, shmemType, &shmemForResend)) {
if (!child->AllocShmem(byteCount, &shmemForResend)) {
NS_WARNING("AllocShmem failed in TexImage");
return;
}

View File

@ -30,9 +30,7 @@ Maybe<Range<uint8_t>> WebGLChild::AllocPendingCmdBytes(const size_t size) {
capacity = size;
}
auto shmem = webgl::RaiiShmem::Alloc(
this, capacity,
mozilla::ipc::SharedMemory::SharedMemoryType::TYPE_BASIC);
auto shmem = webgl::RaiiShmem::Alloc(this, capacity);
if (!shmem) {
NS_WARNING("Failed to alloc shmem for AllocPendingCmdBytes.");
return {};

View File

@ -27,11 +27,10 @@ class RaiiShmem final {
public:
/// Returns zeroed data.
static RaiiShmem Alloc(
mozilla::ipc::IProtocol* const allocator, const size_t size,
const mozilla::ipc::SharedMemory::SharedMemoryType type) {
static RaiiShmem Alloc(mozilla::ipc::IProtocol* const allocator,
const size_t size) {
mozilla::ipc::Shmem shmem;
if (!allocator->AllocShmem(size, type, &shmem)) return {};
if (!allocator->AllocShmem(size, &shmem)) return {};
return {allocator, shmem};
}

View File

@ -127,9 +127,7 @@ IPCResult WebGLParent::GetFrontBufferSnapshot(
const auto& surfSize = *maybeSize;
const auto byteSize = 4 * surfSize.x * surfSize.y;
auto shmem = webgl::RaiiShmem::Alloc(
aProtocol, byteSize,
mozilla::ipc::SharedMemory::SharedMemoryType::TYPE_BASIC);
auto shmem = webgl::RaiiShmem::Alloc(aProtocol, byteSize);
if (!shmem) {
NS_WARNING("Failed to alloc shmem for RecvGetFrontBufferSnapshot.");
return IPC_FAIL(aProtocol, "Failed to allocate shmem for result");
@ -158,9 +156,7 @@ IPCResult WebGLParent::RecvGetBufferSubData(const GLenum target,
}
const auto allocSize = 1 + byteSize;
auto shmem = webgl::RaiiShmem::Alloc(
this, allocSize,
mozilla::ipc::SharedMemory::SharedMemoryType::TYPE_BASIC);
auto shmem = webgl::RaiiShmem::Alloc(this, allocSize);
if (!shmem) {
NS_WARNING("Failed to alloc shmem for RecvGetBufferSubData.");
return IPC_FAIL(this, "Failed to allocate shmem for result");
@ -188,9 +184,7 @@ IPCResult WebGLParent::RecvReadPixels(const webgl::ReadPixelsDesc& desc,
}
const auto allocSize = std::max<uint64_t>(1, byteSize);
auto shmem = webgl::RaiiShmem::Alloc(
this, allocSize,
mozilla::ipc::SharedMemory::SharedMemoryType::TYPE_BASIC);
auto shmem = webgl::RaiiShmem::Alloc(this, allocSize);
if (!shmem) {
NS_WARNING("Failed to alloc shmem for RecvReadPixels.");
return IPC_FAIL(this, "Failed to allocate shmem for result");

View File

@ -352,7 +352,7 @@ bool ChromiumCDMParent::InitCDMInputBuffer(gmp::CDMInputBuffer& aBuffer,
}
Shmem shmem;
if (!AllocShmem(aSample->Size(), Shmem::SharedMemory::TYPE_BASIC, &shmem)) {
if (!AllocShmem(aSample->Size(), &shmem)) {
return false;
}
memcpy(shmem.get<uint8_t>(), aSample->Data(), aSample->Size());
@ -391,7 +391,7 @@ bool ChromiumCDMParent::SendBufferToCDM(uint32_t aSizeInBytes) {
GMP_LOG_DEBUG("ChromiumCDMParent::SendBufferToCDM() size=%" PRIu32,
aSizeInBytes);
Shmem shmem;
if (!AllocShmem(aSizeInBytes, Shmem::SharedMemory::TYPE_BASIC, &shmem)) {
if (!AllocShmem(aSizeInBytes, &shmem)) {
return false;
}
if (!SendGiveBuffer(std::move(shmem))) {

View File

@ -18,9 +18,8 @@ namespace mozilla::gmp {
// Compressed (encoded) data goes from the Decoder parent to the child;
// pool there, and then return with Encoded() frames and goes into the parent
// pool.
bool GMPSharedMemManager::MgrAllocShmem(
GMPSharedMem::GMPMemoryClasses aClass, size_t aSize,
ipc::Shmem::SharedMemory::SharedMemoryType aType, ipc::Shmem* aMem) {
bool GMPSharedMemManager::MgrAllocShmem(GMPSharedMem::GMPMemoryClasses aClass,
size_t aSize, ipc::Shmem* aMem) {
mData->CheckThread();
// first look to see if we have a free buffer large enough
@ -36,7 +35,7 @@ bool GMPSharedMemManager::MgrAllocShmem(
// Didn't find a buffer free with enough space; allocate one
size_t pagesize = ipc::SharedMemory::SystemPageSize();
aSize = (aSize + (pagesize - 1)) & ~(pagesize - 1); // round up to page size
bool retval = Alloc(aSize, aType, aMem);
bool retval = Alloc(aSize, aMem);
if (retval) {
// The allocator (or NeedsShmem call) should never return less than we ask
// for...

View File

@ -52,9 +52,7 @@ class GMPSharedMemManager {
virtual ~GMPSharedMemManager() = default;
virtual bool MgrAllocShmem(GMPSharedMem::GMPMemoryClasses aClass,
size_t aSize,
ipc::Shmem::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aMem);
size_t aSize, ipc::Shmem* aMem);
virtual bool MgrDeallocShmem(GMPSharedMem::GMPMemoryClasses aClass,
ipc::Shmem& aMem);
@ -64,9 +62,7 @@ class GMPSharedMemManager {
// These have to be implemented using the AllocShmem/etc provided by the
// IPDL-generated interfaces, so have the Parent/Child implement them.
virtual bool Alloc(size_t aSize,
ipc::Shmem::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aMem) = 0;
virtual bool Alloc(size_t aSize, ipc::Shmem* aMem) = 0;
virtual void Dealloc(ipc::Shmem&& aMem) = 0;
private:

View File

@ -179,9 +179,7 @@ mozilla::ipc::IPCResult GMPVideoDecoderChild::RecvDecodingComplete() {
return IPC_OK();
}
bool GMPVideoDecoderChild::Alloc(size_t aSize,
Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aMem) {
bool GMPVideoDecoderChild::Alloc(size_t aSize, Shmem* aMem) {
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
bool rv;

View File

@ -42,8 +42,7 @@ class GMPVideoDecoderChild : public PGMPVideoDecoderChild,
void Error(GMPErr aError) override;
// GMPSharedMemManager
bool Alloc(size_t aSize, Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aMem) override;
bool Alloc(size_t aSize, Shmem* aMem) override;
void Dealloc(Shmem&& aMem) override;
private:

View File

@ -402,9 +402,8 @@ mozilla::ipc::IPCResult GMPVideoDecoderParent::RecvNeedShmem(
const uint32_t& aFrameBufferSize, Shmem* aMem) {
ipc::Shmem mem;
if (!mVideoHost.SharedMemMgr()->MgrAllocShmem(
GMPSharedMem::kGMPFrameData, aFrameBufferSize,
ipc::SharedMemory::TYPE_BASIC, &mem)) {
if (!mVideoHost.SharedMemMgr()->MgrAllocShmem(GMPSharedMem::kGMPFrameData,
aFrameBufferSize, &mem)) {
GMP_LOG_ERROR("%s: Failed to get a shared mem buffer for Child! size %u",
__FUNCTION__, aFrameBufferSize);
return IPC_FAIL(this, "Failed to get a shared mem buffer for Child!");

View File

@ -53,9 +53,8 @@ class GMPVideoDecoderParent final : public PGMPVideoDecoderParent,
const nsCString& GetDisplayName() const override;
// GMPSharedMemManager
bool Alloc(size_t aSize, Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aMem) override {
return AllocShmem(aSize, aType, aMem);
bool Alloc(size_t aSize, Shmem* aMem) override {
return AllocShmem(aSize, aMem);
}
void Dealloc(Shmem&& aMem) override { DeallocShmem(aMem); }

View File

@ -100,9 +100,8 @@ GMPErr GMPVideoEncodedFrameImpl::CreateEmptyFrame(uint32_t aSize) {
DestroyBuffer();
} else if (aSize > AllocatedSize()) {
DestroyBuffer();
if (!mHost->SharedMemMgr()->MgrAllocShmem(
GMPSharedMem::kGMPEncodedData, aSize, ipc::SharedMemory::TYPE_BASIC,
&mBuffer) ||
if (!mHost->SharedMemMgr()->MgrAllocShmem(GMPSharedMem::kGMPEncodedData,
aSize, &mBuffer) ||
!Buffer()) {
return GMPAllocErr;
}
@ -176,9 +175,8 @@ void GMPVideoEncodedFrameImpl::SetAllocatedSize(uint32_t aNewSize) {
}
ipc::Shmem new_mem;
if (!mHost->SharedMemMgr()->MgrAllocShmem(
GMPSharedMem::kGMPEncodedData, aNewSize,
ipc::SharedMemory::TYPE_BASIC, &new_mem) ||
if (!mHost->SharedMemMgr()->MgrAllocShmem(GMPSharedMem::kGMPEncodedData,
aNewSize, &new_mem) ||
!new_mem.get<uint8_t>()) {
return;
}

View File

@ -172,9 +172,7 @@ mozilla::ipc::IPCResult GMPVideoEncoderChild::RecvEncodingComplete() {
return IPC_OK();
}
bool GMPVideoEncoderChild::Alloc(size_t aSize,
Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aMem) {
bool GMPVideoEncoderChild::Alloc(size_t aSize, Shmem* aMem) {
MOZ_ASSERT(mPlugin->GMPMessageLoop() == MessageLoop::current());
bool rv;
@ -189,7 +187,7 @@ bool GMPVideoEncoderChild::Alloc(size_t aSize,
this, &GMPVideoEncoderChild::RecvEncodingComplete));
}
#else
rv = AllocShmem(aSize, aType, aMem);
rv = AllocShmem(aSize, aMem);
#endif
return rv;
}

View File

@ -38,8 +38,7 @@ class GMPVideoEncoderChild : public PGMPVideoEncoderChild,
void Error(GMPErr aError) override;
// GMPSharedMemManager
bool Alloc(size_t aSize, Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aMem) override;
bool Alloc(size_t aSize, Shmem* aMem) override;
void Dealloc(Shmem&& aMem) override;
private:

View File

@ -279,9 +279,8 @@ mozilla::ipc::IPCResult GMPVideoEncoderParent::RecvNeedShmem(
// This test may be paranoia now that we don't shut down the VideoHost
// in ::Shutdown, but doesn't hurt
if (!mVideoHost.SharedMemMgr() ||
!mVideoHost.SharedMemMgr()->MgrAllocShmem(
GMPSharedMem::kGMPEncodedData, aEncodedBufferSize,
ipc::SharedMemory::TYPE_BASIC, &mem)) {
!mVideoHost.SharedMemMgr()->MgrAllocShmem(GMPSharedMem::kGMPEncodedData,
aEncodedBufferSize, &mem)) {
GMP_LOG_ERROR(
"%s::%s: Failed to get a shared mem buffer for Child! size %u",
__CLASS__, __FUNCTION__, aEncodedBufferSize);

View File

@ -51,9 +51,8 @@ class GMPVideoEncoderParent : public GMPVideoEncoderProxy,
uint32_t GetPluginId() const override { return mPluginId; }
// GMPSharedMemManager
bool Alloc(size_t aSize, Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aMem) override {
return AllocShmem(aSize, aType, aMem);
bool Alloc(size_t aSize, Shmem* aMem) override {
return AllocShmem(aSize, aMem);
}
void Dealloc(Shmem&& aMem) override { DeallocShmem(aMem); }

View File

@ -72,9 +72,8 @@ GMPErr GMPPlaneImpl::MaybeResize(int32_t aNewSize) {
}
ipc::Shmem new_mem;
if (!mHost->SharedMemMgr()->MgrAllocShmem(
GMPSharedMem::kGMPFrameData, aNewSize, ipc::SharedMemory::TYPE_BASIC,
&new_mem) ||
if (!mHost->SharedMemMgr()->MgrAllocShmem(GMPSharedMem::kGMPFrameData,
aNewSize, &new_mem) ||
!new_mem.get<uint8_t>()) {
return GMPAllocErr;
}

View File

@ -62,16 +62,11 @@ class RemoteDecoderManagerChild final
void DeallocateSurfaceDescriptor(
const SurfaceDescriptorGPUVideo& aSD) override;
bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override {
return PRemoteDecoderManagerChild::AllocShmem(aSize, aShmType, aShmem);
bool AllocShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override {
return PRemoteDecoderManagerChild::AllocShmem(aSize, aShmem);
}
bool AllocUnsafeShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override {
return PRemoteDecoderManagerChild::AllocUnsafeShmem(aSize, aShmType,
aShmem);
bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override {
return PRemoteDecoderManagerChild::AllocUnsafeShmem(aSize, aShmem);
}
// Can be called from any thread, dispatches the request to the IPDL thread

View File

@ -272,8 +272,7 @@ mozilla::ipc::IPCResult RemoteDecoderManagerParent::RecvReadback(
size_t length = ImageDataSerializer::ComputeRGBBufferSize(size, format);
Shmem buffer;
if (!length ||
!AllocShmem(length, Shmem::SharedMemory::TYPE_BASIC, &buffer)) {
if (!length || !AllocShmem(length, &buffer)) {
*aResult = null_t();
return IPC_OK();
}

View File

@ -162,11 +162,9 @@ class ShmemPool final {
bool AllocateShmem(T* aInstance, size_t aSize, ShmemBuffer& aRes,
AllocationPolicy aPolicy) {
return (aPolicy == AllocationPolicy::Default &&
aInstance->AllocShmem(aSize, ipc::SharedMemory::TYPE_BASIC,
&aRes.mShmem)) ||
aInstance->AllocShmem(aSize, &aRes.mShmem)) ||
(aPolicy == AllocationPolicy::Unsafe &&
aInstance->AllocUnsafeShmem(aSize, ipc::SharedMemory::TYPE_BASIC,
&aRes.mShmem));
aInstance->AllocUnsafeShmem(aSize, &aRes.mShmem));
}
const PoolType mPoolType;
Mutex mMutex MOZ_UNANNOTATED;

View File

@ -138,8 +138,7 @@ already_AddRefed<Buffer> Device::CreateBuffer(
const auto& size = checked.value();
// TODO: use `ShmemPool`?
if (!mBridge->AllocShmem(size, ipc::Shmem::SharedMemory::TYPE_BASIC,
&shmem)) {
if (!mBridge->AllocShmem(size, &shmem)) {
aRv.ThrowAbortError(
nsPrintfCString("Unable to allocate shmem of size %" PRIuPTR, size));
return nullptr;

View File

@ -71,8 +71,7 @@ void Queue::WriteBuffer(const Buffer& aBuffer, uint64_t aBufferOffset,
}
ipc::Shmem shmem;
if (!mBridge->AllocShmem(size, ipc::Shmem::SharedMemory::TYPE_BASIC,
&shmem)) {
if (!mBridge->AllocShmem(size, &shmem)) {
aRv.ThrowAbortError(
nsPrintfCString("Unable to allocate shmem of size %" PRIuPTR, size));
return;
@ -124,8 +123,7 @@ void Queue::WriteTexture(const dom::GPUImageCopyTexture& aDestination,
const auto size = checkedSize.value();
ipc::Shmem shmem;
if (!mBridge->AllocShmem(size, ipc::Shmem::SharedMemory::TYPE_BASIC,
&shmem)) {
if (!mBridge->AllocShmem(size, &shmem)) {
aRv.ThrowAbortError(
nsPrintfCString("Unable to allocate shmem of size %" PRIuPTR, size));
return;

View File

@ -717,7 +717,7 @@ ipc::IPCResult WebGPUParent::GetFrontBufferSnapshot(
aSize.width * BytesPerPixel(data->mTextureHost->GetFormat());
uint32_t len = data->mRowCount * stride;
Shmem shmem;
if (!AllocShmem(len, ipc::Shmem::SharedMemory::TYPE_BASIC, &shmem)) {
if (!AllocShmem(len, &shmem)) {
return IPC_OK();
}

View File

@ -1197,8 +1197,7 @@ struct IPDLParamTraits<gfx::PaintFragment> {
paramType&& aParam) {
Shmem shmem;
if (aParam.mSize.IsEmpty() ||
!aActor->AllocShmem(aParam.mRecording.mLen, SharedMemory::TYPE_BASIC,
&shmem)) {
!aActor->AllocShmem(aParam.mRecording.mLen, &shmem)) {
WriteParam(aWriter, gfx::IntSize(0, 0));
return;
}

View File

@ -130,7 +130,7 @@ BufferTextureData* BufferTextureData::CreateInternal(
return new MemoryTextureData(aDesc, aMoz2DBackend, buffer, aBufferSize);
} else {
ipc::Shmem shm;
if (!aAllocator->AllocUnsafeShmem(aBufferSize, OptimalShmemType(), &shm)) {
if (!aAllocator->AllocUnsafeShmem(aBufferSize, &shm)) {
return nullptr;
}
@ -491,7 +491,7 @@ ShmemTextureData* ShmemTextureData::Create(gfx::IntSize aSize,
}
mozilla::ipc::Shmem shm;
if (!aAllocator->AllocUnsafeShmem(bufSize, OptimalShmemType(), &shm)) {
if (!aAllocator->AllocUnsafeShmem(bufSize, &shm)) {
return nullptr;
}

View File

@ -577,18 +577,14 @@ void CompositorBridgeChild::EndCanvasTransaction() {
}
}
bool CompositorBridgeChild::AllocUnsafeShmem(
size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool CompositorBridgeChild::AllocUnsafeShmem(size_t aSize, ipc::Shmem* aShmem) {
ShmemAllocated(this);
return PCompositorBridgeChild::AllocUnsafeShmem(aSize, aType, aShmem);
return PCompositorBridgeChild::AllocUnsafeShmem(aSize, aShmem);
}
bool CompositorBridgeChild::AllocShmem(
size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool CompositorBridgeChild::AllocShmem(size_t aSize, ipc::Shmem* aShmem) {
ShmemAllocated(this);
return PCompositorBridgeChild::AllocShmem(aSize, aType, aShmem);
return PCompositorBridgeChild::AllocShmem(aSize, aShmem);
}
bool CompositorBridgeChild::DeallocShmem(ipc::Shmem& aShmem) {

View File

@ -152,12 +152,8 @@ class CompositorBridgeChild final : public PCompositorBridgeChild,
base::ProcessId GetParentPid() const override { return OtherPid(); }
bool AllocUnsafeShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override;
bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
bool AllocShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
PCompositorWidgetChild* AllocPCompositorWidgetChild(

View File

@ -149,16 +149,13 @@ void CompositorBridgeParentBase::SendAsyncMessage(
Unused << SendParentAsyncMessages(aMessage);
}
bool CompositorBridgeParentBase::AllocShmem(
size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
return PCompositorBridgeParent::AllocShmem(aSize, aType, aShmem);
bool CompositorBridgeParentBase::AllocShmem(size_t aSize, ipc::Shmem* aShmem) {
return PCompositorBridgeParent::AllocShmem(aSize, aShmem);
}
bool CompositorBridgeParentBase::AllocUnsafeShmem(
size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
return PCompositorBridgeParent::AllocUnsafeShmem(aSize, aType, aShmem);
bool CompositorBridgeParentBase::AllocUnsafeShmem(size_t aSize,
ipc::Shmem* aShmem) {
return PCompositorBridgeParent::AllocUnsafeShmem(aSize, aShmem);
}
bool CompositorBridgeParentBase::DeallocShmem(ipc::Shmem& aShmem) {
@ -2115,7 +2112,7 @@ Maybe<CollectedFramesParams> CompositorBridgeParent::WrapCollectedFrames(
}
Shmem shmem;
if (!AllocShmem(totalLength, SharedMemory::TYPE_BASIC, &shmem)) {
if (!AllocShmem(totalLength, &shmem)) {
return Nothing();
}

View File

@ -148,12 +148,8 @@ class CompositorBridgeParentBase : public PCompositorBridgeParent,
const nsTArray<AsyncParentMessageData>& aMessage) override;
// IShmemAllocator
bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aType,
mozilla::ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aType,
mozilla::ipc::Shmem* aShmem) override;
bool AllocShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
NS_IMETHOD_(MozExternalRefCountType) AddRef() override {

View File

@ -18,10 +18,6 @@ NS_IMPL_ISUPPORTS(GfxMemoryImageReporter, nsIMemoryReporter)
mozilla::Atomic<ptrdiff_t> GfxMemoryImageReporter::sAmount(0);
mozilla::ipc::SharedMemory::SharedMemoryType OptimalShmemType() {
return ipc::SharedMemory::SharedMemoryType::TYPE_BASIC;
}
void HostIPCAllocator::SendPendingAsyncMessages() {
if (mPendingAsyncMessage.empty()) {
return;
@ -102,8 +98,7 @@ bool FixedSizeSmallShmemSectionAllocator::AllocShmemSection(
if (!aShmemSection->shmem().IsWritable()) {
ipc::Shmem tmp;
if (!mShmProvider->AllocUnsafeShmem(sShmemPageSize, OptimalShmemType(),
&tmp)) {
if (!mShmProvider->AllocUnsafeShmem(sShmemPageSize, &tmp)) {
return false;
}

View File

@ -52,8 +52,6 @@ enum BufferCapabilities {
class SurfaceDescriptor;
mozilla::ipc::SharedMemory::SharedMemoryType OptimalShmemType();
/**
* An interface used to create and destroy surfaces that are shared with the
* Compositor process (using shmem, or other platform specific memory)

View File

@ -677,36 +677,31 @@ RefPtr<ImageClient> ImageBridgeChild::CreateImageClientNow(
return client;
}
bool ImageBridgeChild::AllocUnsafeShmem(
size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool ImageBridgeChild::AllocUnsafeShmem(size_t aSize, ipc::Shmem* aShmem) {
if (!InImageBridgeChildThread()) {
return DispatchAllocShmemInternal(aSize, aType, aShmem,
return DispatchAllocShmemInternal(aSize, aShmem,
true); // true: unsafe
}
if (!CanSend()) {
return false;
}
return PImageBridgeChild::AllocUnsafeShmem(aSize, aType, aShmem);
return PImageBridgeChild::AllocUnsafeShmem(aSize, aShmem);
}
bool ImageBridgeChild::AllocShmem(size_t aSize,
ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool ImageBridgeChild::AllocShmem(size_t aSize, ipc::Shmem* aShmem) {
if (!InImageBridgeChildThread()) {
return DispatchAllocShmemInternal(aSize, aType, aShmem,
return DispatchAllocShmemInternal(aSize, aShmem,
false); // false: unsafe
}
if (!CanSend()) {
return false;
}
return PImageBridgeChild::AllocShmem(aSize, aType, aShmem);
return PImageBridgeChild::AllocShmem(aSize, aShmem);
}
void ImageBridgeChild::ProxyAllocShmemNow(SynchronousTask* aTask, size_t aSize,
SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem, bool aUnsafe,
bool* aSuccess) {
AutoCompleteTask complete(aTask);
@ -717,22 +712,22 @@ void ImageBridgeChild::ProxyAllocShmemNow(SynchronousTask* aTask, size_t aSize,
bool ok = false;
if (aUnsafe) {
ok = AllocUnsafeShmem(aSize, aType, aShmem);
ok = AllocUnsafeShmem(aSize, aShmem);
} else {
ok = AllocShmem(aSize, aType, aShmem);
ok = AllocShmem(aSize, aShmem);
}
*aSuccess = ok;
}
bool ImageBridgeChild::DispatchAllocShmemInternal(
size_t aSize, SharedMemory::SharedMemoryType aType, ipc::Shmem* aShmem,
bool aUnsafe) {
bool ImageBridgeChild::DispatchAllocShmemInternal(size_t aSize,
ipc::Shmem* aShmem,
bool aUnsafe) {
SynchronousTask task("AllocatorProxy alloc");
bool success = false;
RefPtr<Runnable> runnable = WrapRunnable(
RefPtr<ImageBridgeChild>(this), &ImageBridgeChild::ProxyAllocShmemNow,
&task, aSize, aType, aShmem, aUnsafe, &success);
&task, aSize, aShmem, aUnsafe, &success);
GetThread()->Dispatch(runnable.forget());
task.Wait();

View File

@ -223,7 +223,6 @@ class ImageBridgeChild final : public PImageBridgeChild,
ImageContainer* aContainer);
void ProxyAllocShmemNow(SynchronousTask* aTask, size_t aSize,
SharedMemory::SharedMemoryType aType,
mozilla::ipc::Shmem* aShmem, bool aUnsafe,
bool* aSuccess);
void ProxyDeallocShmemNow(SynchronousTask* aTask, mozilla::ipc::Shmem* aShmem,
@ -288,12 +287,8 @@ class ImageBridgeChild final : public PImageBridgeChild,
* If used outside the ImageBridgeChild thread, it will proxy a synchronous
* call on the ImageBridgeChild thread.
*/
bool AllocUnsafeShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override;
bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
bool AllocShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
/**
* See ISurfaceAllocator.h
@ -321,9 +316,7 @@ class ImageBridgeChild final : public PImageBridgeChild,
protected:
explicit ImageBridgeChild(uint32_t aNamespace);
bool DispatchAllocShmemInternal(size_t aSize,
SharedMemory::SharedMemoryType aType,
Shmem* aShmem, bool aUnsafe);
bool DispatchAllocShmemInternal(size_t aSize, Shmem* aShmem, bool aUnsafe);
void Bind(Endpoint<PImageBridgeChild>&& aEndpoint);
void BindSameProcess(RefPtr<ImageBridgeParent> aParent);

View File

@ -381,22 +381,18 @@ already_AddRefed<ImageBridgeParent> ImageBridgeParent::GetInstance(
return bridge.forget();
}
bool ImageBridgeParent::AllocShmem(size_t aSize,
ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool ImageBridgeParent::AllocShmem(size_t aSize, ipc::Shmem* aShmem) {
if (mClosed) {
return false;
}
return PImageBridgeParent::AllocShmem(aSize, aType, aShmem);
return PImageBridgeParent::AllocShmem(aSize, aShmem);
}
bool ImageBridgeParent::AllocUnsafeShmem(
size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool ImageBridgeParent::AllocUnsafeShmem(size_t aSize, ipc::Shmem* aShmem) {
if (mClosed) {
return false;
}
return PImageBridgeParent::AllocUnsafeShmem(aSize, aType, aShmem);
return PImageBridgeParent::AllocUnsafeShmem(aSize, aShmem);
}
bool ImageBridgeParent::DeallocShmem(ipc::Shmem& aShmem) {

View File

@ -102,11 +102,9 @@ class ImageBridgeParent final : public PImageBridgeParent,
// IShmemAllocator
bool AllocShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
bool AllocShmem(size_t aSize, ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize, ipc::Shmem* aShmem) override;
bool DeallocShmem(ipc::Shmem& aShmem) override;

View File

@ -76,9 +76,8 @@ int32_t RefCountedShm::Release(const RefCountedShmem& aShm) {
bool RefCountedShm::Alloc(mozilla::ipc::IProtocol* aAllocator, size_t aSize,
RefCountedShmem& aShm) {
MOZ_ASSERT(!IsValid(aShm));
auto shmType = ipc::SharedMemory::SharedMemoryType::TYPE_BASIC;
auto size = aSize + SHM_REFCOUNT_HEADER_SIZE;
if (!aAllocator->AllocUnsafeShmem(size, shmType, &aShm.buffer())) {
if (!aAllocator->AllocUnsafeShmem(size, &aShm.buffer())) {
return false;
}
return true;

View File

@ -186,7 +186,7 @@ void UiCompositorControllerParent::ToolbarAnimatorMessageFromCompositor(
bool UiCompositorControllerParent::AllocPixelBuffer(const int32_t aSize,
ipc::Shmem* aMem) {
MOZ_ASSERT(aSize > 0);
return AllocShmem(aSize, ipc::SharedMemory::TYPE_BASIC, aMem);
return AllocShmem(aSize, aMem);
}
void UiCompositorControllerParent::NotifyLayersUpdated() {

View File

@ -57,30 +57,24 @@ VideoBridgeChild::~VideoBridgeChild() = default;
VideoBridgeChild* VideoBridgeChild::GetSingleton() { return sVideoBridge; }
bool VideoBridgeChild::AllocUnsafeShmem(
size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool VideoBridgeChild::AllocUnsafeShmem(size_t aSize, ipc::Shmem* aShmem) {
if (!mThread->IsOnCurrentThread()) {
return DispatchAllocShmemInternal(aSize, aType, aShmem,
true); // true: unsafe
return DispatchAllocShmemInternal(aSize, aShmem, true); // true: unsafe
}
if (!CanSend()) {
return false;
}
return PVideoBridgeChild::AllocUnsafeShmem(aSize, aType, aShmem);
return PVideoBridgeChild::AllocUnsafeShmem(aSize, aShmem);
}
bool VideoBridgeChild::AllocShmem(size_t aSize,
ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool VideoBridgeChild::AllocShmem(size_t aSize, ipc::Shmem* aShmem) {
MOZ_ASSERT(CanSend());
return PVideoBridgeChild::AllocShmem(aSize, aType, aShmem);
return PVideoBridgeChild::AllocShmem(aSize, aShmem);
}
void VideoBridgeChild::ProxyAllocShmemNow(SynchronousTask* aTask, size_t aSize,
SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem, bool aUnsafe,
bool* aSuccess) {
AutoCompleteTask complete(aTask);
@ -91,22 +85,22 @@ void VideoBridgeChild::ProxyAllocShmemNow(SynchronousTask* aTask, size_t aSize,
bool ok = false;
if (aUnsafe) {
ok = AllocUnsafeShmem(aSize, aType, aShmem);
ok = AllocUnsafeShmem(aSize, aShmem);
} else {
ok = AllocShmem(aSize, aType, aShmem);
ok = AllocShmem(aSize, aShmem);
}
*aSuccess = ok;
}
bool VideoBridgeChild::DispatchAllocShmemInternal(
size_t aSize, SharedMemory::SharedMemoryType aType, ipc::Shmem* aShmem,
bool aUnsafe) {
bool VideoBridgeChild::DispatchAllocShmemInternal(size_t aSize,
ipc::Shmem* aShmem,
bool aUnsafe) {
SynchronousTask task("AllocatorProxy alloc");
bool success = false;
RefPtr<Runnable> runnable = WrapRunnable(
RefPtr<VideoBridgeChild>(this), &VideoBridgeChild::ProxyAllocShmemNow,
&task, aSize, aType, aShmem, aUnsafe, &success);
&task, aSize, aShmem, aUnsafe, &success);
GetThread()->Dispatch(runnable.forget());
task.Wait();

View File

@ -39,12 +39,8 @@ class VideoBridgeChild final : public PVideoBridgeChild,
void ActorDealloc() override;
// ISurfaceAllocator
bool AllocUnsafeShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override;
bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
bool AllocShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
// TextureForwarder
@ -69,11 +65,9 @@ class VideoBridgeChild final : public PVideoBridgeChild,
protected:
void HandleFatalError(const char* aMsg) const override;
bool DispatchAllocShmemInternal(size_t aSize,
SharedMemory::SharedMemoryType aType,
mozilla::ipc::Shmem* aShmem, bool aUnsafe);
bool DispatchAllocShmemInternal(size_t aSize, mozilla::ipc::Shmem* aShmem,
bool aUnsafe);
void ProxyAllocShmemNow(SynchronousTask* aTask, size_t aSize,
SharedMemory::SharedMemoryType aType,
mozilla::ipc::Shmem* aShmem, bool aUnsafe,
bool* aSuccess);
void ProxyDeallocShmemNow(SynchronousTask* aTask, mozilla::ipc::Shmem* aShmem,

View File

@ -134,22 +134,18 @@ void VideoBridgeParent::SendAsyncMessage(
MOZ_ASSERT(false, "AsyncMessages not supported");
}
bool VideoBridgeParent::AllocShmem(size_t aSize,
ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool VideoBridgeParent::AllocShmem(size_t aSize, ipc::Shmem* aShmem) {
if (mClosed) {
return false;
}
return PVideoBridgeParent::AllocShmem(aSize, aType, aShmem);
return PVideoBridgeParent::AllocShmem(aSize, aShmem);
}
bool VideoBridgeParent::AllocUnsafeShmem(
size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) {
bool VideoBridgeParent::AllocUnsafeShmem(size_t aSize, ipc::Shmem* aShmem) {
if (mClosed) {
return false;
}
return PVideoBridgeParent::AllocUnsafeShmem(aSize, aType, aShmem);
return PVideoBridgeParent::AllocUnsafeShmem(aSize, aShmem);
}
bool VideoBridgeParent::DeallocShmem(ipc::Shmem& aShmem) {

View File

@ -53,11 +53,9 @@ class VideoBridgeParent final : public PVideoBridgeParent,
bool IPCOpen() const override { return !mClosed; }
// IShmemAllocator
bool AllocShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
bool AllocShmem(size_t aSize, ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize, ipc::Shmem* aShmem) override;
bool DeallocShmem(ipc::Shmem& aShmem) override;

View File

@ -127,8 +127,7 @@ bool ShmSegmentsWriter::AllocChunk() {
layers::OffsetRange ShmSegmentsWriter::AllocLargeChunk(size_t aSize) {
ipc::Shmem shm;
auto shmType = ipc::SharedMemory::SharedMemoryType::TYPE_BASIC;
if (!mShmAllocator->AllocShmem(aSize, shmType, &shm)) {
if (!mShmAllocator->AllocShmem(aSize, &shm)) {
gfxCriticalNote
<< "ShmSegmentsWriter failed to allocate large chunk of size " << aSize;
MOZ_ASSERT(false, "ShmSegmentsWriter fails to allocate large chunk");

View File

@ -52,11 +52,10 @@ class gfxBaseSharedMemorySurface : public Base {
* by this function.
*/
template <class ShmemAllocator>
static already_AddRefed<Sub> Create(
ShmemAllocator* aAllocator, const mozilla::gfx::IntSize& aSize,
gfxImageFormat aFormat,
SharedMemory::SharedMemoryType aShmType = SharedMemory::TYPE_BASIC) {
return Create<ShmemAllocator, false>(aAllocator, aSize, aFormat, aShmType);
static already_AddRefed<Sub> Create(ShmemAllocator* aAllocator,
const mozilla::gfx::IntSize& aSize,
gfxImageFormat aFormat) {
return Create<ShmemAllocator, false>(aAllocator, aSize, aFormat);
}
/**
@ -79,11 +78,10 @@ class gfxBaseSharedMemorySurface : public Base {
}
template <class ShmemAllocator>
static already_AddRefed<Sub> CreateUnsafe(
ShmemAllocator* aAllocator, const mozilla::gfx::IntSize& aSize,
gfxImageFormat aFormat,
SharedMemory::SharedMemoryType aShmType = SharedMemory::TYPE_BASIC) {
return Create<ShmemAllocator, true>(aAllocator, aSize, aFormat, aShmType);
static already_AddRefed<Sub> CreateUnsafe(ShmemAllocator* aAllocator,
const mozilla::gfx::IntSize& aSize,
gfxImageFormat aFormat) {
return Create<ShmemAllocator, true>(aAllocator, aSize, aFormat);
}
Shmem& GetShmem() { return mShmem; }
@ -136,17 +134,16 @@ class gfxBaseSharedMemorySurface : public Base {
template <class ShmemAllocator, bool Unsafe>
static already_AddRefed<Sub> Create(ShmemAllocator* aAllocator,
const mozilla::gfx::IntSize& aSize,
gfxImageFormat aFormat,
SharedMemory::SharedMemoryType aShmType) {
gfxImageFormat aFormat) {
if (!mozilla::gfx::Factory::CheckSurfaceSize(aSize)) return nullptr;
Shmem shmem;
long stride = gfxImageSurface::ComputeStride(aSize, aFormat);
size_t size = GetAlignedSize(aSize, stride);
if (!Unsafe) {
if (!aAllocator->AllocShmem(size, aShmType, &shmem)) return nullptr;
if (!aAllocator->AllocShmem(size, &shmem)) return nullptr;
} else {
if (!aAllocator->AllocUnsafeShmem(size, aShmType, &shmem)) return nullptr;
if (!aAllocator->AllocUnsafeShmem(size, &shmem)) return nullptr;
}
RefPtr<Sub> s = new Sub(aSize, stride, aFormat, shmem);

View File

@ -326,10 +326,9 @@ void IProtocol::Unregister(int32_t aId) {
return mToplevel->Unregister(aId);
}
Shmem::SharedMemory* IProtocol::CreateSharedMemory(
size_t aSize, SharedMemory::SharedMemoryType aType, bool aUnsafe,
int32_t* aId) {
return mToplevel->CreateSharedMemory(aSize, aType, aUnsafe, aId);
Shmem::SharedMemory* IProtocol::CreateSharedMemory(size_t aSize, bool aUnsafe,
int32_t* aId) {
return mToplevel->CreateSharedMemory(aSize, aUnsafe, aId);
}
Shmem::SharedMemory* IProtocol::LookupSharedMemory(int32_t aId) {
return mToplevel->LookupSharedMemory(aId);
@ -403,9 +402,7 @@ void IProtocol::HandleFatalError(const char* aErrorMsg) const {
mozilla::ipc::FatalError(aErrorMsg, mSide == ParentSide);
}
bool IProtocol::AllocShmem(size_t aSize,
Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aOutMem) {
bool IProtocol::AllocShmem(size_t aSize, Shmem* aOutMem) {
if (!CanSend()) {
NS_WARNING(
"Shmem not allocated. Cannot communicate with the other actor.");
@ -413,7 +410,7 @@ bool IProtocol::AllocShmem(size_t aSize,
}
Shmem::id_t id;
Shmem::SharedMemory* rawmem(CreateSharedMemory(aSize, aType, false, &id));
Shmem::SharedMemory* rawmem(CreateSharedMemory(aSize, false, &id));
if (!rawmem) {
return false;
}
@ -422,9 +419,7 @@ bool IProtocol::AllocShmem(size_t aSize,
return true;
}
bool IProtocol::AllocUnsafeShmem(size_t aSize,
Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aOutMem) {
bool IProtocol::AllocUnsafeShmem(size_t aSize, Shmem* aOutMem) {
if (!CanSend()) {
NS_WARNING(
"Shmem not allocated. Cannot communicate with the other actor.");
@ -432,7 +427,7 @@ bool IProtocol::AllocUnsafeShmem(size_t aSize,
}
Shmem::id_t id;
Shmem::SharedMemory* rawmem(CreateSharedMemory(aSize, aType, true, &id));
Shmem::SharedMemory* rawmem(CreateSharedMemory(aSize, true, &id));
if (!rawmem) {
return false;
}
@ -675,11 +670,11 @@ void IToplevelProtocol::Unregister(int32_t aId) {
mActorMap.Remove(aId);
}
Shmem::SharedMemory* IToplevelProtocol::CreateSharedMemory(
size_t aSize, Shmem::SharedMemory::SharedMemoryType aType, bool aUnsafe,
Shmem::id_t* aId) {
Shmem::SharedMemory* IToplevelProtocol::CreateSharedMemory(size_t aSize,
bool aUnsafe,
Shmem::id_t* aId) {
RefPtr<Shmem::SharedMemory> segment(
Shmem::Alloc(Shmem::PrivateIPDLCaller(), aSize, aType, aUnsafe));
Shmem::Alloc(Shmem::PrivateIPDLCaller(), aSize, aUnsafe));
if (!segment) {
return nullptr;
}

View File

@ -198,9 +198,8 @@ class IProtocol : public HasResultCodes {
IProtocol* Lookup(int32_t aId);
void Unregister(int32_t aId);
Shmem::SharedMemory* CreateSharedMemory(size_t aSize,
SharedMemory::SharedMemoryType aType,
bool aUnsafe, int32_t* aId);
Shmem::SharedMemory* CreateSharedMemory(size_t aSize, bool aUnsafe,
int32_t* aId);
Shmem::SharedMemory* LookupSharedMemory(int32_t aId);
bool IsTrackingSharedMemory(Shmem::SharedMemory* aSegment);
bool DestroySharedMemory(Shmem& aShmem);
@ -243,11 +242,8 @@ class IProtocol : public HasResultCodes {
UniquePtr<Message>& aReply) = 0;
virtual Result OnCallReceived(const Message& aMessage,
UniquePtr<Message>& aReply) = 0;
bool AllocShmem(size_t aSize, Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aOutMem);
bool AllocUnsafeShmem(size_t aSize,
Shmem::SharedMemory::SharedMemoryType aType,
Shmem* aOutMem);
bool AllocShmem(size_t aSize, Shmem* aOutMem);
bool AllocUnsafeShmem(size_t aSize, Shmem* aOutMem);
bool DeallocShmem(Shmem& aMem);
void FatalError(const char* const aErrorMsg) const;
@ -401,9 +397,8 @@ class IToplevelProtocol : public IProtocol {
IProtocol* Lookup(int32_t aId);
void Unregister(int32_t aId);
Shmem::SharedMemory* CreateSharedMemory(size_t aSize,
SharedMemory::SharedMemoryType aType,
bool aUnsafe, int32_t* aId);
Shmem::SharedMemory* CreateSharedMemory(size_t aSize, bool aUnsafe,
int32_t* aId);
Shmem::SharedMemory* LookupSharedMemory(int32_t aId);
bool IsTrackingSharedMemory(Shmem::SharedMemory* aSegment);
bool DestroySharedMemory(Shmem& aShmem);
@ -509,25 +504,19 @@ class IToplevelProtocol : public IProtocol {
class IShmemAllocator {
public:
virtual bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) = 0;
virtual bool AllocUnsafeShmem(
size_t aSize, mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) = 0;
virtual bool AllocShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) = 0;
virtual bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) = 0;
virtual bool DeallocShmem(mozilla::ipc::Shmem& aShmem) = 0;
};
#define FORWARD_SHMEM_ALLOCATOR_TO(aImplClass) \
virtual bool AllocShmem( \
size_t aSize, mozilla::ipc::SharedMemory::SharedMemoryType aShmType, \
mozilla::ipc::Shmem* aShmem) override { \
return aImplClass::AllocShmem(aSize, aShmType, aShmem); \
virtual bool AllocShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) \
override { \
return aImplClass::AllocShmem(aSize, aShmem); \
} \
virtual bool AllocUnsafeShmem( \
size_t aSize, mozilla::ipc::SharedMemory::SharedMemoryType aShmType, \
mozilla::ipc::Shmem* aShmem) override { \
return aImplClass::AllocUnsafeShmem(aSize, aShmType, aShmem); \
virtual bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) \
override { \
return aImplClass::AllocUnsafeShmem(aSize, aShmem); \
} \
virtual bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override { \
return aImplClass::DeallocShmem(aShmem); \

View File

@ -38,8 +38,6 @@ class SharedMemory {
}
public:
enum SharedMemoryType { TYPE_BASIC, TYPE_UNKNOWN };
enum OpenRights {
RightsReadOnly = RightsRead,
RightsReadWrite = RightsRead | RightsWrite,
@ -55,8 +53,6 @@ class SharedMemory {
virtual void CloseHandle() = 0;
virtual SharedMemoryType Type() const = 0;
virtual bool WriteHandle(IPC::MessageWriter* aWriter) = 0;
virtual bool ReadHandle(IPC::MessageReader* aReader) = 0;

View File

@ -45,8 +45,6 @@ class SharedMemoryBasic final
#endif
}
virtual SharedMemoryType Type() const override { return TYPE_BASIC; }
static Handle NULLHandle() { return Handle(); }
static void* FindFreeAddressSpace(size_t aSize);

View File

@ -63,8 +63,6 @@ class SharedMemoryBasic final
#endif
}
virtual SharedMemoryType Type() const override { return TYPE_BASIC; }
static Handle NULLHandle() { return base::SharedMemory::NULLHandle(); }
virtual bool IsHandleValid(const Handle& aHandle) const override {

View File

@ -51,8 +51,6 @@ class SharedMemoryBasic final
#endif
}
virtual SharedMemoryType Type() const override { return TYPE_BASIC; }
static Handle NULLHandle() { return Handle(); }
static void* FindFreeAddressSpace(size_t aSize);

View File

@ -20,8 +20,7 @@ class ShmemCreated : public IPC::Message {
typedef Shmem::id_t id_t;
public:
ShmemCreated(int32_t routingId, id_t aIPDLId, size_t aSize,
SharedMemory::SharedMemoryType aType)
ShmemCreated(int32_t routingId, id_t aIPDLId, size_t aSize)
: IPC::Message(routingId, SHMEM_CREATED_MESSAGE_TYPE, 0,
HeaderFlags(NESTED_INSIDE_CPOW)) {
MOZ_RELEASE_ASSERT(aSize < std::numeric_limits<uint32_t>::max(),
@ -29,14 +28,12 @@ class ShmemCreated : public IPC::Message {
IPC::MessageWriter writer(*this);
IPC::WriteParam(&writer, aIPDLId);
IPC::WriteParam(&writer, uint32_t(aSize));
IPC::WriteParam(&writer, int32_t(aType));
}
static bool ReadInfo(IPC::MessageReader* aReader, id_t* aIPDLId,
size_t* aSize, SharedMemory::SharedMemoryType* aType) {
size_t* aSize) {
uint32_t size = 0;
if (!IPC::ReadParam(aReader, aIPDLId) || !IPC::ReadParam(aReader, &size) ||
!IPC::ReadParam(aReader, reinterpret_cast<int32_t*>(aType))) {
if (!IPC::ReadParam(aReader, aIPDLId) || !IPC::ReadParam(aReader, &size)) {
return false;
}
*aSize = size;
@ -60,18 +57,11 @@ class ShmemDestroyed : public IPC::Message {
}
};
static SharedMemory* NewSegment(SharedMemory::SharedMemoryType aType) {
if (SharedMemory::TYPE_BASIC == aType) {
return new SharedMemoryBasic;
} else {
NS_ERROR("unknown Shmem type");
return nullptr;
}
}
static SharedMemory* NewSegment() { return new SharedMemoryBasic; }
static already_AddRefed<SharedMemory> CreateSegment(
SharedMemory::SharedMemoryType aType, size_t aNBytes, size_t aExtraSize) {
RefPtr<SharedMemory> segment = NewSegment(aType);
static already_AddRefed<SharedMemory> CreateSegment(size_t aNBytes,
size_t aExtraSize) {
RefPtr<SharedMemory> segment = NewSegment();
if (!segment) {
return nullptr;
}
@ -89,12 +79,11 @@ static already_AddRefed<SharedMemory> ReadSegment(
NS_ERROR("expected 'shmem created' message");
return nullptr;
}
SharedMemory::SharedMemoryType type;
IPC::MessageReader reader(aDescriptor);
if (!ShmemCreated::ReadInfo(&reader, aId, aNBytes, &type)) {
if (!ShmemCreated::ReadInfo(&reader, aId, aNBytes)) {
return nullptr;
}
RefPtr<SharedMemory> segment = NewSegment(type);
RefPtr<SharedMemory> segment = NewSegment();
if (!segment) {
return nullptr;
}
@ -288,16 +277,14 @@ void Shmem::RevokeRights(PrivateIPDLCaller) {
// static
already_AddRefed<Shmem::SharedMemory> Shmem::Alloc(PrivateIPDLCaller,
size_t aNBytes,
SharedMemoryType aType,
bool aUnsafe,
size_t aNBytes, bool aUnsafe,
bool aProtect) {
NS_ASSERTION(aNBytes <= UINT32_MAX, "Will truncate shmem segment size!");
MOZ_ASSERT(!aProtect || !aUnsafe, "protect => !unsafe");
size_t pageSize = SharedMemory::SystemPageSize();
// |2*pageSize| is for the front and back sentinel
RefPtr<SharedMemory> segment = CreateSegment(aType, aNBytes, 2 * pageSize);
RefPtr<SharedMemory> segment = CreateSegment(aNBytes, 2 * pageSize);
if (!segment) {
return nullptr;
}
@ -388,11 +375,9 @@ Shmem::Shmem(PrivateIPDLCaller, SharedMemory* aSegment, id_t aId)
// static
already_AddRefed<Shmem::SharedMemory> Shmem::Alloc(PrivateIPDLCaller,
size_t aNBytes,
SharedMemoryType aType,
bool /*unused*/,
bool /*unused*/) {
RefPtr<SharedMemory> segment =
CreateSegment(aType, aNBytes, sizeof(uint32_t));
RefPtr<SharedMemory> segment = CreateSegment(aNBytes, sizeof(uint32_t));
if (!segment) {
return nullptr;
}
@ -432,7 +417,7 @@ UniquePtr<IPC::Message> Shmem::MkCreatedMessage(PrivateIPDLCaller,
int32_t routingId) {
AssertInvariants();
auto msg = MakeUnique<ShmemCreated>(routingId, mId, mSize, mSegment->Type());
auto msg = MakeUnique<ShmemCreated>(routingId, mId, mSize);
IPC::MessageWriter writer(*msg);
if (!mSegment->WriteHandle(&writer)) {
return nullptr;

View File

@ -74,7 +74,6 @@ class Shmem final {
typedef int32_t id_t;
// Low-level wrapper around platform shmem primitives.
typedef mozilla::ipc::SharedMemory SharedMemory;
typedef SharedMemory::SharedMemoryType SharedMemoryType;
// Shmem objects should only be constructed directly from SharedMemory
// objects by the Shmem implementation itself, or by a select few functions
// in ProtocolUtils.{h,cpp}. You should not need to add new instances of
@ -151,7 +150,6 @@ class Shmem final {
static already_AddRefed<Shmem::SharedMemory> Alloc(PrivateIPDLCaller,
size_t aNBytes,
SharedMemoryType aType,
bool aUnsafe,
bool aProtect = false);

View File

@ -13,10 +13,8 @@ void TestShmemParent::Main() {
Shmem unsafe;
size_t size = 12345;
if (!AllocShmem(size, SharedMemory::TYPE_BASIC, &mem))
fail("can't alloc shmem");
if (!AllocUnsafeShmem(size, SharedMemory::TYPE_BASIC, &unsafe))
fail("can't alloc shmem");
if (!AllocShmem(size, &mem)) fail("can't alloc shmem");
if (!AllocUnsafeShmem(size, &unsafe)) fail("can't alloc shmem");
if (mem.Size<char>() != size)
fail("shmem is wrong size: expected %lu, got %lu", size, mem.Size<char>());

View File

@ -73,8 +73,7 @@ void FuzzProtocol(T* aProtocol, const uint8_t* aData, size_t aSize,
break;
}
RefPtr<Shmem::SharedMemory> segment(
Shmem::Alloc(Shmem::PrivateIPDLCaller(), shmem_size,
SharedMemory::TYPE_BASIC, false));
Shmem::Alloc(Shmem::PrivateIPDLCaller(), shmem_size, false));
if (!segment) {
break;
}

View File

@ -376,9 +376,7 @@ void ProfilerChild::GatherProfileThreadFunction(
writer->ChunkedWriteFunc().CopyDataIntoLazilyAllocatedBuffer(
[&](size_t allocationSize) -> char* {
if (parameters->profilerChild->AllocShmem(
allocationSize,
mozilla::ipc::Shmem::SharedMemory::TYPE_BASIC,
&shmem)) {
allocationSize, &shmem)) {
return shmem.get<char>();
}
return nullptr;
@ -386,9 +384,7 @@ void ProfilerChild::GatherProfileThreadFunction(
writer = nullptr;
} else {
// No profile, send an empty string.
if (parameters->profilerChild->AllocShmem(
1, mozilla::ipc::Shmem::SharedMemory::TYPE_BASIC,
&shmem)) {
if (parameters->profilerChild->AllocShmem(1, &shmem)) {
shmem.get<char>()[0] = '\0';
}
}
@ -421,7 +417,7 @@ mozilla::ipc::IPCResult ProfilerChild::RecvGatherProfile(
if (!gatherProfileThread) {
// Failed to create and start worker thread, resolve with an empty profile.
mozilla::ipc::Shmem shmem;
if (AllocShmem(1, mozilla::ipc::Shmem::SharedMemory::TYPE_BASIC, &shmem)) {
if (AllocShmem(1, &shmem)) {
shmem.get<char>()[0] = '\0';
}
parameters->resolver(std::move(shmem));