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

changes to support scons from peasoup-umbrella dir

parent 1c1e26a1
No related branches found
No related tags found
No related merge requests found
......@@ -2,3 +2,6 @@
build
*.swp
*.os
*.o
*.zpi
......@@ -63,4 +63,5 @@ Default( pedi )
ret=pedi+lib
Return('ret')
......@@ -43,57 +43,6 @@ using namespace Zipr_SDK;
#define ALLOF(a) begin(a),end(a)
static std::string findAndReplace(const std::string& in_str, const std::string& oldStr, const std::string& newStr)
{
std::string str=in_str;
size_t pos = 0;
while((pos = str.find(oldStr, pos)) != std::string::npos)
{
str.replace(pos, oldStr.length(), newStr);
pos += newStr.length();
}
return str;
}
static bool has_cfi_reloc(Instruction_t* insn)
{
for(auto reloc : insn->getRelocations())
{
/* check for a nonce relocation */
if ( reloc -> getType().find("cfi_nonce") != string::npos )
{
return true;
}
}
return false;
}
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;
}
#if 0
ZiprOptionsNamespace_t *Unpin_t::registerOptions(ZiprOptionsNamespace_t *global)
{
auto unpin_ns = new ZiprOptionsNamespace_t("unpin");
global->addOption(&m_verbose);
m_should_cfi_pin.setDescription("Pin CFI instructions.");
unpin_ns->addOption(&m_should_cfi_pin);
m_on.setDescription("Turn unpin plugin on/off.");
unpin_ns->addOption(&m_on);
m_max_unpins.setDescription("Set how many unpins are allowed, useful for debugging.");
unpin_ns->addOption(&m_max_unpins);
return unpin_ns;
}
#endif
// CAN BE DELETED, left in just for stats? (Would speed up zipr step to delete)
void Unpin_t::DoUnpin()
......@@ -106,7 +55,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((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins)
return;
auto insn_unpins=0;
auto missed_unpins=0;
......@@ -130,7 +79,7 @@ void Unpin_t::DoUnpinForFixedCalls()
unpins++;
insn_unpins++;
if(*m_max_unpins != -1 && unpins>=*m_max_unpins)
if((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins)
return;
}
}
......@@ -143,8 +92,9 @@ 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((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins)
return;
auto missed_unpins=0;
auto scoop_unpins=0;
......@@ -161,7 +111,7 @@ void Unpin_t::DoUnpinForScoops()
unpins++;
scoop_unpins++;
if(*m_max_unpins != -1 && unpins>=*m_max_unpins)
if((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins)
return;
}
}
......@@ -179,13 +129,11 @@ Zipr_SDK::ZiprPreference Unpin_t::retargetCallback(
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((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins)
return Zipr_SDK::ZiprPluginInterface_t::retargetCallback(callback_address, callback_entry, target_address);
auto& ms=*zo->getMemorySpace();
auto insn = callback_entry->getInstruction();
auto& locMap=*(zo->getLocationMap());
for(auto reloc : insn->getRelocations())
{
if (reloc->getType()==string("callback_to_scoop"))
......
......@@ -58,7 +58,6 @@ void UnpinAarch64_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* re
const auto insn_wrt=dynamic_cast<Instruction_t*>(reloc->getWRT());
assert(the_arg_it!=operands.end());
const auto the_arg=*the_arg_it;
const auto mt=firp.getArchitecture()->getMachineType();
// get the new insn addr
const auto from_insn_location=(VirtualOffset_t)locMap[from_insn];
......
......@@ -102,7 +102,6 @@ void UnpinX86_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* reloc)
const auto insn_wrt=dynamic_cast<Instruction_t*>(reloc->getWRT());
assert(the_arg_it!=operands.end());
const auto the_arg=*the_arg_it;
const auto mt=firp.getArchitecture()->getMachineType();
// get the new insn addr
const auto from_insn_location=(VirtualOffset_t)locMap[from_insn];
......@@ -133,7 +132,7 @@ void UnpinX86_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* reloc)
const auto disp_offset=(int)disasm->getMemoryDisplacementOffset(the_arg.get(),from_insn);
const auto disp_size=(int)the_arg->getMemoryDisplacementEncodingSize();
assert(disp_size==4);
assert(0<disp_offset && disp_offset<=from_insn->getDataBits().size() - disp_size);
assert(0<disp_offset && (int64_t)disp_offset<=(int64_t)from_insn->getDataBits().size() - disp_size);
const auto new_disp=(int)(rel_addr1 + to_addr - from_insn->getDataBits().size()-from_insn_location);
const auto newbits=from_insn->getDataBits().replace(disp_offset, disp_size, (char*)&new_disp, disp_size);
......@@ -158,12 +157,11 @@ void UnpinX86_t::HandleAbsptrReloc(Instruction_t* from_insn, Relocation_t* reloc
assert(wrt);
assert(the_arg_it!=operands.end());
const auto &the_arg=*the_arg_it;
VirtualOffset_t rel_addr1=the_arg->getMemoryDisplacement();
int disp_offset=disasm->getMemoryDisplacementOffset(the_arg.get(),from_insn);
int disp_size=the_arg->getMemoryDisplacementEncodingSize();
assert(disp_size==4);
assert(0<disp_offset && disp_offset<=from_insn->getDataBits().size() - disp_size);
assert(0<disp_offset && (int64_t)disp_offset<=(int64_t)from_insn->getDataBits().size() - disp_size);
assert(reloc->getWRT());
unsigned int new_disp=the_arg->getMemoryDisplacement() + wrt->getStart()->getVirtualOffset();
......@@ -210,21 +208,17 @@ void UnpinX86_t::HandleImmedptrReloc(Instruction_t* from_insn, Relocation_t* rel
void UnpinX86_t::HandleCallbackReloc(Instruction_t* from_insn, Relocation_t* reloc)
{
DataScoop_t *wrt = dynamic_cast<DataScoop_t*>(reloc->getWRT());
int addend = reloc->getAddend();
char bytes[]={(char)0x48,
(char)0x8d,
(char)0x64,
(char)0x24,
(char)(64/0x08)}; // lea rsp, [rsp+8]
uintptr_t call_addr = 0x0, at = 0x0;
uint32_t target_addr = 0x0;
if (m_verbose)
cout << "The call insn is "
<< from_insn->getDataBits().length() << " bytes long." << endl;
call_addr = locMap[from_insn];
auto call_addr = locMap[from_insn];
if (m_verbose) {
cout << "Unpin::callback_to_scoop: call_addr "
......@@ -234,8 +228,7 @@ void UnpinX86_t::HandleCallbackReloc(Instruction_t* from_insn, Relocation_t* rel
/*
* Put down the bogus pop.
*/
at = call_addr + 1;
at = call_addr + from_insn->getDataBits().length();
auto at = call_addr + from_insn->getDataBits().length();
ms.plopBytes(at, bytes, sizeof(bytes));
/*
......
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