Containing-register IDs can be >=256, hence their value does not fit
in the allotted 8 bits per register operand of regdeps encoding.
This was causing a memory corruption in instr_convert_to_isa_regdeps()
where src_reg_used and dst_reg_used have only 256 elements and are
laid out next to each other in memory. Writing to index >=256 into one was
overwriting the other. Fix: remap containing-register IDs to virtual-register
IDs starting from 0 for all architectures. We still have only up to 198 unique
containing registers (max number of containing registers for AARCH64),
so remapping allows to fit them in 8 bits.
In the re-mapping (from DRREG to DR_REG_V) we exclude DR_REG_INVALID
and DR_REG_NULL to avoid issues with opnd_t operations for registers.
We introduce a private routine dr_reg_to_virtual() to do the mapping from real ISA
to virtual register. We use it in instr_convert_to_isa_regdeps() to avoid the issue
mentioned above.
We modified the get_register_name() public API to use the global dcontext and its
ISA mode to determine whether to return a real register name or a virtual one.
The signature of the API remained the same, but we document the use of the global
dcontext in doxygen.
We also re-introduce setting the size for register operands in
instr_convert_to_isa_reg_deps() and decode_isa_regdeps() as
instr_t.operation_size because not all DR_REG_V have a predefined size
based on their enum value (e.g., reserved DR_REG_XMM enum values).
We added tests to check that DRREG with IDs >=256 don't cause problems.
Containing-register IDs can be >=256, hence their value does not fit in the allotted 8 bits per register operand of regdeps encoding. This was causing a memory corruption in instr_convert_to_isa_regdeps() where src_reg_used and dst_reg_used have only 256 elements and are laid out next to each other in memory. Writing to index >=256 into one was overwriting the other. Fix: remap containing-register IDs to virtual-register IDs starting from 0 for all architectures. We still have only up to 198 unique containing registers (max number of containing registers for AARCH64), so remapping allows to fit them in 8 bits.
In the re-mapping (from DRREG to DR_REG_V) we exclude DR_REG_INVALID and DR_REG_NULL to avoid issues with opnd_t operations for registers.
We introduce a private routine dr_reg_to_virtual() to do the mapping from real ISA to virtual register. We use it in instr_convert_to_isa_regdeps() to avoid the issue mentioned above.
We modified the get_register_name() public API to use the global dcontext and its ISA mode to determine whether to return a real register name or a virtual one. The signature of the API remained the same, but we document the use of the global dcontext in doxygen.
We also re-introduce setting the size for register operands in instr_convert_to_isa_reg_deps() and decode_isa_regdeps() as instr_t.operation_size because not all DR_REG_V have a predefined size based on their enum value (e.g., reserved DR_REG_XMM enum values).
We added tests to check that DRREG with IDs >=256 don't cause problems.
Issue: #6662