Skip to content

Commit

Permalink
Using x86 encode/decode for synthetic encoding/decoding
Browse files Browse the repository at this point in the history
through setting of instr ISA mode.
  • Loading branch information
edeiana committed Mar 6, 2024
1 parent a0bbf6f commit 8b29dcc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions core/ir/instr.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ enum {
#endif
/* PR 267260: distinguish our own mangling from client-added instrs */
INSTR_OUR_MANGLING = 0x80000000,
/*
* Synthetic ISA mode.
* TOFIX: we're exceeding 4 bytes, this is an issue on 32 bits arch
* where uint flags of instr_t is only 4 bytes.
*/
INSTR_SYNTH_MODE = 0x100000000,
};

#define DR_TUPLE_TYPE_BITS 4
Expand Down
11 changes: 11 additions & 0 deletions core/ir/x86/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
/* decode.c -- a full x86 decoder */

#include "../globals.h"
#include "../synthetic/decode.h"
#include "arch.h"
#include "instr.h"
#include "decode.h"
Expand Down Expand Up @@ -2579,6 +2580,16 @@ check_is_variable_size(opnd_t op)
static byte *
decode_common(dcontext_t *dcontext, byte *pc, byte *orig_pc, instr_t *instr)
{
/*
* If we're dealing with decoding from synthetic ISA, we don't care about returning
* the pc of the next instruction (?), so we just write the encoding in final_pc and
* return it.
*/
if (instr_get_isa_mode(instr) == DR_ISA_SYNTH) {
decode_from_synth(dcontext, orig_pc, instr);
return orig_pc;
}

const instr_info_t *info;
decode_info_t di;
byte *next_pc;
Expand Down
5 changes: 2 additions & 3 deletions core/ir/x86/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2760,13 +2760,12 @@ instr_encode_arch(dcontext_t *dcontext, instr_t *instr, byte *copy_pc, byte *fin
bool *has_instr_opnds /*OUT OPTIONAL*/
_IF_DEBUG(bool assert_reachable))
{

/*
* If we're dealing with encoding to synthetic ISA, we don't care about returning
* the pc of the next instruction, so we just write the encoding in final_pc and
* the pc of the next instruction (?), so we just write the encoding in final_pc and
* return it.
*/
if (dr_get_isa_mode(dcontext) == DR_ISA_SYNTH) {
if (instr_get_isa_mode(instr) == DR_ISA_SYNTH) {
encode_to_synth(dcontext, instr, final_pc);
return final_pc;
}
Expand Down
8 changes: 8 additions & 0 deletions core/ir/x86/instr.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "instr.h"
#include "decode.h"
#include "decode_private.h"
#include "encode_api.h"
#include "instr_create_shared.h"

#ifdef X64
Expand Down Expand Up @@ -70,6 +71,10 @@ instr_get_x86_mode(instr_t *instr)
bool
instr_set_isa_mode(instr_t *instr, dr_isa_mode_t mode)
{
if (mode == DR_ISA_SYNTH) {
instr->flags |= INSTR_SYNTH_MODE;
return true;
}
#ifdef X64
if (mode == DR_ISA_IA32)
instr_set_x86_mode(instr, true);
Expand All @@ -87,6 +92,9 @@ instr_set_isa_mode(instr_t *instr, dr_isa_mode_t mode)
dr_isa_mode_t
instr_get_isa_mode(instr_t *instr)
{
if (TEST(INSTR_SYNTH_MODE, instr->flags)) {
return DR_ISA_SYNTH;
}
#ifdef X64
return TEST(INSTR_X86_MODE, instr->flags) ? DR_ISA_IA32 : DR_ISA_AMD64;
#else
Expand Down

0 comments on commit 8b29dcc

Please sign in to comment.