Skip to content

Commit c3c9c21

Browse files
Add comparison hooks for RISCV (#78)
* Add comparison hooks for RISCV
1 parent 805b14f commit c3c9c21

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Diff for: target/riscv/translate.c

+33
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ static inline bool has_ext(DisasContext *ctx, uint32_t ext)
123123
return ctx->misa_ext & ext;
124124
}
125125

126+
//// --- Begin LibAFL code ---
127+
128+
void libafl_gen_cmp(target_ulong pc, TCGv op0, TCGv op1, MemOp ot);
129+
130+
//// --- End LibAFL code ---
131+
126132
#ifdef TARGET_RISCV32
127133
#define get_xl(ctx) MXL_RV32
128134
#elif defined(CONFIG_USER_ONLY)
@@ -867,6 +873,13 @@ static bool gen_arith_imm_fn(DisasContext *ctx, arg_i *a, DisasExtend ext,
867873
return true;
868874
}
869875

876+
//// --- Begin LibAFL code ---
877+
878+
static void gen_slt(TCGv ret, TCGv s1, TCGv s2);
879+
static void gen_sltu(TCGv ret, TCGv s1, TCGv s2);
880+
881+
//// --- End LibAFL code ---
882+
870883
static bool gen_arith_imm_tl(DisasContext *ctx, arg_i *a, DisasExtend ext,
871884
void (*func)(TCGv, TCGv, TCGv),
872885
void (*f128)(TCGv, TCGv, TCGv, TCGv, TCGv, TCGv))
@@ -876,6 +889,16 @@ static bool gen_arith_imm_tl(DisasContext *ctx, arg_i *a, DisasExtend ext,
876889
TCGv src2 = tcg_constant_tl(a->imm);
877890

878891
if (get_ol(ctx) < MXL_RV128) {
892+
893+
//// --- Begin LibAFL code ---
894+
895+
if (func == gen_slt || func == gen_sltu) {
896+
MemOp memop = get_ol(ctx) == MXL_RV32 ? MO_32 : MO_64;
897+
libafl_gen_cmp(ctx->base.pc_next, src1, src2, memop);
898+
}
899+
900+
//// --- End LibAFL code ---
901+
879902
func(dest, src1, src2);
880903
gen_set_gpr(ctx, a->rd, dest);
881904
} else {
@@ -902,6 +925,16 @@ static bool gen_arith(DisasContext *ctx, arg_r *a, DisasExtend ext,
902925
TCGv src2 = get_gpr(ctx, a->rs2, ext);
903926

904927
if (get_ol(ctx) < MXL_RV128) {
928+
929+
//// --- Begin LibAFL code ---
930+
931+
if (func == gen_slt || func == gen_sltu) {
932+
MemOp memop = get_ol(ctx) == MXL_RV32 ? MO_32 : MO_64;
933+
libafl_gen_cmp(ctx->base.pc_next, src1, src2, memop);
934+
}
935+
936+
//// --- End LibAFL code ---
937+
905938
func(dest, src1, src2);
906939
gen_set_gpr(ctx, a->rd, dest);
907940
} else {

0 commit comments

Comments
 (0)