Skip to main content

opnd_create_rel_addr

Function opnd_create_rel_addr 

Source
pub unsafe extern "C" fn opnd_create_rel_addr(
    addr: *mut c_void,
    data_size: opnd_size_t,
) -> opnd_t
Expand description

Returns a memory reference operand that refers to the address \p addr, but will be encoded as a pc-relative address. At emit time, if \p addr is out of reach of the maximum encodable displacement (signed 32-bit for x86) from the next instruction, encoding will fail.

DR guarantees that all of its code caches, all client libraries and Extensions (though not copies of system libraries), and all client memory allocated through dr_thread_alloc(), dr_global_alloc(), dr_nonheap_alloc(), or dr_custom_alloc() with #DR_ALLOC_CACHE_REACHABLE, can reach each other with a 32-bit displacement. Thus, any normally-allocated data or any static data or code in a client library is guaranteed to be reachable from code cache code. Memory allocated through system libraries (including malloc, operator new, and HeapAlloc) is not guaranteed to be reachable: only memory directly allocated via DR’s API. The runtime option -reachable_heap can be used to guarantee that all memory is reachable.

On x86, if \p addr is not pc-reachable at encoding time and this operand is used in a load or store to or from the rax (or eax) register, an absolute form will be used (as though opnd_create_abs_addr() had been called).

The operand has data size data_size (must be a OPSZ_ constant).

To represent a 32-bit address (i.e., what an address size prefix indicates), simply zero out the top 32 bits of the address before passing it to this routine.

On ARM, the resulting operand will not contain an explicit PC register, and thus will not return true on queries to whether the operand reads the PC. Explicit use of opnd_is_rel_addr() is required. However, DR does not decode any PC-using instructions into this type of relative address operand: decoding will always produce a regular base + displacement operand.

\note For ARM or 64-bit X86 DR builds only.