Skip to content

Commit

Permalink
Support native TCG vector read/write operations in LibAFL hooks (#64)
Browse files Browse the repository at this point in the history
* Support rw vector operations
  • Loading branch information
rmalmain authored Apr 19, 2024
1 parent 4627398 commit 125b77c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tcg/tcg-op-ldst.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#include "exec/plugin-gen.h"
#include "tcg-internal.h"

//// --- Begin LibAFL code ---

void libafl_gen_read(TCGTemp *addr, MemOpIdx oi);
void libafl_gen_write(TCGTemp *addr, MemOpIdx oi);

//// --- End LibAFL code ---

static void check_max_alignment(unsigned a_bits)
{
Expand Down Expand Up @@ -175,13 +181,6 @@ plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *orig_addr, MemOpIdx oi,
#endif
}

//// --- Begin LibAFL code ---

void libafl_gen_read(TCGTemp *addr, MemOpIdx oi);
void libafl_gen_write(TCGTemp *addr, MemOpIdx oi);

//// --- End LibAFL code ---

static void tcg_gen_qemu_ld_i32_int(TCGv_i32 val, TCGTemp *addr,
TCGArg idx, MemOp memop)
{
Expand Down
29 changes: 29 additions & 0 deletions tcg/tcg-op-vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
#include "tcg/tcg-mo.h"
#include "tcg-internal.h"

//// --- Begin LibAFL code ---

void libafl_gen_read(TCGTemp *addr, MemOpIdx oi);
void libafl_gen_write(TCGTemp *addr, MemOpIdx oi);

//// --- End LibAFL code ---

/*
* Vector optional opcode tracking.
* Except for the basic logical operations (and, or, xor), and
Expand Down Expand Up @@ -276,12 +283,34 @@ static void vec_gen_ldst(TCGOpcode opc, TCGv_vec r, TCGv_ptr b, TCGArg o)

void tcg_gen_ld_vec(TCGv_vec r, TCGv_ptr b, TCGArg o)
{
//// --- Begin LibAFL code ---
TCGArg ri = tcgv_vec_arg(r);
TCGTemp *rt = arg_temp(ri);
TCGType type = rt->base_type;
MemOpIdx oi = make_memop_idx((type - TCG_TYPE_V64) + MO_64, 0);
//// --- End LibAFL code ---

vec_gen_ldst(INDEX_op_ld_vec, r, b, o);

//// --- Begin LibAFL code ---
libafl_gen_read(tcgv_ptr_temp(b), oi);
//// --- End LibAFL code ---
}

void tcg_gen_st_vec(TCGv_vec r, TCGv_ptr b, TCGArg o)
{
//// --- Begin LibAFL code ---
TCGArg ri = tcgv_vec_arg(r);
TCGTemp *rt = arg_temp(ri);
TCGType type = rt->base_type;
MemOpIdx oi = make_memop_idx((type - TCG_TYPE_V64) + MO_64, 0);
//// --- End LibAFL code ---

vec_gen_ldst(INDEX_op_st_vec, r, b, o);

//// --- Begin LibAFL code ---
libafl_gen_write(tcgv_ptr_temp(b), oi);
//// --- End LibAFL code ---
}

void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr b, TCGArg o, TCGType low_type)
Expand Down

0 comments on commit 125b77c

Please sign in to comment.