Skip to content

Commit

Permalink
i#3544 RV64: Fix instr_encode_arch (DynamoRIO#6324)
Browse files Browse the repository at this point in the history
Fixes instr_encode_arch by adding missing handling of compressed
instructions.

Issue: DynamoRIO#3544
  • Loading branch information
ksco authored Sep 23, 2023
1 parent 61cc74b commit c1d73b6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/ir/riscv64/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ instr_encode_arch(dcontext_t *dcontext, instr_t *instr, byte *copy_pc, byte *fin
{
decode_info_t di;
uint enc;
int instr_length;

if (has_instr_opnds != NULL) {
*has_instr_opnds = false;
Expand Down Expand Up @@ -135,8 +136,15 @@ instr_encode_arch(dcontext_t *dcontext, instr_t *instr, byte *copy_pc, byte *fin
});
return NULL;
}
*(uint *)copy_pc = enc;
return copy_pc + 4;
instr_length = instr_length_arch(dcontext, instr);
if (instr_length == RISCV64_INSTR_COMPRESSED_SIZE) {
*(ushort *)copy_pc = (ushort)enc;
} else {
ASSERT(instr_length == RISCV64_INSTR_SIZE);
*(uint *)copy_pc = enc;
}

return copy_pc + instr_length;
}

byte *
Expand Down

0 comments on commit c1d73b6

Please sign in to comment.