Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/ipc/MemMapSnapshot.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* vim: set ts=8 sts=4 et sw=4 tw=99: */
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 dom_ipc_MemMapSnapshot_h
8
#define dom_ipc_MemMapSnapshot_h
9
10
#include "mozilla/AutoMemMap.h"
11
#include "mozilla/Attributes.h"
12
#include "mozilla/Maybe.h"
13
#include "mozilla/RangedPtr.h"
14
#include "mozilla/Result.h"
15
#ifdef XP_WIN
16
#  include "mozilla/ipc/FileDescriptor.h"
17
#endif
18
19
namespace mozilla {
20
namespace ipc {
21
22
/**
23
 * A helper class for creating a read-only snapshot of memory-mapped data.
24
 *
25
 * The Init() method initializes a read-write memory mapped region of the given
26
 * size, which can be initialized with arbitrary data. The Finalize() method
27
 * remaps that region as read-only (and backs it with a read-only file
28
 * descriptor), and initializes an AutoMemMap with the new contents.
29
 *
30
 * The file descriptor for the resulting AutoMemMap can be shared among
31
 * processes, to safely access a shared, read-only copy of the data snapshot.
32
 */
33
class MOZ_RAII MemMapSnapshot
34
{
35
public:
36
  Result<Ok, nsresult> Init(size_t aSize);
37
  Result<Ok, nsresult> Finalize(loader::AutoMemMap& aMap);
38
39
  template<typename T = void>
40
  RangedPtr<T> Get()
41
0
  {
42
0
    MOZ_ASSERT(mInitialized);
43
0
    return mMem.get<T>();
44
0
  }
Unexecuted instantiation: mozilla::RangedPtr<char> mozilla::ipc::MemMapSnapshot::Get<char>()
Unexecuted instantiation: mozilla::RangedPtr<mozilla::dom::ipc::SharedStringMap::Header> mozilla::ipc::MemMapSnapshot::Get<mozilla::dom::ipc::SharedStringMap::Header>()
45
46
private:
47
  Result<Ok, nsresult> Create(size_t aSize);
48
  Result<Ok, nsresult> Freeze(loader::AutoMemMap& aMem);
49
50
  loader::AutoMemMap mMem;
51
52
  bool mInitialized = false;
53
54
#ifdef XP_WIN
55
  Maybe<FileDescriptor> mFile;
56
#else
57
  nsCString mPath;
58
#endif
59
};
60
61
} // ipc
62
} // mozilla
63
64
#endif // dom_ipc_MemMapSnapshot_h