MemoryRegion.h revision affc150dc44fab1911775a49636d0ce85333b634
1//===- MemoryRegion.h -----------------------------------------------------===// 2// 3// The MCLinker Project 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#ifndef LD_MEMORY_REGION_H 10#define LD_MEMORY_REGION_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14 15#include <mcld/ADT/Uncopyable.h> 16#include <mcld/Support/FileSystem.h> 17#include <mcld/Support/MemoryArea.h> 18#include <mcld/Support/Space.h> 19 20namespace mcld 21{ 22 23/** \class MemoryRegion 24 * \brief MemoryRegion is a range of virtual memory which is mapped onto a 25 * range of files which is opened by MemoryArea. 26 * 27 * MemoryArea maps a file onto virtual memory. Clients can get a range of 28 * mapped memory space by requesting a MemoryRegion from MemoryArea, and 29 * read/write the mapped file through the MemoryRegion. 30 * 31 * When two different MemoryRegion may overlap memory space, race condition 32 * may occurs. Clients must call MemoryRegion::sync() explicit to tell the 33 * MemoryArea when to synchronize the virtual memory space with the mapped 34 * file. 35 */ 36class MemoryRegion : private Uncopyable 37{ 38friend class RegionFactory; 39friend class MemoryArea; 40 41public: 42 typedef Space::Address Address; 43 typedef Space::ConstAddress ConstAddress; 44 45private: 46 MemoryRegion(Space& pParent, const Address pVMAStart, size_t pSize); 47 48 Space* parent() 49 { return &m_Parent; } 50 51 const Space* parent() const 52 { return &m_Parent; } 53 54public: 55 ~MemoryRegion(); 56 57 Address start() 58 { return m_VMAStart; } 59 60 ConstAddress start() const 61 { return m_VMAStart; } 62 63 Address end() 64 { return m_VMAStart+m_Length; } 65 66 ConstAddress end() const 67 { return m_VMAStart+m_Length; } 68 69 size_t size() const 70 { return m_Length; } 71 72 Address getBuffer(size_t pOffset = 0) 73 { return m_VMAStart+pOffset; } 74 75 ConstAddress getBuffer(size_t pOffset = 0) const 76 { return m_VMAStart+pOffset; } 77 78private: 79 Space& m_Parent; 80 Address m_VMAStart; 81 size_t m_Length; 82}; 83 84} // namespace of mcld 85 86#endif 87 88