Skip to content

Commit b01a0bc

Browse files
authored
Fix helper function calls & support for new x86 decoder (#92)
* fix helper function calls * cmp hooks: support for new x86 decoder
1 parent 513bd84 commit b01a0bc

File tree

12 files changed

+46
-18
lines changed

12 files changed

+46
-18
lines changed

include/libafl/hook.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,4 @@
5656
extern target_ulong libafl_gen_cur_pc;
5757
extern size_t libafl_qemu_hooks_num;
5858

59-
void tcg_gen_callN(TCGHelperInfo* info, TCGTemp* ret, TCGTemp** args);
60-
6159
void libafl_tcg_gen_asan(TCGTemp* addr, size_t size);

include/libafl/hooks/tcg/edge.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "qemu/osdep.h"
4-
54
#include "qapi/error.h"
65

76
#include "exec/exec-all.h"

include/libafl/tcg.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include "qemu/osdep.h"
4+
#include "qapi/error.h"
5+
6+
#include "tcg/tcg.h"
7+
#include "tcg/helper-info.h"
8+
9+
void tcg_gen_callN(void *func, TCGHelperInfo *info,
10+
TCGTemp *ret, TCGTemp **args);

libafl/hooks/tcg/backdoor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "libafl/tcg.h"
12
#include "libafl/hooks/tcg/backdoor.h"
23

34
struct libafl_backdoor_hook* libafl_backdoor_hooks;
@@ -40,7 +41,7 @@ void libafl_qemu_hook_backdoor_run(vaddr pc_next)
4041
TCGTemp* args[3] = {tcgv_i64_temp(tmp0), tcgv_ptr_temp(tcg_env),
4142
tcgv_tl_temp(tmp2)};
4243

43-
tcg_gen_callN(&bhk->helper_info, NULL, args);
44+
tcg_gen_callN(bhk->helper_info.func, &bhk->helper_info, NULL, args);
4445

4546
bhk = bhk->next;
4647
}

libafl/hooks/tcg/block.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "libafl/tcg.h"
12
#include "libafl/hooks/tcg/block.h"
23

34
struct libafl_block_hook* libafl_block_hooks;
@@ -80,7 +81,7 @@ void libafl_qemu_hook_block_run(target_ulong pc)
8081
TCGv_i64 tmp0 = tcg_constant_i64(hook->data);
8182
TCGv_i64 tmp1 = tcg_constant_i64(cur_id);
8283
TCGTemp* tmp2[2] = {tcgv_i64_temp(tmp0), tcgv_i64_temp(tmp1)};
83-
tcg_gen_callN(&hook->helper_info, NULL, tmp2);
84+
tcg_gen_callN(hook->helper_info.func, &hook->helper_info, NULL, tmp2);
8485
tcg_temp_free_i64(tmp0);
8586
tcg_temp_free_i64(tmp1);
8687
}

libafl/hooks/tcg/cmp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "libafl/tcg.h"
12
#include "libafl/hooks/tcg/cmp.h"
23

34
struct libafl_cmp_hook* libafl_cmp_hooks;
@@ -120,7 +121,7 @@ void libafl_gen_cmp(target_ulong pc, TCGv op0, TCGv op1, MemOp ot)
120121
#else
121122
tcgv_i64_temp(op0), tcgv_i64_temp(op1)};
122123
#endif
123-
tcg_gen_callN(info, NULL, tmp2);
124+
tcg_gen_callN(info->func, info, NULL, tmp2);
124125
tcg_temp_free_i64(tmp0);
125126
tcg_temp_free_i64(tmp1);
126127
}

libafl/hooks/tcg/edge.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "libafl/tcg.h"
12
#include "libafl/hooks/tcg/edge.h"
23

34
struct libafl_edge_hook* libafl_edge_hooks;
@@ -8,7 +9,8 @@ static TCGHelperInfo libafl_exec_edge_hook_info = {
89
.name = "libafl_exec_edge_hook",
910
.flags = dh_callflag(void),
1011
.typemask =
11-
dh_typemask(void, 0) | dh_typemask(i64, 1) | dh_typemask(i64, 2)};
12+
dh_typemask(void, 0) | dh_typemask(i64, 1) | dh_typemask(i64, 2)
13+
};
1214

