2016-05-28 00:54:31 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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-11 01:45:59 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_ipc_SharedMemoryBasic_android_h
|
|
|
|
#define mozilla_ipc_SharedMemoryBasic_android_h
|
|
|
|
|
|
|
|
#include "base/file_descriptor_posix.h"
|
|
|
|
|
|
|
|
#include "SharedMemory.h"
|
|
|
|
|
2017-05-23 23:36:28 +03:00
|
|
|
#ifdef FUZZING
|
|
|
|
# include "SharedMemoryFuzzer.h"
|
|
|
|
#endif
|
|
|
|
|
2010-09-11 01:45:59 +04:00
|
|
|
//
|
|
|
|
// 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 {
|
|
|
|
|
2016-02-18 18:56:15 +03:00
|
|
|
class SharedMemoryBasic final
|
|
|
|
: public SharedMemoryCommon<base::FileDescriptor> {
|
2010-09-11 01:45:59 +04:00
|
|
|
public:
|
|
|
|
SharedMemoryBasic();
|
|
|
|
|
2017-04-18 19:24:58 +03:00
|
|
|
virtual bool SetHandle(const Handle& aHandle, OpenRights aRights) override;
|
2010-09-11 01:45:59 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool Create(size_t aNbytes) override;
|
2010-09-11 01:45:59 +04:00
|
|
|
|
2019-03-22 03:11:51 +03:00
|
|
|
virtual bool Map(size_t nBytes, void* fixed_address = nullptr) override;
|
2010-09-11 01:45:59 +04:00
|
|
|
|
2016-02-18 18:56:15 +03:00
|
|
|
virtual void CloseHandle() override;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void* memory() const override {
|
2017-05-23 23:36:28 +03:00
|
|
|
#ifdef FUZZING
|
|
|
|
return SharedMemoryFuzzer::MutateSharedMemory(mMemory, mAllocSize);
|
|
|
|
#else
|
2010-09-11 01:45:59 +04:00
|
|
|
return mMemory;
|
2017-05-23 23:36:28 +03:00
|
|
|
#endif
|
2010-09-11 01:45:59 +04:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual SharedMemoryType Type() const override { return TYPE_BASIC; }
|
2010-09-11 01:45:59 +04:00
|
|
|
|
|
|
|
static Handle NULLHandle() { return Handle(); }
|
|
|
|
|
2019-03-22 03:11:51 +03:00
|
|
|
static void* FindFreeAddressSpace(size_t aSize);
|
|
|
|
|
2016-02-18 18:56:15 +03:00
|
|
|
virtual bool IsHandleValid(const Handle& aHandle) const override {
|
2010-09-11 01:45:59 +04:00
|
|
|
return aHandle.fd >= 0;
|
|
|
|
}
|
|
|
|
|
2016-02-18 18:56:15 +03:00
|
|
|
virtual bool ShareToProcess(base::ProcessId aProcessId,
|
|
|
|
Handle* aNewHandle) override;
|
2010-09-11 01:45:59 +04:00
|
|
|
|
|
|
|
private:
|
2014-07-28 20:56:54 +04:00
|
|
|
~SharedMemoryBasic();
|
|
|
|
|
2010-09-11 01:45:59 +04:00
|
|
|
void Unmap();
|
|
|
|
|
|
|
|
// The /dev/ashmem fd we allocate.
|
|
|
|
int mShmFd;
|
|
|
|
// Pointer to mapped region, null if unmapped.
|
|
|
|
void* mMemory;
|
2017-04-18 19:24:58 +03:00
|
|
|
// Access rights to map an existing region with.
|
|
|
|
OpenRights mOpenRights;
|
2010-09-11 01:45:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // ifndef mozilla_ipc_SharedMemoryBasic_android_h
|