Skip to main content

dr_register_persist_ro

Function dr_register_persist_ro 

Source
pub unsafe extern "C" fn dr_register_persist_ro(
    func_size: Option<unsafe extern "C" fn(drcontext: *mut c_void, perscxt: *mut c_void, file_offs: usize, user_data: *mut *mut c_void) -> usize>,
    func_persist: Option<unsafe extern "C" fn(drcontext: *mut c_void, perscxt: *mut c_void, fd: file_t, user_data: *mut c_void) -> bool_>,
    func_resurrect: Option<unsafe extern "C" fn(drcontext: *mut c_void, perscxt: *mut c_void, map: *mut *mut byte) -> bool_>,
) -> bool_
Expand description

Registers callback functions for storing read-only data in each persisted cache file. When generating a new persisted cache file, DR first calls \p func_size to obtain the size required for read-only data in each persisted cache file. DR subsequently calls \p func_persist to write the actual data. DR ensures that no other thread will execute in between the calls to \p func_size and \p func_persist.

Upon loading a previously-written persisted cache file, DR calls \p func_resurrect to validate and read back in data from the persisted file.

For each callback, the \p perscxt parameter can be passed to the routines dr_persist_start(), dr_persist_size(), and dr_fragment_persistable() to identify the region of code being persisted.

@param[in] func_size The function to call to determine the size needed for persisted data. The \p file_offs parameter indicates the offset from the start of the persisted file where this data will reside (which is needed to calculate patch displacements). The callback can store a void* value into the address specified by \p user_data. This value will be passed to \p func_persist and if a patch callback is registered (see dr_register_persist_patch()) to \p func_patch. The same value will be shared with persisted code callbacks (see dr_register_persist_rx()) and writable data callbacks (see dr_register_persist_rw()). @param[in] func_persist The function to call to write the actual data. Data to be persisted should be written to the file \p fd via dr_write_file(). The data will be read-only when the persisted file is loaded back in for use. The return value of the function indicates success of the write. If the function returns false, the persisted cache file being generated will be abandoned under the assumption of a non-recoverable error. @param[in] func_resurrect The function to call to validate previously written data. The \p map variable points to the mapped-in data that was written at persist time. The return value of the function indicates success of the resurrection. If the function returns false, the persisted cache file being loaded will be abandoned under the assumption of a non-recoverable error. Any validation that the persisted file is suitable for use should be performed by the function prior to any restoration work needed for the data. The \p map address should be updated to point to the end of the persisted data (i.e., on return it should equal its start value plus the size that was passed to dr_register_persist_ro_size()). DR will perform self-consistency checks, including whether the whole pcache is present and that a checksum of at least part of the file matches, prior to calling this callback. Thus, the client can assume that it is not truncated. \note \p func_resurrect may be called during persisted file generation if a persisted file already exists, in order to merge with that file. \return whether successful.