Skip to content

Commit

Permalink
Replace nop instructions with ud2 (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyroguru authored Feb 28, 2023
1 parent e3ff13f commit 9e1a9ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/OIDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,6 @@ bool OIDebugger::writePrologue(
const prequest &preq, const OICompiler::RelocResult::SymTable &jitSymbols) {
size_t off = 0;
uint8_t newInsts[prologueLength];
memset(newInsts, nopInst /* NOP */, sizeof(newInsts));

/*
* Global probes don't have multiple arguments, but calling `getReqForArg(X)`
Expand All @@ -2136,17 +2135,6 @@ bool OIDebugger::writePrologue(
VLOG(1) << "Generating prologue for argument '" << req.arg
<< "', using probe at " << (void *)jitCodeStart->second;

/*
* With the move to an INT3 to regain control of the target thread I'm
* not convinced that we actually need to do any of this now. We may be
* able to simply tack an INT3 on to the end of the JIT'd code sequence
* (obviously we wouldn't ever execute the 'ret' there but that doesn't
* really matter).
*/
/*
* movabs is really a synthetic for a REX prefixed mov instruction.
* The REX prefix opcode is 0x48 (REX.W == 1).
*/
newInsts[off++] = movabsrdi0Inst;
newInsts[off++] = movabsrdi1Inst;
remoteObjAddrs.emplace(std::move(jitCodeStart->first),
Expand Down Expand Up @@ -2177,6 +2165,11 @@ bool OIDebugger::writePrologue(

newInsts[off++] = int3Inst;

while (off <= prologueLength - sizeofUd2) {
newInsts[off++] = ud2Inst0;
newInsts[off++] = ud2Inst1;
}

assert(off <= prologueLength);

return writeTargetMemory(&newInsts, (void *)segConfig.textSegBase,
Expand Down
1 change: 1 addition & 0 deletions src/OIDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class OIDebugger {
uint64_t count{};
bool sigIntHandlerActive{false};
const int sizeofInt3 = 1;
const int sizeofUd2 = 2;
const int replayInstSize = 512;
bool trapsRemoved{false};
std::shared_ptr<SymbolService> symbols;
Expand Down
2 changes: 2 additions & 0 deletions src/X86InstDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ static constexpr uint8_t movabsrax1Inst = 0xb8;
static constexpr uint8_t callRaxInst0Inst = 0xff;
static constexpr uint8_t callRaxInst1Inst = 0xd0;
static constexpr long syscallInsts = 0x9090909090050fcc;
static constexpr uint8_t ud2Inst0 = 0x0f;
static constexpr uint8_t ud2Inst1 = 0x0b;

0 comments on commit 9e1a9ed

Please sign in to comment.