Bug 968823 - Make Shmem gracefully handle errors instead of just aborting - r=bent

This commit is contained in:
Benoit Jacob 2014-02-24 22:21:48 -05:00
parent 3ca81863e0
commit 72803b78cd

View File

@ -370,8 +370,10 @@ Shmem::Alloc(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
else if (aType == SharedMemory::TYPE_SYSV)
segment = CreateSegment(segmentSize, SharedMemorySysV::NULLHandle());
#endif
else
NS_RUNTIMEABORT("unknown shmem type");
else {
NS_ERROR("unknown shmem type");
return nullptr;
}
if (!segment)
return 0;
@ -406,8 +408,10 @@ Shmem::OpenExisting(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
id_t* aId,
bool aProtect)
{
if (SHMEM_CREATED_MESSAGE_TYPE != aDescriptor.type())
NS_RUNTIMEABORT("expected 'shmem created' message");
if (SHMEM_CREATED_MESSAGE_TYPE != aDescriptor.type()) {
NS_ERROR("expected 'shmem created' message");
return nullptr;
}
void* iter = 0;
SharedMemory::SharedMemoryType type;
@ -425,8 +429,10 @@ Shmem::OpenExisting(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
if (!ShmemCreated::ReadHandle(&aDescriptor, &iter, &handle))
return 0;
if (!SharedMemoryBasic::IsHandleValid(handle))
NS_RUNTIMEABORT("trying to open invalid handle");
if (!SharedMemoryBasic::IsHandleValid(handle)) {
NS_ERROR("trying to open invalid handle");
return nullptr;
}
segment = CreateSegment(segmentSize, handle);
}
#ifdef MOZ_HAVE_SHAREDMEMORYSYSV
@ -435,13 +441,16 @@ Shmem::OpenExisting(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
if (!ShmemCreated::ReadHandle(&aDescriptor, &iter, &handle))
return 0;
if (!SharedMemorySysV::IsHandleValid(handle))
NS_RUNTIMEABORT("trying to open invalid handle");
if (!SharedMemorySysV::IsHandleValid(handle)) {
NS_ERROR("trying to open invalid handle");
return nullptr;
}
segment = CreateSegment(segmentSize, handle);
}
#endif
else {
NS_RUNTIMEABORT("unknown shmem type");
NS_ERROR("unknown shmem type");
return nullptr;
}
if (!segment)
@ -500,9 +509,9 @@ Shmem::Alloc(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
segment = CreateSegment(SharedMemory::PageAlignedSize(aNBytes + sizeof(uint32_t)),
SharedMemorySysV::NULLHandle());
#endif
else
// Unhandled!!
NS_ABORT();
else {
return nullptr;
}
if (!segment)
return 0;
@ -519,8 +528,9 @@ Shmem::OpenExisting(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
id_t* aId,
bool /*unused*/)
{
if (SHMEM_CREATED_MESSAGE_TYPE != aDescriptor.type())
NS_RUNTIMEABORT("expected 'shmem created' message");
if (SHMEM_CREATED_MESSAGE_TYPE != aDescriptor.type()) {
return nullptr;
}
SharedMemory::SharedMemoryType type;
void* iter = 0;
@ -536,8 +546,9 @@ Shmem::OpenExisting(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
if (!ShmemCreated::ReadHandle(&aDescriptor, &iter, &handle))
return 0;
if (!SharedMemoryBasic::IsHandleValid(handle))
NS_RUNTIMEABORT("trying to open invalid handle");
if (!SharedMemoryBasic::IsHandleValid(handle)) {
return nullptr;
}
segment = CreateSegment(segmentSize, handle);
}
@ -547,21 +558,23 @@ Shmem::OpenExisting(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
if (!ShmemCreated::ReadHandle(&aDescriptor, &iter, &handle))
return 0;
if (!SharedMemorySysV::IsHandleValid(handle))
NS_RUNTIMEABORT("trying to open invalid handle");
if (!SharedMemorySysV::IsHandleValid(handle)) {
return nullptr;
}
segment = CreateSegment(segmentSize, handle);
}
#endif
else {
NS_RUNTIMEABORT("unknown shmem type");
return nullptr;
}
if (!segment)
return 0;
// this is the only validity check done OPT builds
if (size != static_cast<size_t>(*PtrToSize(segment)))
NS_RUNTIMEABORT("Alloc() segment size disagrees with OpenExisting()'s");
if (size != static_cast<size_t>(*PtrToSize(segment))) {
return nullptr;
}
return segment;
}
@ -582,13 +595,15 @@ Shmem::GetSysVID() const
#ifdef MOZ_HAVE_SHAREDMEMORYSYSV
AssertInvariants();
if (mSegment->Type() != SharedMemory::TYPE_SYSV)
NS_RUNTIMEABORT("Can't call GetSysVID() on a non-SysV Shmem!");
if (mSegment->Type() != SharedMemory::TYPE_SYSV) {
NS_ERROR("Can't call GetSysVID() on a non-SysV Shmem!");
return -1;
}
SharedMemorySysV* seg = static_cast<SharedMemorySysV*>(mSegment);
return seg->GetHandle();
#else
NS_RUNTIMEABORT("Can't call GetSysVID() with no support for SysV shared memory!");
NS_ERROR("Can't call GetSysVID() with no support for SysV shared memory!");
return -1; // not reached
#endif
}
@ -615,7 +630,8 @@ Shmem::ShareTo(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead,
}
#endif
else {
NS_RUNTIMEABORT("unknown shmem type (here?!)");
NS_ABORT_IF_FALSE(false, "unknown shmem type (here?!)");
return nullptr;
}
return 0;