ipc/glue/SharedMemoryBasic_android.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/glue/SharedMemoryBasic_android.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=8 et :
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#ifndef mozilla_ipc_SharedMemoryBasic_android_h
    1.12 +#define mozilla_ipc_SharedMemoryBasic_android_h
    1.13 +
    1.14 +#include "base/file_descriptor_posix.h"
    1.15 +
    1.16 +#include "SharedMemory.h"
    1.17 +
    1.18 +//
    1.19 +// This is a low-level wrapper around platform shared memory.  Don't
    1.20 +// use it directly; use Shmem allocated through IPDL interfaces.
    1.21 +//
    1.22 +
    1.23 +namespace mozilla {
    1.24 +namespace ipc {
    1.25 +
    1.26 +class SharedMemoryBasic : public SharedMemory
    1.27 +{
    1.28 +public:
    1.29 +  typedef base::FileDescriptor Handle;
    1.30 +
    1.31 +  SharedMemoryBasic();
    1.32 +
    1.33 +  SharedMemoryBasic(const Handle& aHandle);
    1.34 +
    1.35 +  virtual ~SharedMemoryBasic();
    1.36 +
    1.37 +  virtual bool Create(size_t aNbytes) MOZ_OVERRIDE;
    1.38 +
    1.39 +  virtual bool Map(size_t nBytes) MOZ_OVERRIDE;
    1.40 +
    1.41 +  virtual void* memory() const MOZ_OVERRIDE
    1.42 +  {
    1.43 +    return mMemory;
    1.44 +  }
    1.45 +
    1.46 +  virtual SharedMemoryType Type() const MOZ_OVERRIDE
    1.47 +  {
    1.48 +    return TYPE_BASIC;
    1.49 +  }
    1.50 +
    1.51 +  static Handle NULLHandle()
    1.52 +  {
    1.53 +    return Handle();
    1.54 +  }
    1.55 +
    1.56 +  static bool IsHandleValid(const Handle &aHandle)
    1.57 +  {
    1.58 +    return aHandle.fd >= 0;
    1.59 +  }
    1.60 +
    1.61 +  bool ShareToProcess(base::ProcessHandle aProcess,
    1.62 +                      Handle* aNewHandle);
    1.63 +
    1.64 +private:
    1.65 +  void Unmap();
    1.66 +  void Destroy();
    1.67 +
    1.68 +  // The /dev/ashmem fd we allocate.
    1.69 +  int mShmFd;
    1.70 +  // Pointer to mapped region, null if unmapped.
    1.71 +  void *mMemory;
    1.72 +};
    1.73 +
    1.74 +} // namespace ipc
    1.75 +} // namespace mozilla
    1.76 +
    1.77 +#endif // ifndef mozilla_ipc_SharedMemoryBasic_android_h

mercurial