Bug 1858509 add thread-safety annotations around MediaSourceDemuxer::mMonitor r=alwu
[gecko.git] / ipc / glue / SharedMemoryBasic_mach.h
blobd7ea9b2c39525209068d869866db49603d3752b8
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* memory() const override {
45 #ifdef FUZZING
46 return SharedMemoryFuzzer::MutateSharedMemory(mMemory, mAllocSize);
47 #else
48 return mMemory;
49 #endif
52 static Handle NULLHandle() { return Handle(); }
54 static void* FindFreeAddressSpace(size_t aSize);
56 virtual bool IsHandleValid(const Handle& aHandle) const override;
58 virtual Handle CloneHandle() override;
60 virtual Handle TakeHandle() 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