+ struct Options {
+ Options() {}
+
+ // Convenience methods; return *this for chaining.
+ Options& setPageSize(off_t v) { pageSize = v; return *this; }
+ Options& setShared(bool v) { shared = v; return *this; }
+ Options& setPrefault(bool v) { prefault = v; return *this; }
+ Options& setReadable(bool v) { readable = v; return *this; }
+ Options& setWritable(bool v) { writable = v; return *this; }
+ Options& setGrow(bool v) { grow = v; return *this; }
+
+ // Page size. 0 = use appropriate page size.
+ // (On Linux, we use a huge page size if the file is on a hugetlbfs
+ // file system, and the default page size otherwise)
+ off_t pageSize = 0;
+
+ // If shared (default), the memory mapping is shared with other processes
+ // mapping the same file (or children); if not shared (private), each
+ // process has its own mapping. Changes in writable, private mappings are
+ // not reflected to the underlying file. See the discussion of
+ // MAP_PRIVATE vs MAP_SHARED in the mmap(2) manual page.
+ bool shared = true;
+
+ // Populate page tables; subsequent accesses should not be blocked
+ // by page faults. This is a hint, as it may not be supported.
+ bool prefault = false;
+
+ // Map the pages readable. Note that mapping pages without read permissions
+ // is not universally supported (not supported on hugetlbfs on Linux, for
+ // example)
+ bool readable = true;
+
+ // Map the pages writable.
+ bool writable = false;
+
+ // When mapping a file in writable mode, grow the file to the requested
+ // length (using ftruncate()) before mapping; if false, truncate the
+ // mapping to the actual file size instead.
+ bool grow = false;
+
+ // Fix map at this address, if not nullptr. Must be aligned to a multiple
+ // of the appropriate page size.
+ void* address = nullptr;
+ };
+
+ // Options to emulate the old WritableMemoryMapping: readable and writable,
+ // allow growing the file if mapping past EOF.
+ static Options writable() {
+ return Options().setWritable(true).setGrow(true);
+ }
+
+ enum AnonymousType {
+ kAnonymous
+ };
+
+ /**
+ * Create an anonymous mapping.
+ */
+ MemoryMapping(AnonymousType, off_t length, Options options=Options());
+