aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2012-08-15 19:05:47 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2012-08-15 19:05:47 +0000
commit1ebd25e438444ae80ec3d9504fe2173b8306501d (patch)
treef65c9ea701488f59ab30a7f9091f135ab135370f /include
parentb9d565ac998fc857b20786bae08bb30719eb966b (diff)
downloadexternal_llvm-1ebd25e438444ae80ec3d9504fe2173b8306501d.zip
external_llvm-1ebd25e438444ae80ec3d9504fe2173b8306501d.tar.gz
external_llvm-1ebd25e438444ae80ec3d9504fe2173b8306501d.tar.bz2
[PathV2] Add mapped_file_region. Implementation for Windows and POSIX.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161976 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Support/FileSystem.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h
index e0353f9..b287a91 100644
--- a/include/llvm/Support/FileSystem.h
+++ b/include/llvm/Support/FileSystem.h
@@ -28,6 +28,7 @@
#define LLVM_SUPPORT_FILE_SYSTEM_H
#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/DataTypes.h"
@@ -576,6 +577,82 @@ error_code FindLibrary(const Twine &short_name, SmallVectorImpl<char> &result);
error_code GetMainExecutable(const char *argv0, void *MainAddr,
SmallVectorImpl<char> &result);
+/// This class represents a memory mapped file. It is based on
+/// boost::iostreams::mapped_file.
+class mapped_file_region {
+ mapped_file_region() LLVM_DELETED_FUNCTION;
+ mapped_file_region(mapped_file_region&) LLVM_DELETED_FUNCTION;
+ mapped_file_region &operator =(mapped_file_region&) LLVM_DELETED_FUNCTION;
+
+public:
+ enum mapmode {
+ readonly, //< May only access map via const_data as read only.
+ readwrite, //< May access map via data and modify it. Written to path.
+ priv //< May modify via data, but changes are lost on destruction.
+ };
+
+private:
+ /// Platform specific mapping state.
+ mapmode Mode;
+ uint64_t Size;
+ void *Mapping;
+#if LLVM_ON_WIN32
+ int FileDescriptor;
+ void *FileHandle;
+ void *FileMappingHandle;
+#endif
+
+ error_code init(int FD, uint64_t Offset);
+
+public:
+ typedef char char_type;
+
+#ifdef LLVM_USE_RVALUE_REFERENCES
+ mapped_file_region(mapped_file_region&&);
+ mapped_file_region &operator =(mapped_file_region&&);
+#endif
+
+ /// Construct a mapped_file_region at \a path starting at \a offset of length
+ /// \a length and with access \a mode.
+ ///
+ /// \param path Path to the file to map. If it does not exist it will be
+ /// created.
+ /// \param mode How to map the memory.
+ /// \param length Number of bytes to map in starting at \a offset. If the file
+ /// is shorter than this, it will be extended. If \a length is
+ /// 0, the entire file will be mapped.
+ /// \param offset Byte offset from the beginning of the file where the map
+ /// should begin. Must be a multiple of
+ /// mapped_file_region::alignment().
+ /// \param ec This is set to errc::success if the map was constructed
+ /// sucessfully. Otherwise it is set to a platform dependent error.
+ mapped_file_region(const Twine &path,
+ mapmode mode,
+ uint64_t length,
+ uint64_t offset,
+ error_code &ec);
+
+ /// \param fd An open file descriptor to map. mapped_file_region takes
+ /// ownership. It must have been opended in the correct mode.
+ mapped_file_region(int fd,
+ mapmode mode,
+ uint64_t length,
+ uint64_t offset,
+ error_code &ec);
+
+ ~mapped_file_region();
+
+ mapmode flags() const;
+ uint64_t size() const;
+ char *data() const;
+
+ /// Get a const view of the data. Modifying this memory has undefined
+ /// behaivor.
+ const char *const_data() const;
+
+ /// \returns The minimum alignment offset must be.
+ static int alignment();
+};
/// @brief Memory maps the contents of a file
///