/work/obj-fuzz/dist/include/mozilla/AutoMemMap.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4; -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #ifndef loader_AutoMemMap_h |
7 | | #define loader_AutoMemMap_h |
8 | | |
9 | | #include "mozilla/FileUtils.h" |
10 | | #include "mozilla/MemoryReporting.h" |
11 | | #include "mozilla/RangedPtr.h" |
12 | | #include "mozilla/Result.h" |
13 | | #include "nsIMemoryReporter.h" |
14 | | |
15 | | #include <prio.h> |
16 | | |
17 | | class nsIFile; |
18 | | |
19 | | namespace mozilla { |
20 | | namespace ipc { |
21 | | class FileDescriptor; |
22 | | } |
23 | | |
24 | | namespace loader { |
25 | | |
26 | | using mozilla::ipc::FileDescriptor; |
27 | | |
28 | | class AutoMemMap |
29 | | { |
30 | | public: |
31 | 6 | AutoMemMap() = default; |
32 | | |
33 | | ~AutoMemMap(); |
34 | | |
35 | | Result<Ok, nsresult> |
36 | | init(nsIFile* file, int flags = PR_RDONLY, int mode = 0, |
37 | | PRFileMapProtect prot = PR_PROT_READONLY); |
38 | | |
39 | | Result<Ok, nsresult> |
40 | | init(const ipc::FileDescriptor& file, |
41 | | PRFileMapProtect prot = PR_PROT_READONLY, |
42 | | size_t expectedSize = 0); |
43 | | |
44 | | // Initializes the mapped memory with a shared memory handle. On |
45 | | // Unix-like systems, this is identical to the above init() method. On |
46 | | // Windows, the FileDescriptor must be a handle for a file mapping, |
47 | | // rather than a file descriptor. |
48 | | Result<Ok, nsresult> |
49 | | initWithHandle(const ipc::FileDescriptor& file, size_t size, |
50 | | PRFileMapProtect prot = PR_PROT_READONLY); |
51 | | |
52 | | void reset(); |
53 | | |
54 | | bool initialized() const { return addr; } |
55 | | |
56 | 0 | uint32_t size() const { return size_; } |
57 | | |
58 | | template<typename T = void> |
59 | | RangedPtr<T> get() |
60 | 0 | { |
61 | 0 | MOZ_ASSERT(addr); |
62 | 0 | return { static_cast<T*>(addr), size_ }; |
63 | 0 | } Unexecuted instantiation: mozilla::RangedPtr<mozilla::SharedPrefMap::Header> mozilla::loader::AutoMemMap::get<mozilla::SharedPrefMap::Header>() Unexecuted instantiation: mozilla::RangedPtr<unsigned char> mozilla::loader::AutoMemMap::get<unsigned char>() Unexecuted instantiation: mozilla::RangedPtr<mozilla::dom::ipc::SharedStringMap::Header> mozilla::loader::AutoMemMap::get<mozilla::dom::ipc::SharedStringMap::Header>() |
64 | | |
65 | | template<typename T = void> |
66 | | const RangedPtr<T> get() const |
67 | 0 | { |
68 | 0 | MOZ_ASSERT(addr); |
69 | 0 | return { static_cast<T*>(addr), size_ }; |
70 | 0 | } Unexecuted instantiation: mozilla::RangedPtr<unsigned char> const mozilla::loader::AutoMemMap::get<unsigned char>() const Unexecuted instantiation: mozilla::RangedPtr<mozilla::SharedPrefMap::Header> const mozilla::loader::AutoMemMap::get<mozilla::SharedPrefMap::Header>() const Unexecuted instantiation: mozilla::RangedPtr<mozilla::dom::ipc::SharedStringMap::Header> const mozilla::loader::AutoMemMap::get<mozilla::dom::ipc::SharedStringMap::Header>() const |
71 | | |
72 | | size_t nonHeapSizeOfExcludingThis() { return size_; } |
73 | | |
74 | | FileDescriptor cloneFileDescriptor() const; |
75 | | FileDescriptor cloneHandle() const; |
76 | | |
77 | | // Makes this mapping persistent. After calling this, the mapped memory |
78 | | // will remained mapped, even after this instance is destroyed. |
79 | 0 | void setPersistent() { persistent_ = true; } |
80 | | |
81 | | private: |
82 | | Result<Ok, nsresult> initInternal(PRFileMapProtect prot = PR_PROT_READONLY, |
83 | | size_t expectedSize = 0); |
84 | | |
85 | | AutoFDClose fd; |
86 | | PRFileMap* fileMap = nullptr; |
87 | | |
88 | | #ifdef XP_WIN |
89 | | // We can't include windows.h in this header, since it gets included |
90 | | // by some binding headers (which are explicitly incompatible with |
91 | | // windows.h). So we can't use the HANDLE type here. |
92 | | void* handle_ = nullptr; |
93 | | #endif |
94 | | |
95 | | uint32_t size_ = 0; |
96 | | void* addr = nullptr; |
97 | | |
98 | | bool persistent_ = 0; |
99 | | |
100 | | AutoMemMap(const AutoMemMap&) = delete; |
101 | | void operator=(const AutoMemMap&) = delete; |
102 | | }; |
103 | | |
104 | | } // namespace loader |
105 | | } // namespace mozilla |
106 | | |
107 | | #endif // loader_AutoMemMap_h |