Skip to content

Commit bf82921

Browse files
authored
Add missing LibAFL RW callbacks (#65)
* Add other rw missing callbacks * Fix mapping iterator * LibAFL guard
1 parent 125b77c commit bf82921

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

include/libafl/user.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct libafl_mapinfo {
1010
const char* path;
1111
int flags;
1212
int is_priv;
13+
bool is_valid;
1314
};
1415

1516
IntervalTreeNode * libafl_maps_first(IntervalTreeRoot * map_info);

linux-user/syscall.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13679,6 +13679,8 @@ IntervalTreeNode * libafl_maps_first(IntervalTreeRoot * map_info) {
1367913679
}
1368013680

1368113681
IntervalTreeNode * libafl_maps_next(IntervalTreeNode *node, struct libafl_mapinfo* ret) {
13682+
ret->is_valid = false;
13683+
1368213684
if (!node || !ret) {
1368313685
return NULL;
1368413686
}
@@ -13702,6 +13704,7 @@ IntervalTreeNode * libafl_maps_next(IntervalTreeNode *node, struct libafl_mapinf
1370213704
if (flags & PAGE_WRITE_ORG) libafl_flags |= PROT_WRITE;
1370313705
if (flags & PAGE_EXEC) libafl_flags |= PROT_EXEC;
1370413706

13707+
ret->is_valid = true;
1370513708
ret->start = (target_ulong)h2g_nocheck(min);
1370613709
ret->end = (target_ulong)h2g_nocheck(max);
1370713710
ret->offset = (target_ulong)e->offset;

tcg/tcg-op-ldst.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,12 @@ static void tcg_gen_qemu_ld_i128_int(TCGv_i128 val, TCGTemp *addr,
636636
tcg_constant_i32(orig_oi));
637637
}
638638

639+
//// --- Start LibAFL code ---
640+
641+
libafl_gen_read(addr, orig_oi);
642+
643+
//// --- End LibAFL code ---
644+
639645
plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_R);
640646
}
641647

@@ -752,6 +758,12 @@ static void tcg_gen_qemu_st_i128_int(TCGv_i128 val, TCGTemp *addr,
752758
tcg_constant_i32(orig_oi));
753759
}
754760

761+
//// --- Start LibAFL code ---
762+
763+
libafl_gen_write(addr, orig_oi);
764+
765+
//// --- End LibAFL code ---
766+
755767
plugin_gen_mem_callbacks(ext_addr, addr, orig_oi, QEMU_PLUGIN_MEM_W);
756768
}
757769

@@ -1245,7 +1257,13 @@ void tcg_gen_atomic_##NAME##_i32_chk(TCGv_i32 ret, TCGTemp *addr, \
12451257
tcg_debug_assert(addr_type == tcg_ctx->addr_type); \
12461258
tcg_debug_assert((memop & MO_SIZE) <= MO_32); \
12471259
if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) { \
1260+
/* --- Start LibAFL code --- */ \
1261+
libafl_gen_read(addr, make_memop_idx(memop, 0)); \
1262+
/* --- End LibAFL code --- */ \
12481263
do_atomic_op_i32(ret, addr, val, idx, memop, table_##NAME); \
1264+
/* --- Start LibAFL code --- */ \
1265+
libafl_gen_write(addr, make_memop_idx(memop, 0)); \
1266+
/* --- End LibAFL code --- */ \
12491267
} else { \
12501268
do_nonatomic_op_i32(ret, addr, val, idx, memop, NEW, \
12511269
tcg_gen_##OP##_i32); \
@@ -1258,7 +1276,13 @@ void tcg_gen_atomic_##NAME##_i64_chk(TCGv_i64 ret, TCGTemp *addr, \
12581276
tcg_debug_assert(addr_type == tcg_ctx->addr_type); \
12591277
tcg_debug_assert((memop & MO_SIZE) <= MO_64); \
12601278
if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) { \
1279+
/* --- Start LibAFL code --- */ \
1280+
libafl_gen_read(addr, make_memop_idx(memop, 0)); \
1281+
/* --- End LibAFL code --- */ \
12611282
do_atomic_op_i64(ret, addr, val, idx, memop, table_##NAME); \
1283+
/* --- Start LibAFL code --- */ \
1284+
libafl_gen_write(addr, make_memop_idx(memop, 0)); \
1285+
/* --- End LibAFL code --- */ \
12621286
} else { \
12631287
do_nonatomic_op_i64(ret, addr, val, idx, memop, NEW, \
12641288
tcg_gen_##OP##_i64); \

tcg/tcg-op-vec.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,17 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr b, TCGArg o, TCGType low_type)
319319
TCGArg bi = tcgv_ptr_arg(b);
320320
TCGTemp *rt = arg_temp(ri);
321321
TCGType type = rt->base_type;
322+
//// --- Begin LibAFL code ---
323+
MemOpIdx oi = make_memop_idx((type - TCG_TYPE_V64) + MO_64, 0);
324+
//// --- End LibAFL code ---
322325

323326
tcg_debug_assert(low_type >= TCG_TYPE_V64);
324327
tcg_debug_assert(low_type <= type);
325328
vec_gen_3(INDEX_op_st_vec, low_type, 0, ri, bi, o);
329+
330+
//// --- Begin LibAFL code ---
331+
libafl_gen_write(tcgv_ptr_temp(b), oi);
332+
//// --- End LibAFL code ---
326333
}
327334

328335
void tcg_gen_and_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b)

0 commit comments

Comments
 (0)