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

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

mercurial