2010-09-10 21:45:59 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-09-10 21:45:59 +00:00
|
|
|
|
|
|
|
#ifndef mozilla_ipc_SharedMemoryBasic_chromium_h
|
|
|
|
#define mozilla_ipc_SharedMemoryBasic_chromium_h
|
|
|
|
|
|
|
|
#include "base/shared_memory.h"
|
|
|
|
#include "SharedMemory.h"
|
|
|
|
|
|
|
|
#include "nsDebug.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// This is a low-level wrapper around platform shared memory. Don't
|
|
|
|
// use it directly; use Shmem allocated through IPDL interfaces.
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class SharedMemoryBasic final : public SharedMemory
|
2010-09-10 21:45:59 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef base::SharedMemoryHandle Handle;
|
|
|
|
|
2010-11-05 07:17:07 +00:00
|
|
|
SharedMemoryBasic()
|
2010-09-10 21:45:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-08 01:18:59 +00:00
|
|
|
explicit SharedMemoryBasic(const Handle& aHandle)
|
2010-11-05 07:17:07 +00:00
|
|
|
: mSharedMemory(aHandle, false)
|
2010-09-10 21:45:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool Create(size_t aNbytes) override
|
2010-09-10 21:45:59 +00:00
|
|
|
{
|
2010-11-05 07:17:07 +00:00
|
|
|
bool ok = mSharedMemory.Create("", false, false, aNbytes);
|
|
|
|
if (ok) {
|
2010-11-05 07:17:07 +00:00
|
|
|
Created(aNbytes);
|
2010-11-05 07:17:07 +00:00
|
|
|
}
|
|
|
|
return ok;
|
2010-09-10 21:45:59 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool Map(size_t nBytes) override
|
2010-09-10 21:45:59 +00:00
|
|
|
{
|
|
|
|
bool ok = mSharedMemory.Map(nBytes);
|
2010-11-05 07:17:07 +00:00
|
|
|
if (ok) {
|
|
|
|
Mapped(nBytes);
|
|
|
|
}
|
2010-09-10 21:45:59 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void* memory() const override
|
2010-09-10 21:45:59 +00:00
|
|
|
{
|
|
|
|
return mSharedMemory.memory();
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual SharedMemoryType Type() const override
|
2010-09-10 21:45:59 +00:00
|
|
|
{
|
|
|
|
return TYPE_BASIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Handle NULLHandle()
|
|
|
|
{
|
|
|
|
return base::SharedMemory::NULLHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsHandleValid(const Handle &aHandle)
|
|
|
|
{
|
|
|
|
return base::SharedMemory::IsHandleValid(aHandle);
|
|
|
|
}
|
|
|
|
|
2015-04-01 08:40:35 +00:00
|
|
|
bool ShareToProcess(base::ProcessId aProcessId,
|
2010-09-10 21:45:59 +00:00
|
|
|
Handle* new_handle)
|
|
|
|
{
|
|
|
|
base::SharedMemoryHandle handle;
|
2015-04-01 08:40:35 +00:00
|
|
|
bool ret = mSharedMemory.ShareToProcess(aProcessId, &handle);
|
2010-09-10 21:45:59 +00:00
|
|
|
if (ret)
|
|
|
|
*new_handle = handle;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-07-28 16:56:54 +00:00
|
|
|
~SharedMemoryBasic()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-10 21:45:59 +00:00
|
|
|
base::SharedMemory mSharedMemory;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
|
|
|
|
#endif // ifndef mozilla_ipc_SharedMemoryBasic_chromium_h
|