Region.h

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 #ifndef __REGION__H__ 
00032 #define __REGION__H__
00033 #include "Serialization.h"
00034 #include "symutil.h"
00035 #include "Annotatable.h"
00036 
00037 namespace Dyninst{
00038 namespace SymtabAPI{
00039 
00040 class Symbol;
00041 class relocationEntry;
00042 class Symtab;
00043 
00044 
00045 class Region : public AnnotatableSparse {
00046    friend class Object;
00047    friend class Symtab;
00048    friend class SymtabTranslatorBase;
00049    friend class SymtabTranslatorBin;
00050 
00051    public:  
00052 
00053    enum perm_t
00054    {
00055       RP_R, 
00056       RP_RW, 
00057       RP_RX,
00058       RP_RWX
00059    };
00060 
00061    static const char *permissions2Str(perm_t);
00062 
00063    enum RegionType 
00064    {
00065       RT_TEXT,
00066       RT_DATA,
00067       RT_TEXTDATA,
00068       RT_SYMTAB,
00069       RT_STRTAB,
00070       RT_BSS,
00071       RT_SYMVERSIONS,
00072       RT_SYMVERDEF,
00073       RT_SYMVERNEEDED,
00074       RT_REL,
00075       RT_RELA,
00076       RT_PLTREL,
00077       RT_PLTRELA,
00078       RT_DYNAMIC,
00079       RT_HASH,
00080       RT_GNU_HASH,
00081       RT_OTHER,
00082       RT_INVALID = -1
00083    };
00084 
00085    static const char *regionType2Str(RegionType);
00086 
00087    SYMTAB_EXPORT Region();
00088    SYMTAB_EXPORT static Region *createRegion(Offset diskOff, perm_t perms, RegionType regType,
00089                 unsigned long diskSize = 0, Offset memOff = 0, unsigned long memSize = 0,
00090                 std::string name = "", char *rawDataPtr = NULL, bool isLoadable = false,
00091                 bool isTLS = false, unsigned long memAlign = sizeof(unsigned));
00092    SYMTAB_EXPORT Region(const Region &reg);
00093    SYMTAB_EXPORT Region& operator=(const Region &reg);
00094    SYMTAB_EXPORT std::ostream& operator<< (std::ostream &os);
00095    SYMTAB_EXPORT bool operator== (const Region &reg);
00096 
00097    SYMTAB_EXPORT ~Region();
00098 
00099    SYMTAB_EXPORT unsigned getRegionNumber() const;
00100    SYMTAB_EXPORT bool setRegionNumber(unsigned regnumber);
00101    SYMTAB_EXPORT std::string getRegionName() const;
00102 
00103    SYMTAB_EXPORT Offset getDiskOffset() const;
00104    SYMTAB_EXPORT unsigned long getDiskSize() const;
00105    SYMTAB_EXPORT unsigned long getFileOffset();
00106 
00107    SYMTAB_EXPORT Offset getMemOffset() const;
00108    SYMTAB_EXPORT unsigned long getMemSize() const;
00109    SYMTAB_EXPORT unsigned long getMemAlignment() const;
00110    SYMTAB_EXPORT void setMemOffset(Offset);
00111    SYMTAB_EXPORT void setMemSize(unsigned long);
00112    SYMTAB_EXPORT void setDiskSize(unsigned long);
00113    SYMTAB_EXPORT void setFileOffset(Offset);
00114 
00115    SYMTAB_EXPORT void *getPtrToRawData() const;
00116    SYMTAB_EXPORT bool setPtrToRawData(void *, unsigned long);//also sets diskSize
00117 
00118    SYMTAB_EXPORT bool isBSS() const;
00119    SYMTAB_EXPORT bool isText() const;
00120    SYMTAB_EXPORT bool isData() const;
00121    SYMTAB_EXPORT bool isTLS() const;
00122    SYMTAB_EXPORT bool isOffsetInRegion(const Offset &offset) const;
00123    SYMTAB_EXPORT bool isLoadable() const;
00124    SYMTAB_EXPORT bool setLoadable(bool isLoadable);
00125    SYMTAB_EXPORT bool isDirty() const;
00126    SYMTAB_EXPORT std::vector<relocationEntry> &getRelocations();
00127    SYMTAB_EXPORT bool patchData(Offset off, void *buf, unsigned size);
00128    SYMTAB_EXPORT bool isStandardCode();
00129 
00130    SYMTAB_EXPORT perm_t getRegionPermissions() const;
00131    SYMTAB_EXPORT bool setRegionPermissions(perm_t newPerms);
00132    SYMTAB_EXPORT RegionType getRegionType() const;
00133 
00134    SYMTAB_EXPORT bool addRelocationEntry(Offset relocationAddr, Symbol *dynref, unsigned long relType, Region::RegionType rtype = Region::RT_REL);
00135    SYMTAB_EXPORT bool addRelocationEntry(const relocationEntry& rel);
00136 
00137    SYMTAB_EXPORT bool updateRelocations(Address start, Address end, Symbol *oldsym, Symbol *newsym);
00138 
00139    SYMTAB_EXPORT Serializable * serialize_impl(SerializerBase *sb, 
00140            const char *tag = "Region") THROW_SPEC (SerializerError);
00141 
00142    SYMTAB_EXPORT Symtab *symtab() const { return symtab_; }
00143    protected:                     
00144    SYMTAB_EXPORT Region(unsigned regnum, std::string name, Offset diskOff,
00145             unsigned long diskSize, Offset memOff, unsigned long memSize,
00146             char *rawDataPtr, perm_t perms, RegionType regType, bool isLoadable = false,
00147             bool isTLS = false, unsigned long memAlign = sizeof(unsigned));
00148    void setSymtab(Symtab *sym) { symtab_ = sym; }
00149    private:
00150    unsigned regNum_;
00151    std::string name_;
00152    Offset diskOff_;
00153    unsigned long diskSize_;
00154    Offset memOff_;
00155    unsigned long memSize_;
00156    Offset fileOff_;
00157    void *rawDataPtr_;
00158    perm_t permissions_;
00159    RegionType rType_;
00160    bool isDirty_;
00161    std::vector<relocationEntry> rels_;
00162    char *buffer_;  //To hold dirty data
00163    bool isLoadable_;
00164    bool isTLS_;
00165    unsigned long memAlign_;
00166    Symtab *symtab_;
00167 };
00168 
00169 }//namespace SymtabAPI
00170 
00171 }//namespace Dyninst
00172 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1