Skip to main content

drwrap_wrap

Function drwrap_wrap 

Source
pub unsafe extern "C" fn drwrap_wrap(
    func: app_pc,
    pre_func_cb: Option<unsafe extern "C" fn(wrapcxt: *mut c_void, user_data: *mut *mut c_void)>,
    post_func_cb: Option<unsafe extern "C" fn(wrapcxt: *mut c_void, user_data: *mut c_void)>,
) -> bool_
Expand description

Wraps the application function that starts at the address \p original by calling \p pre_func_cb prior to every invocation of \p original and calling \p post_func_cb after every invocation of \p original. One of the callbacks can be NULL, but not both. Uses the default calling convention for the platform (see #DRWRAP_CALLCONV_DEFAULT in #drwrap_callconv_t) and passes both #DR_CLEANCALL_READS_APP_CONTEXT and #DR_CLEANCALL_WRITES_APP_CONTEXT to the insertion of the calls.

Wrap requests should normally be made up front during process initialization or module load (see dr_register_module_load_event()). If a wrap request is made after the target code may have already been executed by the application, the caller should flush the target code from the cache using the desired flush method after issuing the wrap request.

Multiple wrap requests are allowed for one \p original function (unless #DRWRAP_NO_FRILLS is set). Their callbacks are called sequentially in the reverse order of registration.

The \p pre_func_cb can examine (drwrap_get_arg()) and set (drwrap_set_arg()) the arguments to \p original and can skip the call to \p original (drwrap_skip_call()). The \p post_func_cb can examine (drwrap_get_retval()) and set (drwrap_set_retval()) \p original’s return value. The opaque pointer \p wrapcxt passed to each callback should be passed to these routines.

When an abnormal stack unwind, such as longjmp or a Windows exception, occurs, drwrap does its best to detect it. All post-calls that would be missed will still be invoked, but with \p wrapcxt set to NULL. Since there is no post-call environment, it does not make sense to query the return value or arguments. The call is invoked to allow for cleanup of state allocated in \p pre_func_cb. However, detection of a stack unwind is not guaranteed. When wrapping a series of functions that do not themselves contain exception handlers, pass the DRWRAP_UNWIND_ON_EXCEPTION flag to drwrap_wrap_ex() to ensure that all post-call callbacks will be called on an exception.

This routine may call dr_unlink_flush_region(), which means that it cannot be called while any locks are held that could block a thread processing a registered event callback or cache callout.

\note The priority of the app2app pass used here is DRMGR_PRIORITY_INSERT_DRWRAP and its name is DRMGR_PRIORITY_NAME_DRWRAP.

\return whether successful.