CMS 3D CMS Logo

FileMapping.h

Go to the documentation of this file.
00001 #ifndef CLASSLIB_FILE_MAPPING_H
00002 # define CLASSLIB_FILE_MAPPING_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "classlib/iobase/Storage.h"
00007 # include <list>
00008 
00009 namespace lat {
00010 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00011 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00012 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00013 
00014 class File;
00015 
00016 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00017 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00018 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00019 
00021 class FileMapping
00022 {
00023     // FIXME: tell page size -- limited to that!
00024     // FIXME: some systems allow to unmap multiple mappings in one go
00025     // (even with unmapped section in between), or unmap sections of a
00026     // file; other systems don't; which interface?
00027     // FIXME: mremap?
00028     // FIXME: fixed address?
00029 
00030 public:
00031     // Protection mode bits.
00032     static const int ProtExec      = 1;  //< Execute permission.
00033     static const int ProtRead      = 2;  //< Read permission.
00034     static const int ProtWrite     = 4;  //< Write permission.
00035     static const int ProtNone      = 8;  //< No permission.
00036 
00037     // Flag bits.
00038     static const int MapShared     = 1;  /*< Share the mapping with
00039                                              other processes.  Changes
00040                                              to the region will be
00041                                              written back to the file.  */
00042     static const int MapPrivate    = 2;  /*< Private copy-on-write
00043                                              mapping.  Changes to the
00044                                              region will not be
00045                                              written back to the but
00046                                              copied on write to the
00047                                              process' address space.  */
00048     static const int MapFixed      = 4;  /*< Map to a fixed address.  */
00049     static const int MapDenyWrite  = 8;  /*< Deny writes.  Mapping
00050                                              will fail if the file is
00051                                              open for writing.  */
00052     static const int MapExecutable = 16; /*< Map as an executable? */
00053 
00054     // FIXME: Do spawned processes inherit memory mappings?
00055     explicit
00056     FileMapping (File *file, IOSize maxSize = 0, int prot = ProtRead);
00057     explicit
00058     FileMapping (IOSize maxSize, int prot = ProtRead | ProtWrite);
00059     virtual ~FileMapping (void);
00060 
00061     // Mapping views.
00062     virtual IOBuffer    map (void);
00063     virtual IOBuffer    map (int prot, int flags);
00064     virtual IOBuffer    map (IOOffset offset, IOSize length,
00065                              int prot, int flags);
00066 
00067     // Unmapping views.
00068     virtual void        unmap (void *address);
00069     virtual void        unmap (void);
00070     virtual void        close (void);
00071 
00072     // Flushing views.
00073     virtual void        flush (void *address, IOSize length);
00074 
00075 private:
00076     struct View
00077     {
00078         void            *m_address;
00079         IOSize          m_bias;
00080         IOSize          m_size;
00081     };
00082 
00083     void                initialise (void);
00084     void *              create (IOOffset pos, IOSize length,
00085                                 int prot, int flags);
00086     void                sysunmap (View &view);
00087     void                sysclose (void);
00088 
00089     void                *m_handle;
00090     File                *m_file;
00091     IOSize              m_limit;
00092     int                 m_prot;
00093     std::list<View>     m_views;
00094 
00095     // undefined, no semantics
00096     FileMapping (const FileMapping &);
00097     FileMapping &operator= (const FileMapping &);
00098 };
00099 
00100 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00101 
00102 } // namespace lat
00103 #endif // CLASSLIB_FILE_MAPPING_H

Generated on Tue Jun 9 17:38:51 2009 for CMSSW by  doxygen 1.5.4