Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / ipc / glue / SharedMemoryBasic_chromium.h
blobc48898c47da4488a3a99910f368b7dd3197de47e
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"
13 #ifdef FUZZING
14 # include "mozilla/ipc/SharedMemoryFuzzer.h"
15 #endif
17 #include "nsDebug.h"
20 // This is a low-level wrapper around platform shared memory. Don't
21 // use it directly; use Shmem allocated through IPDL interfaces.
24 namespace mozilla {
25 namespace ipc {
27 class SharedMemoryBasic final
28 : public SharedMemoryCommon<base::SharedMemoryHandle> {
29 public:
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);
39 if (ok) {
40 Created(aNbytes);
42 return ok;
45 virtual bool Map(size_t nBytes, void* fixed_address = nullptr) override {
46 bool ok = mSharedMemory.Map(nBytes, fixed_address);
47 if (ok) {
48 Mapped(nBytes);
50 return ok;
53 virtual void Unmap() override { mSharedMemory.Unmap(); }
55 virtual void CloseHandle() override { mSharedMemory.Close(false); }
57 virtual void* memory() const override {
58 #ifdef FUZZING
59 return SharedMemoryFuzzer::MutateSharedMemory(mSharedMemory.memory(),
60 mAllocSize);
61 #else
62 return mSharedMemory.memory();
63 #endif
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);
78 private:
79 ~SharedMemoryBasic() = default;
81 base::SharedMemory mSharedMemory;
84 } // namespace ipc
85 } // namespace mozilla
87 #endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h