Skip to content
Snippets Groups Projects
Commit 66ad8a0c authored by Jason Hiser's avatar Jason Hiser :tractor:
Browse files

minor cleanups

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