DynamoRIO / dynamorio

Dynamic Instrumentation Tool Platform
Other
2.67k stars 562 forks source link

add events for Windows APC, NtContinue, callback, and cbret #241

Closed derekbruening closed 6 years ago

derekbruening commented 9 years ago

From derek.br...@gmail.com on December 11, 2009 21:39:16

This was PR 200410

NtContinue and NtCallbackReturn can be watched for via the syscall events, and int 0x2b via the bb event. The Ki entries can be monitored via the bb event as well. So this would be a purely convenience set of events. The callback start and stop events can be important when keeping thread-shared state, because often some part of the state should be shared across callbacks while other parts should be separated.

Original issue: http://code.google.com/p/dynamorio/issues/detail?id=241

derekbruening commented 9 years ago

From bruen...@google.com on August 28, 2011 14:01:59

drmgr's "callback-local storage" (CLS) from issue #402 solves the state sharing problem

derekbruening commented 6 years ago

I'm adding a "kernel transfer" event which includes these Ki events, syscalls that change context, the signal delivery from #1693, and sigreturn.

There are many complications. I will try to summarize them:

derekbruening commented 6 years ago

These and #1693 can be used to simplify Dr. Memory, which today looks for the Ki entry points and monitors syscalls to get this information for updating shadow state.

derekbruening commented 6 years ago

Dr. Memory's use case needs the source xsp for sigreturn handling. But if we provide a full source context for syscalls, doesn't it seem weird to then require dr_get_mcontext for the full target context?

Breaking down by event type:

I guess the biggest perf worry should be timer signals and Windows callbacks. Timer signals should always be from dispatch, but we need to copy mc to a dmc before setting up for the handler, and then copy the handler's mc to a dmc: so two large copies if we have to include simd state.

We could only include CONTROL and INTEGER for the src: simd should be identical in every case to the tgt. So for efficiency, we'd pass in a source dr_mcontext_t CONTROL+INTEGER, and just the target pc+xsp, and require dr_get_mcontext() for the target??

derekbruening commented 6 years ago

Getting the source context for some of these end up requiring extra work but it's worth it in the end as some use cases need it. For dr_redirect_execution we can call dr_get_mcontext() if we take one extra step and point at the exception context in cur_mc so it will work for both clean calls and exception events.