15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- MemoryRegion.h -----------------------------------------------------===// 25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// The MCLinker Project 45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source 65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details. 75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===// 95460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#ifndef LD_MEMORY_REGION_H 105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#define LD_MEMORY_REGION_H 115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#ifdef ENABLE_UNITTEST 125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <gtest.h> 135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif 145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/ADT/Uncopyable.h> 165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/Support/FileSystem.h> 175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/Support/MemoryArea.h> 18affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <mcld/Support/Space.h> 195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace mcld 215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{ 225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** \class MemoryRegion 245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * \brief MemoryRegion is a range of virtual memory which is mapped onto a 255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * range of files which is opened by MemoryArea. 265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * 275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * MemoryArea maps a file onto virtual memory. Clients can get a range of 285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * mapped memory space by requesting a MemoryRegion from MemoryArea, and 295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * read/write the mapped file through the MemoryRegion. 305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * 315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * When two different MemoryRegion may overlap memory space, race condition 325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * may occurs. Clients must call MemoryRegion::sync() explicit to tell the 335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * MemoryArea when to synchronize the virtual memory space with the mapped 345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * file. 355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */ 365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass MemoryRegion : private Uncopyable 375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{ 385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaofriend class RegionFactory; 395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaofriend class MemoryArea; 405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic: 42affc150dc44fab1911775a49636d0ce85333b634Zonr Chang typedef Space::Address Address; 43affc150dc44fab1911775a49636d0ce85333b634Zonr Chang typedef Space::ConstAddress ConstAddress; 445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate: 46affc150dc44fab1911775a49636d0ce85333b634Zonr Chang MemoryRegion(Space& pParent, const Address pVMAStart, size_t pSize); 475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 48affc150dc44fab1911775a49636d0ce85333b634Zonr Chang Space* parent() 49affc150dc44fab1911775a49636d0ce85333b634Zonr Chang { return &m_Parent; } 505460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 51affc150dc44fab1911775a49636d0ce85333b634Zonr Chang const Space* parent() const 52affc150dc44fab1911775a49636d0ce85333b634Zonr Chang { return &m_Parent; } 535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 545460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic: 555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ~MemoryRegion(); 565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Address start() 585460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao { return m_VMAStart; } 595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 605460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ConstAddress start() const 615460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao { return m_VMAStart; } 625460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Address end() 645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao { return m_VMAStart+m_Length; } 655460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 665460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ConstAddress end() const 675460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao { return m_VMAStart+m_Length; } 685460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 695460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao size_t size() const 705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao { return m_Length; } 715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 72affc150dc44fab1911775a49636d0ce85333b634Zonr Chang Address getBuffer(size_t pOffset = 0) 735460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao { return m_VMAStart+pOffset; } 745460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 75affc150dc44fab1911775a49636d0ce85333b634Zonr Chang ConstAddress getBuffer(size_t pOffset = 0) const 765460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao { return m_VMAStart+pOffset; } 775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate: 79affc150dc44fab1911775a49636d0ce85333b634Zonr Chang Space& m_Parent; 805460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao Address m_VMAStart; 815460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao size_t m_Length; 825460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}; 835460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 845460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} // namespace of mcld 855460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 865460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif 875460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 88