From 125b77cbc3622a07efb7236343b5ca2cc2021abb Mon Sep 17 00:00:00 2001 From: Romain Malmain Date: Fri, 19 Apr 2024 11:11:34 +0200 Subject: [PATCH] Support native TCG vector read/write operations in LibAFL hooks (#64) * Support rw vector operations --- tcg/tcg-op-ldst.c | 13 ++++++------- tcg/tcg-op-vec.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c index 4e94c064bf7..03be92f9d0e 100644 --- a/tcg/tcg-op-ldst.c +++ b/tcg/tcg-op-ldst.c @@ -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) { @@ -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) { diff --git a/tcg/tcg-op-vec.c b/tcg/tcg-op-vec.c index 094298bb273..bcbb1e5139b 100644 --- a/tcg/tcg-op-vec.c +++ b/tcg/tcg-op-vec.c @@ -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 @@ -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)