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_chromium_h
8 #define mozilla_ipc_SharedMemoryBasic_chromium_h
10 #include "base/shared_memory.h"
11 #include "mozilla/ipc/SharedMemory.h"
14 # include "mozilla/ipc/SharedMemoryFuzzer.h"
20 // This is a low-level wrapper around platform shared memory. Don't
21 // use it directly; use Shmem allocated through IPDL interfaces.
27 class SharedMemoryBasic final
28 : public SharedMemoryCommon
<base::SharedMemoryHandle
> {
30 SharedMemoryBasic() = default;
32 virtual bool SetHandle(Handle aHandle
, OpenRights aRights
) override
{
33 return mSharedMemory
.SetHandle(std::move(aHandle
),
34 aRights
== RightsReadOnly
);
37 virtual bool Create(size_t aNbytes
) override
{
38 bool ok
= mSharedMemory
.Create(aNbytes
);
45 virtual bool Map(size_t nBytes
, void* fixed_address
= nullptr) override
{
46 bool ok
= mSharedMemory
.Map(nBytes
, fixed_address
);
53 virtual void Unmap() override
{ mSharedMemory
.Unmap(); }
55 virtual void CloseHandle() override
{ mSharedMemory
.Close(false); }
57 virtual void* memory() const override
{
59 return SharedMemoryFuzzer::MutateSharedMemory(mSharedMemory
.memory(),
62 return mSharedMemory
.memory();
66 static Handle
NULLHandle() { return base::SharedMemory::NULLHandle(); }
68 virtual bool IsHandleValid(const Handle
& aHandle
) const override
{
69 return base::SharedMemory::IsHandleValid(aHandle
);
72 virtual Handle
CloneHandle() override
{ return mSharedMemory
.CloneHandle(); }
74 static void* FindFreeAddressSpace(size_t size
) {
75 return base::SharedMemory::FindFreeAddressSpace(size
);
79 ~SharedMemoryBasic() = default;
81 base::SharedMemory mSharedMemory
;
85 } // namespace mozilla
87 #endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h