DynamoRIO / dynamorio

Dynamic Instrumentation Tool Platform
Other
2.59k stars 552 forks source link

Add pre-loop label to rep string expansion for pre-loop instrumentation #6656

Open derekbruening opened 5 months ago

derekbruening commented 5 months ago

Xref https://groups.google.com/g/dynamorio-users/c/_xlaeOuuAJU

The rep string expansion in drutil removes the rep string from the end of its block to isolate it, during the app2app phase. So the client doesn't see the rep string instruction until the block where it's expanded: and that block is what loops, so there is no way to insert once-executed pre-loop instrumentation at that point. (The expansion deliberately uses an exit cti to loop to the top of the block: having intra-block loops is not a good idea as they cannot be unlinked and then signal delivery, thread synchronization, resets, and several other key behaviors break down.)

The proposal here is for drutil to insert a label in the pre-loop block when it truncates it to remove the rep string. This label would say "hey the very next instruction is a rep string". A client could see that and know to insert its pre-loop instrumentation there.

(There may be one complication with a block-final label not being allowed? If that is the case it might have to be one instruction in; or we should re-examine whether that restriction can be removed.)