LCOV - code coverage report
Current view: top level - ipc/glue - SharedMemoryBasic_chromium.h (source / functions) Hit Total Coverage
Test: output.info Lines: 35 35 100.0 %
Date: 2017-07-14 16:53:18 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       6             : 
       7             : #ifndef mozilla_ipc_SharedMemoryBasic_chromium_h
       8             : #define mozilla_ipc_SharedMemoryBasic_chromium_h
       9             : 
      10             : #include "base/shared_memory.h"
      11             : #include "SharedMemory.h"
      12             : 
      13             : #ifdef FUZZING
      14             : #include "SharedMemoryFuzzer.h"
      15             : #endif
      16             : 
      17             : #include "nsDebug.h"
      18             : 
      19             : //
      20             : // This is a low-level wrapper around platform shared memory.  Don't
      21             : // use it directly; use Shmem allocated through IPDL interfaces.
      22             : //
      23             : 
      24             : namespace mozilla {
      25             : namespace ipc {
      26             : 
      27             : class SharedMemoryBasic final : public SharedMemoryCommon<base::SharedMemoryHandle>
      28             : {
      29             : public:
      30          50 :   SharedMemoryBasic()
      31          50 :   {
      32          50 :   }
      33             : 
      34          37 :   virtual bool SetHandle(const Handle& aHandle, OpenRights aRights) override {
      35          37 :     return mSharedMemory.SetHandle(aHandle, aRights == RightsReadOnly);
      36             :   }
      37             : 
      38          13 :   virtual bool Create(size_t aNbytes) override
      39             :   {
      40          13 :     bool ok = mSharedMemory.Create("", false, false, aNbytes);
      41          13 :     if (ok) {
      42          13 :       Created(aNbytes);
      43             :     }
      44          13 :     return ok;
      45             :   }
      46             : 
      47          50 :   virtual bool Map(size_t nBytes) override
      48             :   {
      49          50 :     bool ok = mSharedMemory.Map(nBytes);
      50          50 :     if (ok) {
      51          50 :       Mapped(nBytes);
      52             :     }
      53          50 :     return ok;
      54             :   }
      55             : 
      56           5 :   virtual void CloseHandle() override
      57             :   {
      58           5 :     mSharedMemory.Close(false);
      59           5 :   }
      60             : 
      61          99 :   virtual void* memory() const override
      62             :   {
      63             : #ifdef FUZZING
      64             :     return SharedMemoryFuzzer::MutateSharedMemory(mSharedMemory.memory(),
      65             :                                                   mAllocSize);
      66             : #else
      67          99 :     return mSharedMemory.memory();
      68             : #endif
      69             :   }
      70             : 
      71           3 :   virtual SharedMemoryType Type() const override
      72             :   {
      73           3 :     return TYPE_BASIC;
      74             :   }
      75             : 
      76          35 :   static Handle NULLHandle()
      77             :   {
      78          35 :     return base::SharedMemory::NULLHandle();
      79             :   }
      80             : 
      81          37 :   virtual bool IsHandleValid(const Handle &aHandle) const override
      82             :   {
      83          37 :     return base::SharedMemory::IsHandleValid(aHandle);
      84             :   }
      85             : 
      86          38 :   virtual bool ShareToProcess(base::ProcessId aProcessId,
      87             :                               Handle* new_handle) override
      88             :   {
      89          38 :     base::SharedMemoryHandle handle;
      90          38 :     bool ret = mSharedMemory.ShareToProcess(aProcessId, &handle);
      91          38 :     if (ret)
      92          38 :       *new_handle = handle;
      93          38 :     return ret;
      94             :   }
      95             : 
      96             : private:
      97          74 :   ~SharedMemoryBasic()
      98          37 :   {
      99         111 :   }
     100             : 
     101             :   base::SharedMemory mSharedMemory;
     102             : };
     103             : 
     104             : } // namespace ipc
     105             : } // namespace mozilla
     106             : 
     107             : 
     108             : #endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h

Generated by: LCOV version 1.13