Skip to content

Commit

Permalink
Add missing LibAFL RW callbacks (#65)
Browse files Browse the repository at this point in the history
* Add other rw missing callbacks

* Fix mapping iterator

* LibAFL guard
  • Loading branch information
rmalmain authored Apr 24, 2024
1 parent 125b77c commit bf82921
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/libafl/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct libafl_mapinfo {
const char* path;
int flags;
int is_priv;
bool is_valid;
};

IntervalTreeNode * libafl_maps_first(IntervalTreeRoot * map_info);
Expand Down
3 changes: 3 additions & 0 deletions linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -13679,6 +13679,8 @@ IntervalTreeNode * libafl_maps_first(IntervalTreeRoot * map_info) {
}

IntervalTreeNode * libafl_maps_next(IntervalTreeNode *node, struct libafl_mapinfo* ret) {
ret->is_valid = false;

if (!node || !ret) {
return NULL;
}
Expand All @@ -13702,6 +13704,7 @@ IntervalTreeNode * libafl_maps_next(IntervalTreeNode *node, struct libafl_mapinf
if (flags & PAGE_WRITE_ORG) libafl_flags |= PROT_WRITE;
if (flags & PAGE_EXEC) libafl_flags |= PROT_EXEC;

ret->is_valid = true;
ret->start = (target_ulong)h2g_nocheck(min);
ret->end = (target_ulong)h2g_nocheck(max);
ret->offset = (target_ulong)e->offset;
Expand Down
24 changes: 24 additions & 0 deletions tcg/tcg-op-ldst.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ static void tcg_gen_qemu_ld_i128_int(TCGv_i128 val, TCGTemp *addr,
tcg_constant_i32(orig_oi));
}

//// --- Start LibAFL code ---

libafl_gen_read(addr, orig_oi);

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

plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R);
}

Expand Down Expand Up @@ -752,6 +758,12 @@ static void tcg_gen_qemu_st_i128_int(TCGv_i128 val, TCGTemp *addr,
tcg_constant_i32(orig_oi));
}

//// --- Start LibAFL code ---

libafl_gen_write(addr, orig_oi);

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

plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_W);
}

Expand Down Expand Up @@ -1245,7 +1257,13 @@ void tcg_gen_atomic_##NAME##_i32_chk(TCGv_i32 ret, TCGTemp *addr, \
tcg_debug_assert(addr_type == tcg_ctx->addr_type); \
tcg_debug_assert((memop & MO_SIZE) <= MO_32); \
if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) { \
/* --- Start LibAFL code --- */ \
libafl_gen_read(addr, make_memop_idx(memop, 0)); \
/* --- End LibAFL code --- */ \
do_atomic_op_i32(ret, addr, val, idx, memop, table_##NAME); \
/* --- Start LibAFL code --- */ \
libafl_gen_write(addr, make_memop_idx(memop, 0)); \
/* --- End LibAFL code --- */ \
} else { \
do_nonatomic_op_i32(ret, addr, val, idx, memop, NEW, \
tcg_gen_##OP##_i32); \
Expand All @@ -1258,7 +1276,13 @@ void tcg_gen_atomic_##NAME##_i64_chk(TCGv_i64 ret, TCGTemp *addr, \
tcg_debug_assert(addr_type == tcg_ctx->addr_type); \
tcg_debug_assert((memop & MO_SIZE) <= MO_64); \
if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) { \
/* --- Start LibAFL code --- */ \
libafl_gen_read(addr, make_memop_idx(memop, 0)); \
/* --- End LibAFL code --- */ \
do_atomic_op_i64(ret, addr, val, idx, memop, table_##NAME); \
/* --- Start LibAFL code --- */ \
libafl_gen_write(addr, make_memop_idx(memop, 0)); \
/* --- End LibAFL code --- */ \
} else { \
do_nonatomic_op_i64(ret, addr, val, idx, memop, NEW, \
tcg_gen_##OP##_i64); \
Expand Down
7 changes: 7 additions & 0 deletions tcg/tcg-op-vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,17 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr b, TCGArg o, TCGType low_type)
TCGArg bi = tcgv_ptr_arg(b);
TCGTemp *rt = arg_temp(ri);
TCGType type = rt->base_type;
//// --- Begin LibAFL code ---
MemOpIdx oi = make_memop_idx((type - TCG_TYPE_V64) + MO_64, 0);
//// --- End LibAFL code ---

tcg_debug_assert(low_type >= TCG_TYPE_V64);
tcg_debug_assert(low_type <= type);
vec_gen_3(INDEX_op_st_vec, low_type, 0, ri, bi, o);

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

void tcg_gen_and_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b)
Expand Down

0 comments on commit bf82921

Please sign in to comment.