Bug 1869092 - Fix timeouts in browser_PanelMultiView.js. r=twisniewski,test-only
[gecko.git] / ipc / glue / SharedMemoryBasic_chromium.h
blob8d65e7f1895e89b5bb1daa3811efc3ef0756ca20
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* memory() const override {
56 #ifdef FUZZING
57 return SharedMemoryFuzzer::MutateSharedMemory(mSharedMemory.memory(),
58 mAllocSize);
59 #else
60 return mSharedMemory.memory();
61 #endif
64 static Handle NULLHandle() { return base::SharedMemory::NULLHandle(); }
66 virtual bool IsHandleValid(const Handle& aHandle) const override {
67 return base::SharedMemory::IsHandleValid(aHandle);
70 virtual Handle CloneHandle() override { return mSharedMemory.CloneHandle(); }
72 virtual Handle TakeHandle() override {
73 return mSharedMemory.TakeHandle(false);
76 static void* FindFreeAddressSpace(size_t size) {
77 return base::SharedMemory::FindFreeAddressSpace(size);
80 private:
81 ~SharedMemoryBasic() = default;
83 base::SharedMemory mSharedMemory;
86 } // namespace ipc
87 } // namespace mozilla
89 #endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h