/* -*- 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/. */
/* This source code was derived from Chromium code, and as such is also subject
* to the [Chromium license](ipc/chromium/src/LICENSE). */
// Rust Bindgen code doesn't actually use these types, but `UniqueFileHandle` // and `UniqueMachSendRight` aren't defined and some headers need to type check, // so we define a dummy type. #ifdefined(RUST_BINDGEN) using SharedMemoryHandle = void*; #elifdefined(XP_DARWIN) using SharedMemoryHandle = mozilla::UniqueMachSendRight; #else using SharedMemoryHandle = mozilla::UniqueFileHandle; #endif
class SharedMemory {
~SharedMemory();
/// # Provided methods public: using Handle = SharedMemoryHandle;
// 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)
/// Private methods which should be defined as part of each implementation. private: bool CreateImpl(size_t size, bool freezable);
Maybe<void*> MapImpl(size_t nBytes, void* fixedAddress); staticvoid UnmapImpl(size_t nBytes, void* address);
Maybe<Handle> ReadOnlyCopyImpl(); void ResetImpl();
/// Common members private: struct MappingDeleter {
size_t mMappedSize = 0; explicit MappingDeleter(size_t size) : mMappedSize(size) {}
MappingDeleter() = default; voidoperator()(void* ptr) {
MOZ_ASSERT(mMappedSize != 0);
UnmapImpl(mMappedSize, ptr); // Guard against multiple calls of the same deleter, which shouldn't // happen (but could, if `UniquePtr::reset` were used). Calling // `munmap` with an incorrect non-zero length would be bad.
mMappedSize = 0;
}
}; #ifndef RUST_BINDGEN using UniqueMapping = mozilla::UniquePtr<void, MappingDeleter>; #else using UniqueMapping = void*; #endif
// The held handle, if any.
Handle mHandle = NULLHandle(); // 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 // access to the alloc-size information.
size_t mAllocSize; // The memory mapping, if any.
UniqueMapping mMemory; // The size of the region mapped in Map(), if successful. All // SharedMemorys that are mapped have a non-zero mapped size.
size_t mMappedSize; // Whether the handle held is freezable. bool mFreezable = false; // Whether the handle held is read-only. bool mReadOnly = false; // Whether the handle held is external (set with `SetHandle`). bool mExternalHandle = false;
#if !defined(XP_DARWIN) && !defined(XP_WIN) /// # Unix/POSIX-specific methods and members. public: // If named POSIX shm is being used, append the prefix (including // the leading '/') that would be used by a process with the given // pid to the given string and return true. If not, return false. // (This is public so that the Linux sandboxing code can use it.) staticbool AppendPosixShmPrefix(std::string* str, pid_t pid);
// Similar, but simply returns whether POSIX shm is in use. staticbool UsingPosixShm();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.