ipc/glue/SharedMemoryBasic_android.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=8 et :
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #ifndef mozilla_ipc_SharedMemoryBasic_android_h
michael@0 9 #define mozilla_ipc_SharedMemoryBasic_android_h
michael@0 10
michael@0 11 #include "base/file_descriptor_posix.h"
michael@0 12
michael@0 13 #include "SharedMemory.h"
michael@0 14
michael@0 15 //
michael@0 16 // This is a low-level wrapper around platform shared memory. Don't
michael@0 17 // use it directly; use Shmem allocated through IPDL interfaces.
michael@0 18 //
michael@0 19
michael@0 20 namespace mozilla {
michael@0 21 namespace ipc {
michael@0 22
michael@0 23 class SharedMemoryBasic : public SharedMemory
michael@0 24 {
michael@0 25 public:
michael@0 26 typedef base::FileDescriptor Handle;
michael@0 27
michael@0 28 SharedMemoryBasic();
michael@0 29
michael@0 30 SharedMemoryBasic(const Handle& aHandle);
michael@0 31
michael@0 32 virtual ~SharedMemoryBasic();
michael@0 33
michael@0 34 virtual bool Create(size_t aNbytes) MOZ_OVERRIDE;
michael@0 35
michael@0 36 virtual bool Map(size_t nBytes) MOZ_OVERRIDE;
michael@0 37
michael@0 38 virtual void* memory() const MOZ_OVERRIDE
michael@0 39 {
michael@0 40 return mMemory;
michael@0 41 }
michael@0 42
michael@0 43 virtual SharedMemoryType Type() const MOZ_OVERRIDE
michael@0 44 {
michael@0 45 return TYPE_BASIC;
michael@0 46 }
michael@0 47
michael@0 48 static Handle NULLHandle()
michael@0 49 {
michael@0 50 return Handle();
michael@0 51 }
michael@0 52
michael@0 53 static bool IsHandleValid(const Handle &aHandle)
michael@0 54 {
michael@0 55 return aHandle.fd >= 0;
michael@0 56 }
michael@0 57
michael@0 58 bool ShareToProcess(base::ProcessHandle aProcess,
michael@0 59 Handle* aNewHandle);
michael@0 60
michael@0 61 private:
michael@0 62 void Unmap();
michael@0 63 void Destroy();
michael@0 64
michael@0 65 // The /dev/ashmem fd we allocate.
michael@0 66 int mShmFd;
michael@0 67 // Pointer to mapped region, null if unmapped.
michael@0 68 void *mMemory;
michael@0 69 };
michael@0 70
michael@0 71 } // namespace ipc
michael@0 72 } // namespace mozilla
michael@0 73
michael@0 74 #endif // ifndef mozilla_ipc_SharedMemoryBasic_android_h

mercurial