Granary / granary2

Dynamic binary translation framework for instrumenting x86-64 user space Linux programs
MIT License
39 stars 5 forks source link

Inline encoder cache #76

Open pgoodman opened 9 years ago

pgoodman commented 9 years ago

Most instructions have the same stage- and commit-encoding, meaning that they don't depend on anything specific to their encoded location (such as having a RIP-relative operand). For such instructions, I think we could benefit from having a simple "cache" for these instruction encodings, so that we don't waste time re-encoding them. There are some options available to us.

One option is to re-use operand memory for this purpose, as there are almost certainly unused operands. This enables re-use of existing space.

Another option is to use Instruction::transient_meta. This would limit cached encodings to 8 bytes, but this is not too onerous.

Another option is to add in a whole new char[arch::Instruction::MAX_INSTRUCTION_LENGTH] array into the instruction. arch::Instructions are massive anyway so, in the grand scheme of things it's not making things much worse--especially if sizeof(NativeInstruction) is not a multiple of the cache line size, so there's that.

Anyway, this is a nice, simple-to-do thing that would require a bit of poking about in the instruction encoding to flag "uncachable" instructions as stage-encode time, then re-use cached encodings at commit-encode time.