|
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/. */ |
|
7 |
|
8 #ifndef mozilla_ipc_SharedMemoryBasic_android_h |
|
9 #define mozilla_ipc_SharedMemoryBasic_android_h |
|
10 |
|
11 #include "base/file_descriptor_posix.h" |
|
12 |
|
13 #include "SharedMemory.h" |
|
14 |
|
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 // |
|
19 |
|
20 namespace mozilla { |
|
21 namespace ipc { |
|
22 |
|
23 class SharedMemoryBasic : public SharedMemory |
|
24 { |
|
25 public: |
|
26 typedef base::FileDescriptor Handle; |
|
27 |
|
28 SharedMemoryBasic(); |
|
29 |
|
30 SharedMemoryBasic(const Handle& aHandle); |
|
31 |
|
32 virtual ~SharedMemoryBasic(); |
|
33 |
|
34 virtual bool Create(size_t aNbytes) MOZ_OVERRIDE; |
|
35 |
|
36 virtual bool Map(size_t nBytes) MOZ_OVERRIDE; |
|
37 |
|
38 virtual void* memory() const MOZ_OVERRIDE |
|
39 { |
|
40 return mMemory; |
|
41 } |
|
42 |
|
43 virtual SharedMemoryType Type() const MOZ_OVERRIDE |
|
44 { |
|
45 return TYPE_BASIC; |
|
46 } |
|
47 |
|
48 static Handle NULLHandle() |
|
49 { |
|
50 return Handle(); |
|
51 } |
|
52 |
|
53 static bool IsHandleValid(const Handle &aHandle) |
|
54 { |
|
55 return aHandle.fd >= 0; |
|
56 } |
|
57 |
|
58 bool ShareToProcess(base::ProcessHandle aProcess, |
|
59 Handle* aNewHandle); |
|
60 |
|
61 private: |
|
62 void Unmap(); |
|
63 void Destroy(); |
|
64 |
|
65 // The /dev/ashmem fd we allocate. |
|
66 int mShmFd; |
|
67 // Pointer to mapped region, null if unmapped. |
|
68 void *mMemory; |
|
69 }; |
|
70 |
|
71 } // namespace ipc |
|
72 } // namespace mozilla |
|
73 |
|
74 #endif // ifndef mozilla_ipc_SharedMemoryBasic_android_h |