Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / ipc / glue / SharedMemoryPlatform.h
blob38daec5883cf98549f52c3fa4acc84eea1286815
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ipc_SharedMemoryPlatform_h
8 #define mozilla_ipc_SharedMemoryPlatform_h
10 #include "mozilla/ipc/SharedMemoryHandle.h"
11 #include "mozilla/ipc/SharedMemoryMapping.h"
12 #include "mozilla/Logging.h"
14 namespace mozilla::ipc::shared_memory {
16 /// The shared memory logger.
17 // The definition resides in `SharedMemoryHandle.cpp`.
18 extern LazyLogModule gSharedMemoryLog;
20 /**
21 * Functions that need to be implemented for each platform.
23 * These are static methods of a class to simplify access (the class can be
24 * made a friend to give access to platform implementations).
26 class Platform {
27 public:
28 /**
29 * Create a new shared memory handle.
31 * @param aHandle The handle to populate.
32 * @param aSize The size of the handle.
34 * @returns Whether the handle was successfully created.
36 static bool Create(Handle& aHandle, size_t aSize);
38 /**
39 * Create a new freezable shared memory handle.
41 * @param aHandle The handle to populate.
42 * @param aSize The size of the handle.
44 * @returns Whether the handle was successfully created.
46 static bool CreateFreezable(FreezableHandle& aHandle, size_t aSize);
48 /**
49 * Return whether a platform handle is safe to map.
51 * This is used when handles are read from IPC.
53 * @param aHandle The handle to check.
55 * @returns Whether the handle is safe to map.
57 static bool IsSafeToMap(const PlatformHandle& aHandle);
59 /**
60 * Clone a handle.
62 * @param aHandle The handle to clone.
64 * @returns The cloned handle, or nullptr if not successful.
66 static PlatformHandle CloneHandle(const PlatformHandle& aHandle);
68 /**
69 * Freeze a handle, returning the frozen handle.
71 * @param aHandle The handle to freeze.
73 * The inner `PlatformHandle mHandle` should be the frozen handle upon
74 * successful return. `mSize` must not change.
76 * @return Whether freezing the handle was successful.
78 static bool Freeze(FreezableHandle& aHandle);
80 /**
81 * Map the given handle with the size ane fixed address.
83 * @param aHandle The handle to map.
84 * @param aFixedAddress The address at which to map the memory, or nullptr to
85 * map anywhere.
86 * @param aReadOnly Whether the mapping should be read-only.
88 * @returns The location of the mapping.
90 static Maybe<void*> Map(const HandleBase& aHandle, void* aFixedAddress,
91 bool aReadOnly);
93 /**
94 * Unmap previously mapped memory.
96 * @param aMemory The memory location to unmap.
97 * @param aSize The size of the mapping.
99 static void Unmap(void* aMemory, size_t aSize);
102 * Protect the given memory region.
104 * @param aAddr The address at the beginning of the memory region.
105 * @param aSize The size of the region to protect.
106 * @param aAccess The access level to allow.
108 * @returns Whether protection was successful.
110 static bool Protect(char* aAddr, size_t aSize, Access aAccess);
113 * Find a region of free memory.
115 * @param aSize The size of the region to locate.
117 * @returns The start of the memory region, or nullptr on error.
119 static void* FindFreeAddressSpace(size_t aSize);
122 * Return the page size of the system.
124 static size_t PageSize();
127 } // namespace mozilla::ipc::shared_memory
129 #endif