From 1c1e26a1c38ed817a22c1f01742960725346d62a Mon Sep 17 00:00:00 2001 From: Jason Hiser <jdhiser@gmail.com> Date: Thu, 14 Feb 2019 10:02:32 -0500 Subject: [PATCH] refactored to deal with options better --- unpin.cpp | 18 ++++++++++-------- unpin.h | 26 ++++++++++++++++---------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/unpin.cpp b/unpin.cpp index c3d73da..b8cdd3b 100644 --- a/unpin.cpp +++ b/unpin.cpp @@ -73,9 +73,10 @@ bool Unpin_t::should_cfi_pin(Instruction_t* insn) // add command line option that: // 1) return false if !has_cfi_reloc(insn) // 2) return true if option is on. - return m_should_cfi_pin; + return *m_should_cfi_pin; } +#if 0 ZiprOptionsNamespace_t *Unpin_t::registerOptions(ZiprOptionsNamespace_t *global) { auto unpin_ns = new ZiprOptionsNamespace_t("unpin"); @@ -92,6 +93,7 @@ ZiprOptionsNamespace_t *Unpin_t::registerOptions(ZiprOptionsNamespace_t *global) return unpin_ns; } +#endif // CAN BE DELETED, left in just for stats? (Would speed up zipr step to delete) void Unpin_t::DoUnpin() @@ -104,7 +106,7 @@ void Unpin_t::DoUnpin() // scan instructions and process instruction relocs that can be unpinned. void Unpin_t::DoUnpinForFixedCalls() { - if(m_max_unpins != -1 && unpins>=m_max_unpins) + if(*m_max_unpins != -1 && unpins>=*m_max_unpins) return; auto insn_unpins=0; auto missed_unpins=0; @@ -128,7 +130,7 @@ void Unpin_t::DoUnpinForFixedCalls() unpins++; insn_unpins++; - if(m_max_unpins != -1 && unpins>=m_max_unpins) + if(*m_max_unpins != -1 && unpins>=*m_max_unpins) return; } } @@ -141,7 +143,7 @@ void Unpin_t::DoUnpinForFixedCalls() // CAN BE DELETED, left in just for stats? void Unpin_t::DoUnpinForScoops() { - if(m_max_unpins != -1 && unpins>=m_max_unpins) + if(*m_max_unpins != -1 && unpins>=*m_max_unpins) return; auto missed_unpins=0; auto scoop_unpins=0; @@ -159,7 +161,7 @@ void Unpin_t::DoUnpinForScoops() unpins++; scoop_unpins++; - if(m_max_unpins != -1 && unpins>=m_max_unpins) + if(*m_max_unpins != -1 && unpins>=*m_max_unpins) return; } } @@ -174,10 +176,10 @@ Zipr_SDK::ZiprPreference Unpin_t::retargetCallback( const DollopEntry_t *callback_entry, RangeAddress_t &target_address) { - if(!m_on) return Zipr_SDK::ZiprPluginInterface_t::retargetCallback(callback_address, callback_entry, target_address); + if(!*m_on) return Zipr_SDK::ZiprPluginInterface_t::retargetCallback(callback_address, callback_entry, target_address); unpins++;// unpinning a call to a scoop. - if(m_max_unpins != -1 && unpins>=m_max_unpins) + if(*m_max_unpins != -1 && unpins>=*m_max_unpins) return Zipr_SDK::ZiprPluginInterface_t::retargetCallback(callback_address, callback_entry, target_address); @@ -193,7 +195,7 @@ Zipr_SDK::ZiprPreference Unpin_t::retargetCallback( target_address = wrt->getStart()->getVirtualOffset() + addend; - if (m_verbose) { + if (*m_verbose) { cout << "Unpin::callback_to_scoop: target_addr " << std::hex << target_address << endl; } diff --git a/unpin.h b/unpin.h index 53a6bdf..bdc06c6 100644 --- a/unpin.h +++ b/unpin.h @@ -40,17 +40,23 @@ class Unpin_t : public Zipr_SDK::ZiprPluginInterface_t Unpin_t( Zipr_SDK::Zipr_t* zipr_object) : zo(zipr_object), - m_verbose("verbose",false), - m_should_cfi_pin("should_cfi_pin", false) , - m_on("on",true), - m_max_unpins("max-unpins",-1), unpins(0), missed_unpins(0), ms(*zo->getMemorySpace()), locMap(*(zo->getLocationMap())), firp(*(zo->getFileIR())) - { } + { + + auto global=zo->getOptionsManager()->getNamespace("global"); + auto unpin =zo->getOptionsManager()->getNamespace("unpin" ); + + m_verbose = global->getBooleanOption("verbose"); + m_should_cfi_pin = unpin ->getBooleanOption("should_cfi_pin", "Pin CFI instructions.", false); + m_on = unpin ->getBooleanOption("on","Turn unpin plugin on/off.", true); + m_max_unpins = unpin ->getIntegerOption("max-unpins","Set how many unpins are allowed, useful for debugging.",-1); + + } virtual ~Unpin_t() { } @@ -66,7 +72,7 @@ class Unpin_t : public Zipr_SDK::ZiprPluginInterface_t DoUpdate(); } - virtual Zipr_SDK::ZiprOptionsNamespace_t *registerOptions(Zipr_SDK::ZiprOptionsNamespace_t *) override; + // virtual Zipr_SDK::ZiprOptionsNamespace_t *registerOptions(Zipr_SDK::ZiprOptionsNamespace_t *) override; Zipr_SDK::ZiprPreference retargetCallback( const Zipr_SDK::RangeAddress_t &callback_address, @@ -93,10 +99,10 @@ class Unpin_t : public Zipr_SDK::ZiprPluginInterface_t Zipr_SDK::Zipr_t* zo; - Zipr_SDK::ZiprBooleanOption_t m_verbose; - Zipr_SDK::ZiprBooleanOption_t m_should_cfi_pin; - Zipr_SDK::ZiprBooleanOption_t m_on; - Zipr_SDK::ZiprIntegerOption_t m_max_unpins; + Zipr_SDK::ZiprBooleanOption_t *m_verbose; + Zipr_SDK::ZiprBooleanOption_t *m_should_cfi_pin; + Zipr_SDK::ZiprBooleanOption_t *m_on; + Zipr_SDK::ZiprIntegerOption_t *m_max_unpins; int unpins; int missed_unpins=0; -- GitLab