1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "mozilla/RefCounted.h"
13 * Helper class to mmap plain files.
15 class Mappable
: public mozilla::RefCounted
<Mappable
> {
17 MOZ_DECLARE_REFCOUNTED_TYPENAME(Mappable
)
20 MemoryRange
mmap(const void* addr
, size_t length
, int prot
, int flags
,
24 void munmap(void* addr
, size_t length
) { ::munmap(addr
, length
); }
25 /* Limit use of Mappable::munmap to classes that keep track of the address
26 * and size of the mapping. This allows to ignore ::munmap return value. */
27 friend class Mappable1stPagePtr
;
28 friend class LibHandle
;
32 * Indicate to a Mappable instance that no further mmap is going to happen.
37 * Returns the maximum length that can be mapped from this Mappable for
40 size_t GetLength() const;
43 * Create a Mappable instance for the given file path.
45 static Mappable
* Create(const char* path
);
48 explicit Mappable(int fd
) : fd(fd
) {}
52 std::optional
<AutoCloseFD
> fd
;
55 #endif /* Mappable_h */