Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / ipc / glue / SharedMemoryBasic_mach.h
blobe487c99c84685c1cc97ce003797add4dea308354
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_SharedMemoryBasic_mach_h
8 #define mozilla_ipc_SharedMemoryBasic_mach_h
10 #include "base/process.h"
12 #include "mozilla/UniquePtrExtensions.h"
13 #include "mozilla/ipc/SharedMemory.h"
14 #include <mach/port.h>
16 #ifdef FUZZING
17 # include "mozilla/ipc/SharedMemoryFuzzer.h"
18 #endif
21 // This is a low-level wrapper around platform shared memory. Don't
22 // use it directly; use Shmem allocated through IPDL interfaces.
25 class MachPortSender;
26 class ReceivePort;
28 namespace mozilla {
29 namespace ipc {
31 class SharedMemoryBasic final
32 : public SharedMemoryCommon<mozilla::UniqueMachSendRight> {
33 public:
34 SharedMemoryBasic();
36 virtual bool SetHandle(Handle aHandle, OpenRights aRights) override;
38 virtual bool Create(size_t aNbytes) override;
40 virtual bool Map(size_t nBytes, void* fixed_address = nullptr) override;
42 virtual void Unmap() override;
44 virtual void CloseHandle() override;
46 virtual void* memory() const override {
47 #ifdef FUZZING
48 return SharedMemoryFuzzer::MutateSharedMemory(mMemory, mAllocSize);
49 #else
50 return mMemory;
51 #endif
54 static Handle NULLHandle() { return Handle(); }
56 static void* FindFreeAddressSpace(size_t aSize);
58 virtual bool IsHandleValid(const Handle& aHandle) const override;
60 virtual Handle CloneHandle() override;
62 private:
63 ~SharedMemoryBasic();
65 mozilla::UniqueMachSendRight mPort;
66 // Pointer to mapped region, null if unmapped.
67 void* mMemory;
68 // Access rights to map an existing region with.
69 OpenRights mOpenRights;
72 } // namespace ipc
73 } // namespace mozilla
75 #endif // ifndef mozilla_ipc_SharedMemoryBasic_mach_h