diff --git a/include/memory_space.h b/include/memory_space.h index 47c94dcb5d7b10d1b8ea7936ed29197f0bfa0911..c317624e6f7db4f6ffc4f56eeef7193fd8808213 100644 --- a/include/memory_space.h +++ b/include/memory_space.h @@ -34,43 +34,44 @@ namespace Zipr_SDK { + using namespace std; -typedef std::set<Range_t, Range_tCompare> RangeSet_t; + using RangeSet_t = set<Range_t, Range_tCompare> ; -// a memory space _is_ a map of range addres to char, with additional functionality. -class MemorySpace_t : public std::map<RangeAddress_t,char> -{ - public: + // a memory space _is_ a map of range addres to char, with additional functionality. + class MemorySpace_t : public map<RangeAddress_t,char> + { + public: - // range operatations - virtual void SplitFreeRange(RangeAddress_t addr)=0; - virtual void SplitFreeRange(Range_t range)=0; - virtual void MergeFreeRange(RangeAddress_t addr)=0; - virtual void MergeFreeRange(Range_t range)=0; - virtual RangeSet_t::iterator FindFreeRange(RangeAddress_t addr)=0; - virtual Range_t getFreeRange(int size)=0; - virtual Range_t getInfiniteFreeRange()=0; - virtual std::list<Range_t> getFreeRanges(size_t size = 0) = 0; - virtual std::pair<RangeSet_t::const_iterator,RangeSet_t::const_iterator> - getNearbyFreeRanges(const RangeAddress_t hint, size_t count = 0) = 0; - virtual void AddFreeRange(Range_t newRange)=0; - virtual void RemoveFreeRange(Range_t newRange)=0; - virtual Range_t GetLargeRange(void)=0; + // range operatations + virtual void SplitFreeRange(RangeAddress_t addr)=0; + virtual void SplitFreeRange(Range_t range)=0; + virtual void MergeFreeRange(RangeAddress_t addr)=0; + virtual void MergeFreeRange(Range_t range)=0; + virtual RangeSet_t::iterator FindFreeRange(RangeAddress_t addr)=0; + virtual Range_t getFreeRange(int size)=0; + virtual Range_t getInfiniteFreeRange()=0; + virtual list<Range_t> getFreeRanges(size_t size = 0) = 0; + virtual pair<RangeSet_t::const_iterator,RangeSet_t::const_iterator> + getNearbyFreeRanges(const RangeAddress_t hint, size_t count = 0) = 0; + virtual void AddFreeRange(Range_t newRange)=0; + virtual void RemoveFreeRange(Range_t newRange)=0; + virtual Range_t GetLargeRange(void)=0; - // queries about free areas. - virtual bool AreBytesFree(RangeAddress_t addr, int num_bytes)=0; - virtual bool IsByteFree(RangeAddress_t addr)=0; - virtual bool IsValidRange(RangeSet_t::iterator it)=0; - virtual int GetRangeCount()=0; - virtual void PrintMemorySpace(std::ostream &out)=0; + // queries about free areas. + virtual bool AreBytesFree(RangeAddress_t addr, int num_bytes)=0; + virtual bool IsByteFree(RangeAddress_t addr)=0; + virtual bool IsValidRange(RangeSet_t::iterator it)=0; + virtual int GetRangeCount()=0; + virtual void PrintMemorySpace(ostream &out)=0; - virtual void PlopBytes(RangeAddress_t addr, const char the_byte[], int num)=0; - virtual void PlopByte(RangeAddress_t addr, char the_byte)=0; - virtual void PlopJump(RangeAddress_t addr)=0; - virtual RangeAddress_t GetMinPlopped() const =0; - virtual RangeAddress_t GetMaxPlopped() const =0; + virtual void PlopBytes(RangeAddress_t addr, const char the_byte[], int num)=0; + virtual void PlopByte(RangeAddress_t addr, char the_byte)=0; + virtual void PlopJump(RangeAddress_t addr)=0; + virtual RangeAddress_t GetMinPlopped() const =0; + virtual RangeAddress_t GetMaxPlopped() const =0; -}; + }; } #endif diff --git a/include/range.h b/include/range.h index 93cd8e0c87d4c05c0a25c7d7d89697dc9f976f01..6ce0d319d69f24295b2a4e4a952fe551e4891010 100644 --- a/include/range.h +++ b/include/range.h @@ -35,46 +35,47 @@ namespace Zipr_SDK { -typedef uintptr_t RangeAddress_t; + using namespace std; + using RangeAddress_t = uintptr_t ; -class Range_t -{ - public: - Range_t(RangeAddress_t p_s, RangeAddress_t p_e) : m_start(p_s), m_end(p_e) { } - Range_t() : m_start(0), m_end(0) { } + class Range_t + { + public: + Range_t(RangeAddress_t p_s, RangeAddress_t p_e) : m_start(p_s), m_end(p_e) { } + Range_t() : m_start(0), m_end(0) { } - virtual RangeAddress_t getStart() const { return m_start; } - virtual RangeAddress_t getEnd() const { return m_end; } - virtual void SetStart(RangeAddress_t s) { m_start=s; } - virtual void SetEnd(RangeAddress_t e) { m_end=e; } + virtual RangeAddress_t getStart() const { return m_start; } + virtual RangeAddress_t getEnd() const { return m_end; } + virtual void SetStart(RangeAddress_t s) { m_start=s; } + virtual void SetEnd(RangeAddress_t e) { m_end=e; } - virtual bool Is2ByteRange() - { - return (m_end - m_start) == 2; - }; - virtual bool Is5ByteRange() - { - return (m_end - m_start) == 5; - }; + virtual bool Is2ByteRange() + { + return (m_end - m_start) == 2; + }; + virtual bool Is5ByteRange() + { + return (m_end - m_start) == 5; + }; - virtual bool IsInfiniteRange() - { - return m_end==(RangeAddress_t)-1; - }; + virtual bool IsInfiniteRange() + { + return m_end==(RangeAddress_t)-1; + }; - protected: + protected: - RangeAddress_t m_start, m_end; -}; + RangeAddress_t m_start, m_end; + }; -struct Range_tCompare -{ - bool operator() (const Range_t first, const Range_t second) const - { - return first.getEnd() < second.getStart(); - } -}; + struct Range_tCompare + { + bool operator() (const Range_t first, const Range_t second) const + { + return first.getEnd() < second.getStart(); + } + }; } #endif diff --git a/include/zipr.h b/include/zipr.h index 48416dedfb81e8494399631c2a5598c6724fb0eb..ee8493bb4856d8154983632c0cbc62353c22998c 100644 --- a/include/zipr.h +++ b/include/zipr.h @@ -39,44 +39,45 @@ namespace Zipr_SDK { + using namespace std; -typedef std::set< std::pair<Dollop_t*,RangeAddress_t> > PlacementQueue_t; + using PlacementQueue_t = set< pair<Dollop_t*,RangeAddress_t> > ; -class Zipr_t -{ - public: - /* - * These are public functions that the SDK user way want to use. - */ - virtual size_t DetermineDollopEntrySize( - DollopEntry_t*, - bool account_for_fallthrough) = 0; + class Zipr_t + { + public: + /* + * These are public functions that the SDK user way want to use. + */ + virtual size_t DetermineDollopEntrySize( + DollopEntry_t*, + bool account_for_fallthrough) = 0; - virtual RangeAddress_t PlopDollopEntry( - DollopEntry_t *, - RangeAddress_t = 0, - RangeAddress_t = 0) = 0; + virtual RangeAddress_t PlopDollopEntry( + DollopEntry_t *, + RangeAddress_t = 0, + RangeAddress_t = 0) = 0; - virtual RangeAddress_t PlopDollopEntryWithTarget( - DollopEntry_t *, - RangeAddress_t = 0, - RangeAddress_t = 0) = 0; + virtual RangeAddress_t PlopDollopEntryWithTarget( + DollopEntry_t *, + RangeAddress_t = 0, + RangeAddress_t = 0) = 0; - virtual RangeAddress_t PlopDollopEntryWithCallback( - DollopEntry_t *, - RangeAddress_t = 0) = 0; + virtual RangeAddress_t PlopDollopEntryWithCallback( + DollopEntry_t *, + RangeAddress_t = 0) = 0; - virtual MemorySpace_t *GetMemorySpace()=0; - virtual ELFIO::elfio *getELFIO()=0; - virtual IRDB_SDK::FileIR_t *getFileIR()=0; - virtual InstructionLocationMap_t *GetLocationMap()=0; - virtual DollopManager_t *getDollopManager()=0; - virtual PlacementQueue_t* GetPlacementQueue()=0; - virtual void ApplyPatch( - RangeAddress_t from_addr, - RangeAddress_t to_addr)=0; + virtual MemorySpace_t *GetMemorySpace()=0; + virtual ELFIO::elfio *getELFIO()=0; + virtual IRDB_SDK::FileIR_t *getFileIR()=0; + virtual InstructionLocationMap_t *GetLocationMap()=0; + virtual DollopManager_t *getDollopManager()=0; + virtual PlacementQueue_t* GetPlacementQueue()=0; + virtual void ApplyPatch( + RangeAddress_t from_addr, + RangeAddress_t to_addr)=0; -}; + }; }; diff --git a/include/zipr_constants.h b/include/zipr_constants.h index 76dbdaabb0258af0d1828be439c1ae93863d70c4..df9f44722449f593dc51812a22db0ee0160766ac 100644 --- a/include/zipr_constants.h +++ b/include/zipr_constants.h @@ -33,8 +33,10 @@ #ifndef ZIPR_CONSTANTS_H #define ZIPR_CONSTANTS_H -namespace Zipr_SDK { - enum { +namespace Zipr_SDK +{ + enum + { DEFAULT_TRAMPOLINE_SIZE=5 }; }; diff --git a/include/zipr_plugin.h b/include/zipr_plugin.h index 908bc7896bd4cb67e6987c6f30ca6cf77044c2d3..785184d1845f0d9e61d68b8d878643e223468379 100644 --- a/include/zipr_plugin.h +++ b/include/zipr_plugin.h @@ -1,133 +1,136 @@ namespace Zipr_SDK { -typedef std::map<IRDB_SDK::Instruction_t*,Zipr_SDK::RangeAddress_t> InstructionLocationMap_t; + using namespace std; -enum ZiprPreference { - None, - Must, -}; + using InstructionLocationMap_t = map<IRDB_SDK::Instruction_t*,RangeAddress_t>; -class ZiprPluginInterface_t -{ - public: - virtual void PinningBegin() - { - } - virtual void PinningEnd() - { - } - virtual void DollopBegin() - { - } - virtual void DollopEnd() - { - } - virtual void CallbackLinkingBegin() - { - } - virtual void CallbackLinkingEnd() - { - } + enum ZiprPreference + { + None, + Must, + }; + + class ZiprPluginInterface_t + { + public: + virtual void PinningBegin() + { + } + virtual void PinningEnd() + { + } + virtual void DollopBegin() + { + } + virtual void DollopEnd() + { + } + virtual void CallbackLinkingBegin() + { + } + virtual void CallbackLinkingEnd() + { + } - virtual ZiprPreference AddressDollop(const Dollop_t *dollop, const RangeAddress_t &source, Range_t &place, bool &coalesce, bool &fallthrough_ok) - { - return None; - } + virtual ZiprPreference AddressDollop(const Dollop_t *dollop, const RangeAddress_t &source, Range_t &place, bool &coalesce, bool &fallthrough_ok) + { + return None; + } - virtual bool WillPluginPlop(IRDB_SDK::Instruction_t*) - { - return false; - } + virtual bool WillPluginPlop(IRDB_SDK::Instruction_t*) + { + return false; + } - virtual size_t InsnSize(IRDB_SDK::Instruction_t*, bool) - { - return 0; - } - /* - * DollopEntryOpeningSize() - * DollopEntryClosingSize() - * - * A plugin that wants to put padding into a - * dollop entry before/after an instruction - * should return the size of that padding in - * these functions. - */ - virtual size_t DollopEntryOpeningSize(DollopEntry_t*) - { - return 0; - } - virtual size_t DollopEntryClosingSize(DollopEntry_t*) - { - return 0; - } + virtual size_t InsnSize(IRDB_SDK::Instruction_t*, bool) + { + return 0; + } + /* + * DollopEntryOpeningSize() + * DollopEntryClosingSize() + * + * A plugin that wants to put padding into a + * dollop entry before/after an instruction + * should return the size of that padding in + * these functions. + */ + virtual size_t DollopEntryOpeningSize(DollopEntry_t*) + { + return 0; + } + virtual size_t DollopEntryClosingSize(DollopEntry_t*) + { + return 0; + } - /* - * PlopDollopEntry() - * - * This function is invoked by Zipr for a plugin to - * plop a dollop entry. The entry to plop is given as - * the first parameter. The plugin writer can use - * it's Place() function to determine the beginning - * of the space allocated for this dollop entry. - * - * entry: A pointer to the dollop entry to be plopped. - * - * instruction_address: Because multiple plugins - * may want to plop the same dollop entry, the current - * address of the instruction within the entry is - * passed in this parameter. If the plugin moves that - * instruction, it must update the parameter. - * - * instruction_size: The size of the instruction itself. - * - * placed_instruction: A flag that the plugin sets - * to tell Zipr whether this plugin placed the - * instruction or whether it just wrote into the entry - * surrounding the instruction. The plugin should set - * this value appropriately. The default is false. - * - * zipr: Pointer to a Zipr object for plugin access to - * functionality provided by zipr. - * - * As output, the implementation must provide the - * address of the memory that "concludes" the - * dollop entry. - */ - virtual RangeAddress_t PlopDollopEntry(Zipr_SDK::DollopEntry_t *entry, - RangeAddress_t &instruction_address, - RangeAddress_t &target_address, - size_t instruction_size, - bool &placed_instruction) - { - return 0; - } - virtual std::string ToString() - { - return "NamelessPlugin"; - } - virtual ZiprOptionsNamespace_t *RegisterOptions(ZiprOptionsNamespace_t *) - { - return new ZiprOptionsNamespace_t(""); - } + /* + * PlopDollopEntry() + * + * This function is invoked by Zipr for a plugin to + * plop a dollop entry. The entry to plop is given as + * the first parameter. The plugin writer can use + * it's Place() function to determine the beginning + * of the space allocated for this dollop entry. + * + * entry: A pointer to the dollop entry to be plopped. + * + * instruction_address: Because multiple plugins + * may want to plop the same dollop entry, the current + * address of the instruction within the entry is + * passed in this parameter. If the plugin moves that + * instruction, it must update the parameter. + * + * instruction_size: The size of the instruction itself. + * + * placed_instruction: A flag that the plugin sets + * to tell Zipr whether this plugin placed the + * instruction or whether it just wrote into the entry + * surrounding the instruction. The plugin should set + * this value appropriately. The default is false. + * + * zipr: Pointer to a Zipr object for plugin access to + * functionality provided by zipr. + * + * As output, the implementation must provide the + * address of the memory that "concludes" the + * dollop entry. + */ + virtual RangeAddress_t PlopDollopEntry(DollopEntry_t *entry, + RangeAddress_t &instruction_address, + RangeAddress_t &target_address, + size_t instruction_size, + bool &placed_instruction) + { + return 0; + } + virtual string ToString() + { + return "NamelessPlugin"; + } + virtual ZiprOptionsNamespace_t *RegisterOptions(ZiprOptionsNamespace_t *) + { + return new ZiprOptionsNamespace_t(""); + } - virtual ZiprPreference RetargetPin(const RangeAddress_t &, const Zipr_SDK::Dollop_t *, RangeAddress_t &) - { - return None; - } - virtual ZiprPreference RetargetCallback(const RangeAddress_t &, const Zipr_SDK::DollopEntry_t *, RangeAddress_t &) - { - return None; - } - virtual RangeAddress_t PlaceScoopsBegin(const RangeAddress_t max_addr) - { - return max_addr; - } - virtual RangeAddress_t PlaceScoopsEnd(const RangeAddress_t max_addr) - { - return max_addr; - } + virtual ZiprPreference RetargetPin(const RangeAddress_t &, const Dollop_t *, RangeAddress_t &) + { + return None; + } + virtual ZiprPreference RetargetCallback(const RangeAddress_t &, const DollopEntry_t *, RangeAddress_t &) + { + return None; + } + virtual RangeAddress_t PlaceScoopsBegin(const RangeAddress_t max_addr) + { + return max_addr; + } + virtual RangeAddress_t PlaceScoopsEnd(const RangeAddress_t max_addr) + { + return max_addr; + } -}; + }; }