IPC::Message* Shmem::ShareTo(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead, base::ProcessHandle aProcess, int32_t routingId) { AssertInvariants(); // kInvalidProcessHandle is used to indicate that it's the same process. if (aProcess == kInvalidProcessHandle) { aProcess = base::GetCurrentProcessHandle(); } if (SharedMemory::TYPE_BASIC == mSegment->Type()) { SharedMemoryBasic* seg = static_cast<SharedMemoryBasic*>(mSegment); SharedMemoryBasic::Handle handle; if (!seg->ShareToProcess(aProcess, &handle)) return nullptr; return new ShmemCreated(routingId, mId, mSize, handle); } #ifdef MOZ_HAVE_SHAREDMEMORYSYSV else if (SharedMemory::TYPE_SYSV == mSegment->Type()) { SharedMemorySysV* seg = static_cast<SharedMemorySysV*>(mSegment); return new ShmemCreated(routingId, mId, mSize, seg->GetHandle()); } #endif else { MOZ_ASSERT(false, "unknown shmem type (here?!)"); return nullptr; } return nullptr; }
void FibHeap::Push(Node *node) { node->mFirstChild = 0; node->mDegree = 0; node->mParent = 0; if(mHead) { node->mNextSibling = mHead; node->mPrevSibling = mHead->mPrevSibling; node->mNextSibling->mPrevSibling = node; node->mPrevSibling->mNextSibling = node; if(CompareLt(node,mHead)) mHead = node; } else { node->mNextSibling = node; node->mPrevSibling = node; mHead = node; } #ifdef ASSERT_HEAVILY AssertInvariants(); #endif }
FibHeap2::Node* FibHeap2::Peek() { #ifdef ASSERT_HEAVILY AssertInvariants(); #endif return mHead; }
IPC::Message* Shmem::ShareTo(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead, base::ProcessHandle aProcess, int32 routingId) { AssertInvariants(); if (SharedMemory::TYPE_BASIC == mSegment->Type()) { SharedMemoryBasic* seg = static_cast<SharedMemoryBasic*>(mSegment); SharedMemoryBasic::Handle handle; if (!seg->ShareToProcess(aProcess, &handle)) return 0; return new ShmemCreated(routingId, mId, mSize, handle); } #ifdef MOZ_HAVE_SHAREDMEMORYSYSV else if (SharedMemory::TYPE_SYSV == mSegment->Type()) { SharedMemorySysV* seg = static_cast<SharedMemorySysV*>(mSegment); return new ShmemCreated(routingId, mId, mSize, seg->GetHandle()); } #endif else { NS_RUNTIMEABORT("unknown shmem type (here?!)"); } return 0; }
IPC::Message* Shmem::UnshareFrom(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead, base::ProcessHandle aProcess, int32 routingId) { AssertInvariants(); return new ShmemDestroyed(routingId, mId); }
void FibHeap2::Push(Node *node) { node->mChildren.mFirst = nullptr; node->mDegree = 0; mRoots.Append(node); if(!mHead || CompareLt(node,mHead)) mHead = node; #ifdef ASSERT_HEAVILY AssertInvariants(); #endif }
void LinkedList::Remove(LLNode *node) { if(node == mHead) mHead = node->GetNext(); if(node == mTail) mTail = node->GetPrev(); node->RemoveFromList(); #ifdef ASSERT_HEAVILY AssertInvariants(); #endif }
void FibHeap::Pop() { assert(mHead); if(mHead->mNextSibling == mHead) { if(mHead->mFirstChild) { mHead = mHead->mFirstChild; mHead->mParent = 0; ConsolidateRoots(); } else { mHead = 0; } } else { if(mHead->mFirstChild) { Node *firstChild = mHead->mFirstChild; Node *lastChild = mHead->mFirstChild->mPrevSibling; firstChild->mPrevSibling = mHead->mPrevSibling; lastChild->mNextSibling = mHead->mNextSibling; firstChild->mPrevSibling->mNextSibling = firstChild; lastChild->mNextSibling->mPrevSibling = lastChild; mHead = firstChild; mHead->mParent = 0; ConsolidateRoots(); } else { mHead->mNextSibling->mPrevSibling = mHead->mPrevSibling; mHead->mPrevSibling->mNextSibling = mHead->mNextSibling; mHead = mHead->mNextSibling; ConsolidateRoots(); } } #ifdef ASSERT_HEAVILY AssertInvariants(); #endif }
void FibHeap2::Remove(Node *node) { if(node == mHead) { Pop(); } else { RemoveMergeChildren(node); } #ifdef ASSERT_HEAVILY AssertInvariants(); #endif }
IPC::Message* Shmem::ShareTo(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead, base::ProcessId aTargetPid, int32_t routingId) { AssertInvariants(); IPC::Message *msg = new ShmemCreated(routingId, mId, mSize, mSegment->Type()); if (!mSegment->ShareHandle(aTargetPid, msg)) { return nullptr; } // close the handle to the segment after it is shared mSegment->CloseHandle(); return msg; }
int 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!"); SharedMemorySysV* seg = static_cast<SharedMemorySysV*>(mSegment); return seg->GetHandle(); #else NS_RUNTIMEABORT("Can't call GetSysVID() with no support for SysV shared memory!"); return -1; // not reached #endif }
void LinkedList::Append(LLNode *node) { if(mTail) { mTail->InsertAfter(node); mTail = node; } else { mHead = mTail = node; } #ifdef ASSERT_HEAVILY AssertInvariants(); #endif }
void Shmem::RevokeRights(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead) { AssertInvariants(); size_t pageSize = SharedMemory::SystemPageSize(); Header* header = GetHeader(mSegment); // Open this up for reading temporarily mSegment->Protect(reinterpret_cast<char*>(header), pageSize, RightsRead); if (!header->mUnsafe) { Protect(mSegment); } else { mSegment->Protect(reinterpret_cast<char*>(header), pageSize, RightsNone); } }
void FibHeap2::Pop() { assert(mHead); RemoveMergeChildren(mHead); if(!mRoots.Empty()) { ConsolidateRoots(); } else { mHead = nullptr; } #ifdef ASSERT_HEAVILY AssertInvariants(); #endif }
void LinkedList::Splice(LinkedList &b) { if(b.mHead) { if(mTail) { mTail->InsertAfter(b.mHead); mTail = b.mTail; } else { mHead = b.mHead; mTail = b.mTail; } b.mHead = b.mTail = 0; } #ifdef ASSERT_HEAVILY AssertInvariants(); #endif }
void Shmem::RevokeRights(IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead) { AssertInvariants(); Protect(mSegment); }
void FibHeap::Remove(Node *node) { if(node == mHead) { Pop(); return; } // check whether this node is an only child if(node->mNextSibling == node) { // if parent == 0, and it's an only child, then it must be the fib heap's head, // but for that we've already tested. assert(node->mParent); if(node->mFirstChild) { node->mParent->mFirstChild = node->mFirstChild; node->mFirstChild->mParent = node->mParent; } else { node->mParent->mFirstChild = 0; node->mParent->mDegree = 0; } } else { if(node->mFirstChild) { Node *firstChild = node->mFirstChild; Node *lastChild = node->mFirstChild->mPrevSibling; firstChild->mPrevSibling = node->mPrevSibling; lastChild->mNextSibling = node->mNextSibling; firstChild->mPrevSibling->mNextSibling = firstChild; lastChild->mNextSibling->mPrevSibling = lastChild; if(node->mParent) { node->mParent->mFirstChild = firstChild; firstChild->mParent = node->mParent; } else { firstChild->mParent = 0; } } else { node->mNextSibling->mPrevSibling = node->mPrevSibling; node->mPrevSibling->mNextSibling = node->mNextSibling; if(node->mParent) { node->mNextSibling->mParent = node->mParent; node->mParent->mFirstChild = node->mNextSibling; } } } #ifdef ASSERT_HEAVILY AssertInvariants(); #endif }