1315
GEN_REMOVE_HOOK(edge)
1416

@@ -84,7 +86,7 @@ void libafl_qemu_hook_edge_run(void)
8486
TCGv_i64 tmp0 = tcg_constant_i64(hook->data);
8587
TCGv_i64 tmp1 = tcg_constant_i64(hook->cur_id);
8688
TCGTemp* tmp2[2] = {tcgv_i64_temp(tmp0), tcgv_i64_temp(tmp1)};
87-
tcg_gen_callN(&hook->helper_info, NULL, tmp2);
89+
tcg_gen_callN(hook->helper_info.func, &hook->helper_info, NULL, tmp2);
8890
tcg_temp_free_i64(tmp0);
8991
tcg_temp_free_i64(tmp1);
9092
}

libafl/hooks/tcg/instruction.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "libafl/tcg.h"
12
#include "libafl/hooks/tcg/instruction.h"
23

34
#include "libafl/cpu.h"
@@ -124,7 +125,7 @@ void libafl_qemu_hook_instruction_run(vaddr pc_next)
124125
TCGTemp* tmp2[2] = {tcgv_i64_temp(tmp0), tcgv_i64_temp(tmp1)};
125126
#endif
126127
// tcg_gen_callN(hk->callback, NULL, 2, tmp2);
127-
tcg_gen_callN(&hk->helper_info, NULL, tmp2);
128+
tcg_gen_callN(hk->helper_info.func, &hk->helper_info, NULL, tmp2);
128129
#if TARGET_LONG_BITS == 32
129130
tcg_temp_free_i32(tmp1);
130131
#else

libafl/hooks/tcg/read_write.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "libafl/tcg.h"
12
#include "libafl/hooks/tcg/read_write.h"
23

34
struct libafl_rw_hook* libafl_read_hooks;
@@ -201,7 +202,7 @@ static void libafl_gen_rw(TCGTemp* addr, MemOpIdx oi,
201202
TCGv_i64 tmp1 = tcg_constant_i64(cur_id);
202203
TCGTemp* tmp2[3] = {tcgv_i64_temp(tmp0), tcgv_i64_temp(tmp1),
203204
addr};
204-
tcg_gen_callN(info, NULL, tmp2);
205+
tcg_gen_callN(info->func, info, NULL, tmp2);
205206
tcg_temp_free_i64(tmp0);
206207
tcg_temp_free_i64(tmp1);
207208
} else if (hook->helper_infoN.func) {
@@ -215,7 +216,7 @@ static void libafl_gen_rw(TCGTemp* addr, MemOpIdx oi,
215216
#else
216217
tcgv_i64_temp(tmp2)};
217218
#endif
218-
tcg_gen_callN(&hook->helper_infoN, NULL, tmp3);
219+
tcg_gen_callN(hook->helper_infoN.func, &hook->helper_infoN, NULL, tmp3);
219220
tcg_temp_free_i64(tmp0);
220221
tcg_temp_free_i64(tmp1);
221222
#if TARGET_LONG_BITS == 32

target/i386/tcg/emit.c.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,6 +3848,13 @@ static void gen_SUB(DisasContext *s, X86DecodedInsn *decode)
38483848
tcg_gen_sub_tl(s->T0, s->cc_srcT, s->T1);
38493849
} else {
38503850
tcg_gen_mov_tl(s->cc_srcT, s->T0);
3851+
3852+
//// --- Begin LibAFL code ---
3853+
3854+
libafl_gen_cmp(s->pc, s->T0, s->T1, ot);
3855+
3856+
//// --- End LibAFL code ---
3857+
38513858
tcg_gen_sub_tl(s->T0, s->T0, s->T1);
38523859
}
38533860
prepare_update2_cc(decode, s, CC_OP_SUBB + ot);

0 commit comments

Comments
 (0)