michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_ipc_SharedMemoryBasic_android_h michael@0: #define mozilla_ipc_SharedMemoryBasic_android_h michael@0: michael@0: #include "base/file_descriptor_posix.h" michael@0: michael@0: #include "SharedMemory.h" michael@0: michael@0: // michael@0: // This is a low-level wrapper around platform shared memory. Don't michael@0: // use it directly; use Shmem allocated through IPDL interfaces. michael@0: // michael@0: michael@0: namespace mozilla { michael@0: namespace ipc { michael@0: michael@0: class SharedMemoryBasic : public SharedMemory michael@0: { michael@0: public: michael@0: typedef base::FileDescriptor Handle; michael@0: michael@0: SharedMemoryBasic(); michael@0: michael@0: SharedMemoryBasic(const Handle& aHandle); michael@0: michael@0: virtual ~SharedMemoryBasic(); michael@0: michael@0: virtual bool Create(size_t aNbytes) MOZ_OVERRIDE; michael@0: michael@0: virtual bool Map(size_t nBytes) MOZ_OVERRIDE; michael@0: michael@0: virtual void* memory() const MOZ_OVERRIDE michael@0: { michael@0: return mMemory; michael@0: } michael@0: michael@0: virtual SharedMemoryType Type() const MOZ_OVERRIDE michael@0: { michael@0: return TYPE_BASIC; michael@0: } michael@0: michael@0: static Handle NULLHandle() michael@0: { michael@0: return Handle(); michael@0: } michael@0: michael@0: static bool IsHandleValid(const Handle &aHandle) michael@0: { michael@0: return aHandle.fd >= 0; michael@0: } michael@0: michael@0: bool ShareToProcess(base::ProcessHandle aProcess, michael@0: Handle* aNewHandle); michael@0: michael@0: private: michael@0: void Unmap(); michael@0: void Destroy(); michael@0: michael@0: // The /dev/ashmem fd we allocate. michael@0: int mShmFd; michael@0: // Pointer to mapped region, null if unmapped. michael@0: void *mMemory; michael@0: }; michael@0: michael@0: } // namespace ipc michael@0: } // namespace mozilla michael@0: michael@0: #endif // ifndef mozilla_ipc_SharedMemoryBasic_android_h