LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

llvm::sys::MappedFile Class Reference

An abstraction for memory mapped files. More...

#include <MappedFile.h>

Collaboration diagram for llvm::sys::MappedFile:

Collaboration graph
[legend]
List of all members.

Public Types

Types
enum  MappingOptions { READ_ACCESS = 0x0001, WRITE_ACCESS = 0x0002, EXEC_ACCESS = 0x0004, SHARED_MAPPING = 0x0008 }

Public Member Functions

Constructors
 MappedFile (const Path &path, int options=READ_ACCESS)
 ~MappedFile ()
Accessors
bool isMapped () const
 Determine if a MappedFile is currently mapped
Exceptions:
nothing. 

void * base () const
 Obtain the base pointer to the memory mapped file.
Exceptions:
nothing. 

char * charBase () const
 Obtain the base pointer to the memory mapped file.
Exceptions:
nothing. 

const sys::Pathpath () const
 Returns the mapped file's path as a sys::Path
Exceptions:
nothing. 

size_t size ()
Mutators
void unmap ()
 Remove the file mapping from memory.
void * map ()
 Map the file into memory.
void size (size_t new_size)
 Set the size of the file and memory mapping.
void close ()

Detailed Description

An abstraction for memory mapped files.

This class provides an abstraction for a memory mapped file in the operating system's filesystem. It provides platform independent operations for mapping a file into memory for both read and write access. This class does not provide facilities for finding the file or operating on paths to files. The sys::Path class is used for that.

Since:
1.4

Definition at line 33 of file MappedFile.h.


Member Enumeration Documentation

enum llvm::sys::MappedFile::MappingOptions
 

Enumerator:
READ_ACCESS  Map the file for reading.
WRITE_ACCESS  Map the file for write access.
EXEC_ACCESS  Map the file for execution access.
SHARED_MAPPING  Map the file shared with other processes.

Definition at line 37 of file MappedFile.h.


Constructor & Destructor Documentation

llvm::sys::MappedFile::MappedFile const Path path,
int  options = READ_ACCESS
[inline]
 

Construct a MappedFile to the path in the operating system's file system with the mapping options provided.

Exceptions:
std::string if an error occurs

Definition at line 50 of file MappedFile.h.

llvm::sys::MappedFile::~MappedFile  )  [inline]
 

Destruct a MappedFile and release all memory associated with it.

Exceptions:
std::string if an error occurs

Definition at line 55 of file MappedFile.h.


Member Function Documentation

void* llvm::sys::MappedFile::base  )  const [inline]
 

Obtain the base pointer to the memory mapped file.

Exceptions:
nothing. 

This function returns a void* pointer to the base address of the file mapping. This is the memory address of the first byte in the file. Note that although a non-const pointer is returned, the memory might not actually be writable, depending on the MappingOptions used when the MappedFile was opened.

Returns:
The base pointer to the memory mapped file.

Definition at line 75 of file MappedFile.h.

char* llvm::sys::MappedFile::charBase  )  const [inline]
 

Obtain the base pointer to the memory mapped file.

Exceptions:
nothing. 

This function returns a char* pointer to the base address of the file mapping. This is the memory address of the first byte in the file. Note that although a non-const pointer is returned, the memory might not actually be writable, depending on the MappingOptions used when the MappedFile was opened.

Returns:
The base pointer to the memory mapped file as a char pointer.

Definition at line 85 of file MappedFile.h.

void llvm::sys::MappedFile::close  )  [inline]
 

Definition at line 124 of file MappedFile.h.

bool llvm::sys::MappedFile::isMapped  )  const [inline]
 

Determine if a MappedFile is currently mapped

Exceptions:
nothing. 

This function determines if the file is currently mapped or not.

Returns:
true iff the file is mapped into memory, false otherwise

Definition at line 65 of file MappedFile.h.

Referenced by map(), and unmap().

void * llvm::MappedFile::map  ) 
 

Map the file into memory.

The mapped file is put into memory.

Returns:
The base memory address of the mapped file.

Definition at line 78 of file Unix/MappedFile.cpp.

References EXEC_ACCESS, llvm::sys::Path::get(), llvm::GetPageSize(), isMapped(), SHARED_MAPPING, and ThrowErrno().

Referenced by llvm::Archive::Archive(), size(), llvm::Archive::writeMember(), and llvm::Archive::writeToDisk().

const sys::Path& llvm::sys::MappedFile::path  )  const [inline]
 

Returns the mapped file's path as a sys::Path

Exceptions:
nothing. 

This function returns a reference to the sys::Path object kept by the MappedFile object. This contains the path to the file that is or will be mapped.

Returns:
sys::Path containing the path name.

Definition at line 93 of file MappedFile.h.

void llvm::MappedFile::size size_t  new_size  ) 
 

Set the size of the file and memory mapping.

This method causes the size of the file, and consequently the size of the mapping to be set. This is logically the same as unmap(), adjust size of the file, map(). Consequently, when calling this function, the caller should not rely on previous results of the map(), base(), or baseChar() members as they may point to invalid areas of memory after this call.

Exceptions:
std::string if an error occurs

Definition at line 116 of file Unix/MappedFile.cpp.

References llvm::GetPageSize(), map(), and unmap().

size_t llvm::MappedFile::size  ) 
 

This function returns the number of bytes in the file.

Exceptions:
std::string if an error occurs

Definition at line 111 of file Unix/MappedFile.cpp.

Referenced by llvm::Archive::checkSignature(), llvm::Archive::findModuleDefiningSymbol(), llvm::Archive::findModulesDefiningSymbols(), llvm::Archive::loadArchive(), llvm::Archive::loadSymbolTable(), llvm::Archive::writeMember(), and llvm::Archive::writeToDisk().

void llvm::MappedFile::unmap  ) 
 

Remove the file mapping from memory.

The mapped file is removed from memory. If the file was mapped for write access, the memory contents will be automatically synchronized with the file's disk contents.

Definition at line 69 of file Unix/MappedFile.cpp.

References isMapped().

Referenced by size(), llvm::Archive::writeMember(), llvm::Archive::writeToDisk(), and llvm::Archive::~Archive().


The documentation for this class was generated from the following files: